Skip to content

Commit 8bd9548

Browse files
committed
fix(docker): 修复容器启动时 Codex 版本不同步问题
- 将 CODEX_CLI_VERSION 导出为环境变量,供运行时入口脚本读取 - 在初始化 /root 种子数据时写入版本标记文件,记录已安装的 Codex 版本 - 启动时比对镜像内期望版本与已安装版本,不一致时自动执行全局升级 - 升级后重建相关 arg0 符号链接,避免多调用二进制路径变化导致工具失效 - 保留升级失败时的降级处理,输出告警并继续使用当前已安装版本
1 parent 10c3634 commit 8bd9548

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

Dockerfile

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ RUN node --version \
8282

8383
# Install global npm tools (codex + MCP utilities)
8484
ARG CODEX_CLI_VERSION=0.123.0
85+
ENV CODEX_CLI_VERSION=${CODEX_CLI_VERSION}
8586
RUN npm install -g \
8687
@openai/codex@${CODEX_CLI_VERSION} \
8788
mcp-safe-proxy \
@@ -125,34 +126,66 @@ COPY drizzle/ ./drizzle/
125126
RUN tar -C /root -czf /opt/root-seed.tar.gz .
126127

127128
# ── Entrypoint ───────────────────────────────────────────────────────
128-
RUN cat > /usr/local/bin/entrypoint.sh <<'EOF'
129+
RUN cat > /usr/local/bin/entrypoint.sh <<'ENTRYPOINT_EOF'
129130
#!/usr/bin/env bash
130131
set -euo pipefail
131132

132133
ROOT_SEED="/opt/root-seed.tar.gz"
133134
ROOT_MARKER="/root/.codex-webui-initialized"
135+
VERSION_MARKER="/root/.codex-webui-version"
134136

135137
is_root_empty() {
136138
find /root -mindepth 1 -maxdepth 1 -print -quit | grep -q . && return 1
137139
return 0
138140
}
139141

142+
# ── Phase 1: Root seed restore ──────────────────────────────────────
140143
if is_root_empty; then
141144
echo "[entrypoint] /root is empty, restoring seed data..."
142145
tar -C /root -xzf "${ROOT_SEED}"
143146
touch "${ROOT_MARKER}"
147+
echo "${CODEX_CLI_VERSION:-unknown}" > "${VERSION_MARKER}"
144148
elif [ ! -e "${ROOT_MARKER}" ] && [ ! -d /root/.local/share/mise ]; then
145149
echo "[entrypoint] /root has data but mise seed is missing; leaving unchanged."
146150
echo "[entrypoint] Clear the host volume and restart if this is unintended."
147151
else
148152
echo "[entrypoint] /root already initialized."
149153
fi
150154

155+
# ── Phase 2: Codex version upgrade ─────────────────────────────────
156+
# Compare image-embedded CODEX_CLI_VERSION with installed version.
157+
# If different, upgrade codex and rebuild arg0 symlinks.
158+
EXPECTED_VER="${CODEX_CLI_VERSION:-}"
159+
INSTALLED_VER=""
160+
if [ -f "${VERSION_MARKER}" ]; then
161+
INSTALLED_VER="$(cat "${VERSION_MARKER}" 2>/dev/null || true)"
162+
fi
163+
164+
if [ -n "${EXPECTED_VER}" ] && [ "${EXPECTED_VER}" != "${INSTALLED_VER}" ]; then
165+
echo "[entrypoint] Codex version mismatch: installed=${INSTALLED_VER:-none}, expected=${EXPECTED_VER}"
166+
echo "[entrypoint] Upgrading @openai/codex to ${EXPECTED_VER}..."
167+
if npm install -g "@openai/codex@${EXPECTED_VER}" 2>&1; then
168+
echo "${EXPECTED_VER}" > "${VERSION_MARKER}"
169+
echo "[entrypoint] Codex upgraded to ${EXPECTED_VER}"
170+
171+
# Rebuild arg0 symlinks (codex multi-call binary may have moved)
172+
CODEX_BIN="$(find /root/.local/share/mise -name codex -path '*/vendor/*/codex/codex' -type f 2>/dev/null | head -1)"
173+
if [ -n "${CODEX_BIN}" ]; then
174+
for tool in apply_patch applypatch codex-execve-wrapper codex-linux-sandbox; do
175+
ln -sf "${CODEX_BIN}" "/usr/local/bin/${tool}"
176+
done
177+
echo "[entrypoint] Rebuilt arg0 symlinks -> ${CODEX_BIN}"
178+
fi
179+
else
180+
echo "[entrypoint] WARNING: Codex upgrade failed, continuing with installed version"
181+
fi
182+
fi
183+
151184
# Ensure directories exist (in case volume is pre-populated but partial)
152185
mkdir -p /root/.codex /workspaces /app/logs
153186

154187
exec "$@"
155-
EOF
188+
ENTRYPOINT_EOF
156189

157190
RUN chmod +x /usr/local/bin/entrypoint.sh
158191

0 commit comments

Comments
 (0)