From 3cb7a6bad81a9a769f84e80eb7d6370088c05092 Mon Sep 17 00:00:00 2001 From: yml Date: Sat, 21 Nov 2026 21:06:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(deploy):=20=E6=94=AF=E6=8C=81=E5=A4=8D?= =?UTF-8?q?=E7=94=A8=E5=AE=B9=E5=99=A8=E5=8C=96=20Caddy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 拆分为镜像运行与本地构建 Compose\n- 增加现有 Caddy Docker 网络覆盖\n- 增加容器内反代示例与部署说明 --- deploy/control-center/.env.example | 3 +++ deploy/control-center/Caddyfile.container.example | 14 ++++++++++++++ deploy/control-center/README.md | 15 ++++++++++++--- deploy/control-center/compose.build.yaml | 7 +++++++ deploy/control-center/compose.existing-caddy.yaml | 12 ++++++++++++ deploy/control-center/compose.yaml | 5 ----- docs/远程控制.md | 2 +- 7 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 deploy/control-center/Caddyfile.container.example create mode 100644 deploy/control-center/compose.build.yaml create mode 100644 deploy/control-center/compose.existing-caddy.yaml diff --git a/deploy/control-center/.env.example b/deploy/control-center/.env.example index c05c923..89e1fe1 100644 --- a/deploy/control-center/.env.example +++ b/deploy/control-center/.env.example @@ -7,6 +7,9 @@ GOPROXY=https://proxy.golang.org,direct # 宿主机只监听回环地址,由 Caddy 暴露 HTTPS。 DOUYU_CONTROL_HOST_PORT=18080 +# 使用容器化 Caddy 时,控制中心加入该现有 Docker 网络。 +DOUYU_CONTROL_CADDY_NETWORK=caddy + # 管理网页令牌,与注册令牌必须不同。 DOUYU_CONTROL_OPERATOR_TOKEN=replace-with-openssl-rand-hex-32 diff --git a/deploy/control-center/Caddyfile.container.example b/deploy/control-center/Caddyfile.container.example new file mode 100644 index 0000000..1117fde --- /dev/null +++ b/deploy/control-center/Caddyfile.container.example @@ -0,0 +1,14 @@ +control.example.com { + encode zstd gzip + + reverse_proxy douyu-control:18080 { + flush_interval -1 + } + + header { + Strict-Transport-Security "max-age=31536000" + Referrer-Policy "no-referrer" + X-Content-Type-Options "nosniff" + X-Frame-Options "DENY" + } +} diff --git a/deploy/control-center/README.md b/deploy/control-center/README.md index 6463baf..fa1a4b4 100644 --- a/deploy/control-center/README.md +++ b/deploy/control-center/README.md @@ -34,7 +34,8 @@ DOUYU_CONTROL_ENROLL_TOKEN=桌面实例注册令牌 ```bash sudo install -d -m 0700 -o 10001 -g 10001 data -docker compose up -d --build +docker compose -f compose.yaml -f compose.build.yaml build +docker compose up -d ``` 如果服务器无法访问 `proxy.golang.org`,将 `.env` 中的 `GOPROXY` 改为可用的 Go 模块代理,例如 `https://goproxy.cn,direct`。 @@ -49,7 +50,15 @@ docker compose logs -f --tail=100 ## Caddy -把 `Caddyfile.example` 中的配置改好域名后加入宿主机现有 Caddy 站点配置,然后验证并重载: +宿主机 Caddy 使用 `Caddyfile.example`。如果现有 Caddy 本身运行在 Docker 中,使用 `Caddyfile.container.example`,并加载网络覆盖文件: + +```bash +docker compose -f compose.yaml -f compose.existing-caddy.yaml up -d +``` + +此时 Caddy 通过 `douyu-control:18080` 访问控制中心。`.env` 中的 `DOUYU_CONTROL_CADDY_NETWORK` 必须填写现有 Caddy 所在 Docker 网络。 + +把对应示例中的配置改好域名后加入现有 Caddy 站点配置,然后验证并重载: ```bash sudo caddy validate --config /etc/caddy/Caddyfile @@ -95,7 +104,7 @@ data/ 使用本地构建: ```bash -docker compose build --pull +docker compose -f compose.yaml -f compose.build.yaml build --pull docker compose up -d ``` diff --git a/deploy/control-center/compose.build.yaml b/deploy/control-center/compose.build.yaml new file mode 100644 index 0000000..65a46a6 --- /dev/null +++ b/deploy/control-center/compose.build.yaml @@ -0,0 +1,7 @@ +services: + control-center: + build: + context: ../.. + dockerfile: deploy/control-center/Dockerfile + args: + GOPROXY: ${GOPROXY:-https://proxy.golang.org,direct} diff --git a/deploy/control-center/compose.existing-caddy.yaml b/deploy/control-center/compose.existing-caddy.yaml new file mode 100644 index 0000000..46546b8 --- /dev/null +++ b/deploy/control-center/compose.existing-caddy.yaml @@ -0,0 +1,12 @@ +services: + control-center: + networks: + default: + caddy: + aliases: + - douyu-control + +networks: + caddy: + external: true + name: ${DOUYU_CONTROL_CADDY_NETWORK:-caddy} diff --git a/deploy/control-center/compose.yaml b/deploy/control-center/compose.yaml index 142c337..bbc16de 100644 --- a/deploy/control-center/compose.yaml +++ b/deploy/control-center/compose.yaml @@ -3,11 +3,6 @@ name: douyu-control services: control-center: image: ${DOUYU_CONTROL_IMAGE:-douyu-control:local} - build: - context: ../.. - dockerfile: deploy/control-center/Dockerfile - args: - GOPROXY: ${GOPROXY:-https://proxy.golang.org,direct} env_file: - .env environment: diff --git a/docs/远程控制.md b/docs/远程控制.md index 9811052..6ff227d 100644 --- a/docs/远程控制.md +++ b/docs/远程控制.md @@ -433,7 +433,7 @@ to RFC3339 go test ./... go test -race ./internal/remote cd frontend && npm run type-check -docker compose -f deploy/control-center/compose.yaml config +docker compose -f deploy/control-center/compose.yaml -f deploy/control-center/compose.build.yaml config ./build.sh control ./build.sh build ```