@@ -33,6 +33,97 @@ if [[ "$CODEX_SHARE_AUTH" == "1" ]]; then
3333 ln -sf "$SHARED_AUTH_FILE" "$AUTH_FILE"
3434fi`
3535
36+ export const renderEntrypointDockerGitBootstrap = ( config : TemplateConfig ) : string =>
37+ `# Bootstrap ~/.docker-git for nested docker-git usage inside this container.
38+ DOCKER_GIT_HOME="/home/${ config . sshUser } /.docker-git"
39+ DOCKER_GIT_AUTH_DIR="$DOCKER_GIT_HOME/.orch/auth/codex"
40+ DOCKER_GIT_ENV_DIR="$DOCKER_GIT_HOME/.orch/env"
41+ DOCKER_GIT_ENV_GLOBAL="$DOCKER_GIT_ENV_DIR/global.env"
42+ DOCKER_GIT_ENV_PROJECT="$DOCKER_GIT_ENV_DIR/project.env"
43+ DOCKER_GIT_AUTH_KEYS="$DOCKER_GIT_HOME/authorized_keys"
44+
45+ mkdir -p "$DOCKER_GIT_AUTH_DIR" "$DOCKER_GIT_ENV_DIR" "$DOCKER_GIT_HOME/.orch/auth/gh"
46+
47+ if [[ -f "/home/${ config . sshUser } /.ssh/authorized_keys" ]]; then
48+ cp "/home/${ config . sshUser } /.ssh/authorized_keys" "$DOCKER_GIT_AUTH_KEYS"
49+ elif [[ -f /authorized_keys ]]; then
50+ cp /authorized_keys "$DOCKER_GIT_AUTH_KEYS"
51+ fi
52+ if [[ -f "$DOCKER_GIT_AUTH_KEYS" ]]; then
53+ chmod 600 "$DOCKER_GIT_AUTH_KEYS" || true
54+ fi
55+
56+ if [[ ! -f "$DOCKER_GIT_ENV_GLOBAL" ]]; then
57+ cat <<'EOF' > "$DOCKER_GIT_ENV_GLOBAL"
58+ # docker-git env
59+ # KEY=value
60+ EOF
61+ fi
62+ if [[ ! -f "$DOCKER_GIT_ENV_PROJECT" ]]; then
63+ cat <<'EOF' > "$DOCKER_GIT_ENV_PROJECT"
64+ # docker-git project env defaults
65+ CODEX_SHARE_AUTH=1
66+ CODEX_AUTO_UPDATE=1
67+ DOCKER_GIT_ZSH_AUTOSUGGEST=1
68+ DOCKER_GIT_ZSH_AUTOSUGGEST_STYLE=fg=8,italic
69+ DOCKER_GIT_ZSH_AUTOSUGGEST_STRATEGY=history completion
70+ MCP_PLAYWRIGHT_ISOLATED=1
71+ EOF
72+ fi
73+
74+ upsert_env_var() {
75+ local file="$1"
76+ local key="$2"
77+ local value="$3"
78+ local tmp
79+ tmp="$(mktemp)"
80+ awk -v key="$key" 'index($0, key "=") != 1 { print }' "$file" > "$tmp"
81+ printf "%s=%s\\n" "$key" "$value" >> "$tmp"
82+ mv "$tmp" "$file"
83+ }
84+
85+ copy_if_distinct_file() {
86+ local source="$1"
87+ local target="$2"
88+ if [[ ! -f "$source" ]]; then
89+ return 1
90+ fi
91+ local source_real=""
92+ local target_real=""
93+ source_real="$(readlink -f "$source" 2>/dev/null || true)"
94+ target_real="$(readlink -f "$target" 2>/dev/null || true)"
95+ if [[ -n "$source_real" && -n "$target_real" && "$source_real" == "$target_real" ]]; then
96+ return 0
97+ fi
98+ cp "$source" "$target"
99+ return 0
100+ }
101+
102+ if [[ -n "$GH_TOKEN" ]]; then
103+ upsert_env_var "$DOCKER_GIT_ENV_GLOBAL" "GH_TOKEN" "$GH_TOKEN"
104+ fi
105+ if [[ -n "$GITHUB_TOKEN" ]]; then
106+ upsert_env_var "$DOCKER_GIT_ENV_GLOBAL" "GITHUB_TOKEN" "$GITHUB_TOKEN"
107+ elif [[ -n "$GH_TOKEN" ]]; then
108+ upsert_env_var "$DOCKER_GIT_ENV_GLOBAL" "GITHUB_TOKEN" "$GH_TOKEN"
109+ fi
110+
111+ SOURCE_CODEX_CONFIG="${ config . codexHome } /config.toml"
112+ copy_if_distinct_file "$SOURCE_CODEX_CONFIG" "$DOCKER_GIT_AUTH_DIR/config.toml" || true
113+
114+ SOURCE_SHARED_AUTH="${ config . codexHome } -shared/auth.json"
115+ SOURCE_LOCAL_AUTH="${ config . codexHome } /auth.json"
116+ if [[ -f "$SOURCE_SHARED_AUTH" ]]; then
117+ copy_if_distinct_file "$SOURCE_SHARED_AUTH" "$DOCKER_GIT_AUTH_DIR/auth.json" || true
118+ elif [[ -f "$SOURCE_LOCAL_AUTH" ]]; then
119+ copy_if_distinct_file "$SOURCE_LOCAL_AUTH" "$DOCKER_GIT_AUTH_DIR/auth.json" || true
120+ fi
121+ if [[ -f "$DOCKER_GIT_AUTH_DIR/auth.json" ]]; then
122+ chmod 600 "$DOCKER_GIT_AUTH_DIR/auth.json" || true
123+ fi
124+
125+ chown -R 1000:1000 "$DOCKER_GIT_HOME" || true`
126+
36127const entrypointMcpPlaywrightTemplate = String . raw `# Optional: configure Playwright MCP for Codex (browser automation)
37128CODEX_CONFIG_FILE="__CODEX_HOME__/config.toml"
38129
0 commit comments