fix: inject PROXY_VERSION at Docker build time to fix stale version display (#676)#677
Open
icebear0828 wants to merge 6 commits into
Open
fix: inject PROXY_VERSION at Docker build time to fix stale version display (#676)#677icebear0828 wants to merge 6 commits into
icebear0828 wants to merge 6 commits into
Conversation
…isplay
Docker containers lack .git so getProxyInfo() falls back to package.json
which hasn't been bumped (still 2.0.77 while tag is 2.0.80).
Changes:
- Dockerfile: add ARG PROXY_VERSION + ENV PROXY_VERSION=${PROXY_VERSION}
- docker-publish.yml: pass build-args: PROXY_VERSION=<computed-version>
- src/self-update.ts: getProxyInfo() checks process.env.PROXY_VERSION first,
falls back to git-tag / package.json for non-Docker environments
Fixes #676
Owner
Author
Self-review Notes总体评价核心机制( 🔴 Must Fix1. CI smoke 未传
建议 smoke step 改为: run: |
PKG_VER=$(node -p "require('./package.json').version")
docker build -t codex-proxy:smoke --build-arg PROXY_VERSION=$PKG_VER .
docker run --rm codex-proxy:smoke node -e "const m=require('./dist/self-update.js'); const v=m.getProxyInfo().version; if(!v) process.exit(1); console.log('version:',v)"2. 缺少单元测试(违反项目 TDD 规范)
it("prefers PROXY_VERSION env over package.json", () => {
process.env.PROXY_VERSION = "9.9.9";
try {
expect(getProxyInfo().version).toBe("9.9.9");
} finally {
delete process.env.PROXY_VERSION;
}
});🟢 Low
|
icebear0828
commented
Jun 17, 2026
icebear0828
left a comment
Owner
Author
There was a problem hiding this comment.
Review
核心逻辑正确,有三个小问题建议处理:
🟡 envVersion !== "1.0.0" 过滤逻辑有歧义
如果有人手动 export PROXY_VERSION=1.0.0(合法的版本号),会被静默忽略并 fallback 到 git/package.json,行为不符合预期。建议只过滤空字符串:
const envVersion = process.env.PROXY_VERSION?.trim();
if (envVersion) { // 不再额外排除 1.0.0
version = envVersion;
}🟡 ARG PROXY_VERSION 缺默认值
如果 CI 忘记传 --build-arg PROXY_VERSION=...,PROXY_VERSION 会为空,静默 fallback 到旧逻辑而不报错。建议加默认值:
ARG PROXY_VERSION=unknown
ENV PROXY_VERSION=${PROXY_VERSION}并在启动时检测到 unknown 时打一条 warning。
🟡 docker-publish.yml 改动
PR body 提到 CI 会传 build-args: PROXY_VERSION=<computed>,但 diff 里没看到 workflow 文件变更,请确认是否已包含在本 PR 中。
🟢 做得好的地方
- 优先级链清晰:env → git tag → package.json
- 测试覆盖了 env 优先级场景
1.0.0的过滤与下层逻辑一致(即使建议修改,至少现在行为是一致的)
…Y_VERSION including 1.0.0 - Dockerfile ARG PROXY_VERSION defaults to 'unknown' instead of empty - getProxyInfo() filters out 'unknown' (not real version) and falls back to git/package.json - Remove the 1.0.0 exclusion — users setting PROXY_VERSION=1.0.0 explicitly should have it respected - Add tests: 'unknown' fallback + 1.0.0 acceptance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Docker 容器内没有
.git,所以getProxyInfo()只能读package.json。但package.json的 version 字段一直停在2.0.77(tag-only 发版策略不 bump package.json),导致容器始终显示旧版本。修复
DockerfileARG PROXY_VERSION+ENV PROXY_VERSION=${PROXY_VERSION}docker-publish.ymlbuild-args: PROXY_VERSION=<computed>src/self-update.tsgetProxyInfo()优先读process.env.PROXY_VERSION,无环境变量时回退 git-tag / package.json验证
Closes #676