Skip to content

Commit 26c31f9

Browse files
committed
feat: docker-compose.yml 镜像引用变量化,setup-env.sh 自动检测中国大陆并换源
- compose 文件镜像引用全部改为 ${CONTAINER_REGISTRY:-ghcr.io}/... - setup-env.sh 启动时自动检测 ghcr.io 连通性,不可达则提示切换镜像源 - 用户确认后自动写入 CONTAINER_REGISTRY=ghcr.1ms.run 到 .env - compose 拉取和运行时 docker pull 全部自动走镜像源 - 删除 docker-compose.cn.yml,不再需要单独覆盖文件
1 parent 666c928 commit 26c31f9

6 files changed

Lines changed: 42 additions & 82 deletions

File tree

deploy/scripts/setup-env.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ else
9898
log "将使用外部 PostgreSQL"
9999
fi
100100

101+
# ── 镜像源检测 ──────────────────────────────────────────────
102+
103+
CONTAINER_REGISTRY=""
104+
if command -v curl &>/dev/null; then
105+
echo ""
106+
log "正在检测 ghcr.io 连通性..."
107+
if curl -sSf --connect-timeout 5 --max-time 10 "https://ghcr.io" >/dev/null 2>&1; then
108+
log "ghcr.io 直接可达"
109+
else
110+
warn "ghcr.io 不可达(可能在防火墙后),建议使用镜像源 ghcr.1ms.run"
111+
echo ""
112+
printf "是否将镜像源切换为 ghcr.1ms.run(毫秒镜像)? [Y/n]: "
113+
read -r USE_MIRROR
114+
USE_MIRROR="${USE_MIRROR:-y}"
115+
if [[ "$USE_MIRROR" == "y" || "$USE_MIRROR" == "Y" ]]; then
116+
CONTAINER_REGISTRY="ghcr.1ms.run"
117+
log "将使用中国大陆镜像源"
118+
fi
119+
fi
120+
else
121+
warn "未检测到 curl,跳过镜像源检测"
122+
fi
123+
101124
# ── 控制面和管理员 ──────────────────────────────────────────
102125

103126
echo ""
@@ -148,6 +171,9 @@ ADMIN_USERNAME=${ADMIN_USER}
148171
ADMIN_PASSWORD=${ADMIN_PASSWORD}
149172
ADMIN_JWT_SECRET=${ADMIN_JWT_SECRET}
150173
174+
# Container Registry
175+
CONTAINER_REGISTRY=${CONTAINER_REGISTRY}
176+
151177
# Logging
152178
LOG_FORMAT=json
153179
LOG_LEVEL=info

docker-compose.build.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ services:
33
build:
44
context: .
55
dockerfile: deploy/docker/control-plane/Dockerfile
6-
image: ghcr.io/zanel1u/cloud-cli-proxy/control-plane:latest
6+
image: ${CONTAINER_REGISTRY:-ghcr.io}/zanel1u/cloud-cli-proxy/control-plane:latest
77
pull_policy: never
88

99
admin:
1010
build:
1111
context: .
1212
dockerfile: deploy/docker/admin/Dockerfile
13-
image: ghcr.io/zanel1u/cloud-cli-proxy/admin:latest
13+
image: ${CONTAINER_REGISTRY:-ghcr.io}/zanel1u/cloud-cli-proxy/admin:latest
1414
pull_policy: never
1515

1616
managed-user-image:
1717
build:
1818
context: .
1919
dockerfile: deploy/docker/managed-user/Dockerfile
20-
image: ghcr.io/zanel1u/cloud-cli-proxy/managed-user:latest
20+
image: ${CONTAINER_REGISTRY:-ghcr.io}/zanel1u/cloud-cli-proxy/managed-user:latest
2121
pull_policy: never
2222
command: ["true"]
2323
profiles:

docker-compose.cn.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

docker-compose.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
- cloudproxy-postgres:/var/lib/postgresql
1616

1717
control-plane:
18-
image: ghcr.io/zanel1u/cloud-cli-proxy/control-plane:latest
18+
image: ${CONTAINER_REGISTRY:-ghcr.io}/zanel1u/cloud-cli-proxy/control-plane:latest
1919
pull_policy: always
2020
restart: unless-stopped
2121
depends_on:
@@ -31,6 +31,7 @@ services:
3131
ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET:?Set ADMIN_JWT_SECRET in .env}
3232
LOG_FORMAT: ${LOG_FORMAT:-json}
3333
LOG_LEVEL: ${LOG_LEVEL:-info}
34+
CONTAINER_REGISTRY: ${CONTAINER_REGISTRY:-}
3435
ports:
3536
- "${SSH_PROXY_PORT:-2222}:2222"
3637
pid: host
@@ -48,7 +49,7 @@ services:
4849
start_period: 30s
4950

5051
admin:
51-
image: ghcr.io/zanel1u/cloud-cli-proxy/admin:latest
52+
image: ${CONTAINER_REGISTRY:-ghcr.io}/zanel1u/cloud-cli-proxy/admin:latest
5253
pull_policy: always
5354
restart: unless-stopped
5455
depends_on:
@@ -59,14 +60,14 @@ services:
5960

