[优化] 修复 docker

This commit is contained in:
ryan
2026-06-01 12:03:09 +08:00
parent 9a2616dc0e
commit 5af13d0709
3 changed files with 28 additions and 7 deletions
+14
View File
@@ -33,5 +33,19 @@ services:
OPENFLARE_SERVER_URL: http://host.docker.internal:3000
OPENFLARE_DISCOVERY_TOKEN: 85464eeb72c49abc430569d6b9c77f78
LOG_LEVEL: "debug"
extra_hosts:
- "host.docker.internal:host-gateway"
openflared:
build:
context: .
dockerfile: openflared/Dockerfile
container_name: openflared
network_mode: host
restart: unless-stopped
environment:
OPENFLARE_SERVER_URL: http://host.docker.internal:3000
OPENFLARE_TUNNEL_TOKEN: 85464eeb72c49abc430569d6b9c77f78
LOG_LEVEL: "debug"
extra_hosts:
- "host.docker.internal:host-gateway"
+8 -3
View File
@@ -23,12 +23,17 @@ func printHelp() {
fmt.Println("Usage: openflare [--port <port>] [--log-dir <log directory>] [--version] [--help]")
}
func init() {
// ParseFlags 在命令行参数被任何 import 链上的 init() 误解析之前,
// 由各 binary 的 main() 显式调用一次。openflare_server 与 openflare-relay
// 共用 flag.CommandLine,必须先注册各自的 flag 再调用本函数。
// 测试场景(go test)下不会执行本函数,单元测试可直接跳过命令行解析。
func ParseFlags() {
executableName := strings.ToLower(filepath.Base(os.Args[0]))
isTest := strings.Contains(executableName, ".test") || flag.Lookup("test.v") != nil
if !isTest {
flag.Parse()
if isTest {
return
}
flag.Parse()
if *PrintVersion {
fmt.Println(Version)
+6 -4
View File
@@ -4,10 +4,6 @@ import (
"context"
"embed"
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"log/slog"
"openflare/common"
_ "openflare/docs"
@@ -19,6 +15,11 @@ import (
"openflare/utils/geoip"
"os"
"strconv"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
)
//go:embed all:web/build
@@ -41,6 +42,7 @@ var indexPage []byte
// @name X-Agent-Token
// @description Agent API 使用节点专属 Agent Token 或全局 Discovery Token
func main() {
common.ParseFlags()
common.SetupGinLog()
slog.Info("OpenFlare started", "version", common.Version)
if os.Getenv("GIN_MODE") != "debug" {