@@ -82,6 +82,7 @@ RUN node --version \
8282
8383# Install global npm tools (codex + MCP utilities)
8484ARG CODEX_CLI_VERSION=0.123.0
85+ ENV CODEX_CLI_VERSION=${CODEX_CLI_VERSION}
8586RUN npm install -g \
8687 @openai/codex@${CODEX_CLI_VERSION} \
8788 mcp-safe-proxy \
@@ -125,34 +126,66 @@ COPY drizzle/ ./drizzle/
125126RUN 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
130131set -euo pipefail
131132
132133ROOT_SEED="/opt/root-seed.tar.gz"
133134ROOT_MARKER="/root/.codex-webui-initialized"
135+ VERSION_MARKER="/root/.codex-webui-version"
134136
135137is_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 ──────────────────────────────────────
140143if 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}"
144148elif [ ! -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."
147151else
148152 echo "[entrypoint] /root already initialized."
149153fi
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)
152185mkdir -p /root/.codex /workspaces /app/logs
153186
154187exec "$@"
155- EOF
188+ ENTRYPOINT_EOF
156189
157190RUN chmod +x /usr/local/bin/entrypoint.sh
158191
0 commit comments