From 7a65d1eaa24faea89d332ced23a1996cc8ea2416 Mon Sep 17 00:00:00 2001 From: jacob-sheng Date: Sat, 21 Mar 2026 09:55:53 +0800 Subject: [PATCH] fix: allow Docker builds without BUILD_VERSION --- DEPLOY.en.md | 1 + DEPLOY.md | 1 + Dockerfile | 2 +- README.MD | 2 ++ README.en.md | 2 ++ zeabur.yaml | 1 + 6 files changed, 8 insertions(+), 1 deletion(-) diff --git a/DEPLOY.en.md b/DEPLOY.en.md index 2304cfd..8f5ae27 100644 --- a/DEPLOY.en.md +++ b/DEPLOY.en.md @@ -181,6 +181,7 @@ Notes: - **Port**: DS2API listens on `5001` by default; the template sets `PORT=5001`. - **Persistent config**: the template mounts `/data` and sets `DS2API_CONFIG_PATH=/data/config.json`. After importing config in Admin UI, it will be written and persisted to this path. +- **Build version**: Zeabur / regular `docker build` does not require `BUILD_VERSION` by default. The image prefers that build arg when provided, and automatically falls back to the repo-root `VERSION` file when it is absent. - **First login**: after deployment, open `/admin` and login with `DS2API_ADMIN_KEY` shown in Zeabur env/template instructions (recommended: rotate to a strong secret after first login). --- diff --git a/DEPLOY.md b/DEPLOY.md index 93364ef..1c71b91 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -181,6 +181,7 @@ healthcheck: - **端口**:服务默认监听 `5001`,模板会固定设置 `PORT=5001`。 - **配置持久化**:模板挂载卷 `/data`,并设置 `DS2API_CONFIG_PATH=/data/config.json`;在管理台导入配置后,会写入并持久化到该路径。 +- **构建版本号**:Zeabur / 普通 `docker build` 默认不需要传 `BUILD_VERSION`;镜像会优先使用该构建参数,未提供时自动回退到仓库根目录的 `VERSION` 文件。 - **首次登录**:部署完成后访问 `/admin`,使用 Zeabur 环境变量/模板指引中的 `DS2API_ADMIN_KEY` 登录(建议首次登录后自行更换为强密码)。 --- diff --git a/Dockerfile b/Dockerfile index 19c24ea..6aa1974 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ COPY . . RUN set -eux; \ GOOS="${TARGETOS:-$(go env GOOS)}"; \ GOARCH="${TARGETARCH:-$(go env GOARCH)}"; \ - BUILD_VERSION_RESOLVED="${BUILD_VERSION}"; \ + BUILD_VERSION_RESOLVED="${BUILD_VERSION:-}"; \ if [ -z "${BUILD_VERSION_RESOLVED}" ] && [ -f VERSION ]; then BUILD_VERSION_RESOLVED="$(cat VERSION | tr -d "[:space:]")"; fi; \ CGO_ENABLED=0 GOOS="${GOOS}" GOARCH="${GOARCH}" go build -ldflags="-s -w -X ds2api/internal/version.BuildVersion=${BUILD_VERSION_RESOLVED}" -o /out/ds2api ./cmd/ds2api diff --git a/README.MD b/README.MD index 9946515..1544ca8 100644 --- a/README.MD +++ b/README.MD @@ -178,6 +178,8 @@ docker-compose logs -f 2. 部署完成后访问 `/admin`,使用 Zeabur 环境变量/模板指引中的 `DS2API_ADMIN_KEY` 登录。 3. 在管理台导入/编辑配置(会写入并持久化到 `/data/config.json`)。 +说明:Zeabur 使用仓库内 `Dockerfile` 直接构建时,不需要额外传入 `BUILD_VERSION`;镜像会优先读取该构建参数,未提供时自动回退到仓库根目录的 `VERSION` 文件。 + ### 方式三:Vercel 部署 1. Fork 仓库到自己的 GitHub diff --git a/README.en.md b/README.en.md index 8ab7b32..8b4ddef 100644 --- a/README.en.md +++ b/README.en.md @@ -178,6 +178,8 @@ Rebuild after updates: `docker-compose up -d --build` 2. After deployment, open `/admin` and login with `DS2API_ADMIN_KEY` shown in Zeabur env/template instructions. 3. Import / edit config in Admin UI (it will be written and persisted to `/data/config.json`). +Note: when Zeabur builds directly from the repo `Dockerfile`, you do not need to pass `BUILD_VERSION`. The image prefers that build arg when provided, and automatically falls back to the repo-root `VERSION` file when it is absent. + ### Option 3: Vercel 1. Fork this repo to your GitHub account diff --git a/zeabur.yaml b/zeabur.yaml index 8d36cb4..c1ba6bf 100644 --- a/zeabur.yaml +++ b/zeabur.yaml @@ -16,6 +16,7 @@ spec: - Admin panel: `/admin` - Health check: `/healthz` - Config is persisted at `/data/config.json` (mounted volume) + - `BUILD_VERSION` is optional; when omitted, Docker build falls back to the repo `VERSION` file automatically ## First-time setup 1. Open your service URL, then visit `/admin`