6061
# 预拉取镜像,保持本地缓存。host-agent 通过 docker create 使用此镜像。
6162
managed-user:
62-
image: ghcr.io/zanel1u/cloud-cli-proxy/managed-user:latest
63+
image: ${CONTAINER_REGISTRY:-ghcr.io}/zanel1u/cloud-cli-proxy/managed-user:latest
6364
pull_policy: always
6465
restart: "no"
6566
command: ["true"]
6667

6768
# 预拉取探针镜像,供 egress IP 连通性测试使用。
6869
sing-box:
69-
image: ghcr.io/sagernet/sing-box:v1.13.3
70+
image: ${CONTAINER_REGISTRY:-ghcr.io}/sagernet/sing-box:v1.13.3
7071
pull_policy: always
7172
restart: "no"
7273
command: ["true"]

docs/en/guide/deployment.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,38 +59,17 @@ curl http://127.0.0.1:8080/healthz
5959

6060
## Users in Mainland China
6161

62-
### Option 1: Use docker-compose.cn.yml (recommended)
62+
`ghcr.io` may be slow or unreachable from within mainland China. `setup-env.sh` auto-detects connectivity and prompts whether to switch to `ghcr.1ms.run` mirror. Accept and it writes the setting to `.env`. Then just `docker compose pull && docker compose up -d`.
6363

64-
The repo includes `docker-compose.cn.yml`, which pre-configures `ghcr.1ms.run` mirror for compose images and sets the `CONTAINER_REGISTRY` environment variable so that runtime image pulls (`managed-user`, `sing-box` probe) also go through the mirror. Start with the override file:
65-
66-
```bash
67-
docker compose -f docker-compose.yml -f docker-compose.cn.yml pull
68-
docker compose -f docker-compose.yml -f docker-compose.cn.yml up -d
69-
```
70-
71-
For bare-metal systemd deployments, add to `/etc/cloud-cli-proxy/env`:
64+
If you already generated `.env`, add this line manually:
7265

7366
```bash
7467
CONTAINER_REGISTRY=ghcr.1ms.run
7568
```
7669

77-
Restart the control plane. All `docker pull` operations will use the mirror.
78-
79-
Building from source (fallback):
80-
81-
```bash
82-
docker compose -f docker-compose.yml -f docker-compose.cn.yml -f docker-compose.build.yaml --profile build-only build --no-cache
83-
docker compose -f docker-compose.yml -f docker-compose.cn.yml -f docker-compose.build.yaml up -d --force-recreate
84-
```
85-
86-
### Option 2: Pull through a local proxy
70+
This variable controls both compose image pulls and runtime `docker pull` operations (`managed-user` updates, `sing-box` probes). Every `ghcr.io` reference is replaced.
8771

88-
If your machine already has a TUN-mode proxy or global proxy, the default compose file works:
89-
90-
```bash
91-
docker compose pull
92-
docker compose up -d
93-
```
72+
For bare-metal systemd deployments, add the same line to `/etc/cloud-cli-proxy/env` and restart the control plane.
9473

9574
## Environment Variables
9675

docs/zh/guide/deployment.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,38 +59,17 @@ curl http://127.0.0.1:8080/healthz
5959

6060
## 中国大陆用户
6161

62-
### 方案一:使用 docker-compose.cn.yml(推荐)
62+
中国大陆访问 `ghcr.io` 可能较慢或不可达。`setup-env.sh` 会自动检测连通性,如果不可达会提示你是否切换到 `ghcr.1ms.run`(毫秒镜像),同意后自动写入 `.env`。直接 `docker compose pull && docker compose up -d` 即可。
6363

64-
项目提供了 `docker-compose.cn.yml`,已将 compose 镜像替换为 `ghcr.1ms.run`(毫秒镜像),同时设置了 `CONTAINER_REGISTRY` 环境变量,确保运行时动态拉取的镜像(`managed-user``sing-box` 探针)也走同一镜像源。直接通过覆盖文件启动:
65-
66-
```bash
67-
docker compose -f docker-compose.yml -f docker-compose.cn.yml pull
68-
docker compose -f docker-compose.yml -f docker-compose.cn.yml up -d
69-
```
70-
71-
systemd 裸机部署的用户,在 `/etc/cloud-cli-proxy/env` 中加上:
64+
如果已经生成了 `.env`,手动加上一行:
7265

7366
```bash
7467
CONTAINER_REGISTRY=ghcr.1ms.run
7568
```
7669

77-
重启控制面后生效。所有 `docker pull` 操作都会自动走镜像源。
78-
79-
源码构建(兜底):
80-
81-
```bash
82-
docker compose -f docker-compose.yml -f docker-compose.cn.yml -f docker-compose.build.yaml --profile build-only build --no-cache
83-
docker compose -f docker-compose.yml -f docker-compose.cn.yml -f docker-compose.build.yaml up -d --force-recreate
84-
```
85-
86-
### 方案二:走本地代理拉取
70+
这个变量同时控制 compose 镜像拉取和运行时 `docker pull``managed-user` 更新、`sing-box` 探针),所有 `ghcr.io` 引用都会自动替换。
8771

88-
本机已开 TUN 模式或全局代理,镜像走代理出站,直接用默认 compose 文件即可:
89-
90-
```bash
91-
docker compose pull
92-
docker compose up -d
93-
```
72+
systemd 裸机部署同理,在 `/etc/cloud-cli-proxy/env` 中加上这一行后重启控制面。
9473

9574
## 环境变量
9675

0 commit comments

Comments
 (0)