Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- .codex/auth.json +10 -0
- .github/.codex/.auth.json +10 -0
- Dockerfile +3 -0
- README.md +1 -0
- docker-entrypoint.sh +33 -0
.codex/auth.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"OPENAI_API_KEY": null,
|
| 3 |
+
"tokens": {
|
| 4 |
+
"id_token": "${CODEX_ID_TOKEN}",
|
| 5 |
+
"access_token": "${CODEX_ACCESS_TOKEN}",
|
| 6 |
+
"refresh_token": "${CODEX_REFRESH_TOKEN}",
|
| 7 |
+
"account_id": "${CODEX_ACCOUNT_ID}"
|
| 8 |
+
},
|
| 9 |
+
"last_refresh": null
|
| 10 |
+
}
|
.github/.codex/.auth.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"OPENAI_API_KEY": null,
|
| 3 |
+
"tokens": {
|
| 4 |
+
"id_token": "",
|
| 5 |
+
"access_token": "",
|
| 6 |
+
"refresh_token": "",
|
| 7 |
+
"account_id": ""
|
| 8 |
+
},
|
| 9 |
+
"last_refresh": null
|
| 10 |
+
}
|
Dockerfile
CHANGED
|
@@ -66,6 +66,9 @@ COPY . .
|
|
| 66 |
# Expose port 7860 for HF Spaces
|
| 67 |
EXPOSE 7860
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
# Generate SSH keys at runtime (for git over SSH), then start app
|
| 70 |
RUN chmod +x /app/docker-entrypoint.sh
|
| 71 |
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
|
|
|
| 66 |
# Expose port 7860 for HF Spaces
|
| 67 |
EXPOSE 7860
|
| 68 |
|
| 69 |
+
# Codex auth: non-sensitive account ID baked into image (tokens come from runtime secrets).
|
| 70 |
+
ENV CODEX_ACCOUNT_ID="36724931-c63d-429d-91ac-9de1dae41ea8"
|
| 71 |
+
|
| 72 |
# Generate SSH keys at runtime (for git over SSH), then start app
|
| 73 |
RUN chmod +x /app/docker-entrypoint.sh
|
| 74 |
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
README.md
CHANGED
|
@@ -73,5 +73,6 @@ This repo includes a manual workflow at `.github/workflows/codex-autofix.yml`.
|
|
| 73 |
- **Terminal PTY**: the host/container must have PTY devices (`/dev/pts`) available for interactive terminals.
|
| 74 |
- **Codex login (Hugging Face Spaces/web terminal)**: Spaces expose a single port, so localhost callback URLs (like `http://localhost:1455/auth/callback?...`) won’t work; use device auth: `codex login --device-auth` (alias: `codex-login`).
|
| 75 |
- **Codex login persistence (Spaces)**: on startup the container will use `/data/.codex` (if available) for `~/.codex`, so device-auth stays logged in across restarts.
|
|
|
|
| 76 |
- **Gemini CLI**: installed as `gemini` via `npm i -g @google/gemini-cli`. Set one of `GEMINI_API_KEY`, `GOOGLE_GENAI_USE_VERTEXAI`, or `GOOGLE_GENAI_USE_GCA` (Spaces Secret recommended).
|
| 77 |
- **Git over SSH (web terminal/Docker)**: the container auto-generates `~/.ssh/id_ed25519` on first start and prints the public key; add it to your Git provider, then use `git@github.com:ORG/REPO.git` URLs.
|
|
|
|
| 73 |
- **Terminal PTY**: the host/container must have PTY devices (`/dev/pts`) available for interactive terminals.
|
| 74 |
- **Codex login (Hugging Face Spaces/web terminal)**: Spaces expose a single port, so localhost callback URLs (like `http://localhost:1455/auth/callback?...`) won’t work; use device auth: `codex login --device-auth` (alias: `codex-login`).
|
| 75 |
- **Codex login persistence (Spaces)**: on startup the container will use `/data/.codex` (if available) for `~/.codex`, so device-auth stays logged in across restarts.
|
| 76 |
+
- **Codex tokens (Spaces Secrets)**: if you already have tokens, set `CODEX_ID_TOKEN`, `CODEX_ACCESS_TOKEN`, `CODEX_REFRESH_TOKEN` (and optionally `CODEX_ACCOUNT_ID`) as Spaces Secrets; the container will write `~/.codex/auth.json` on startup.
|
| 77 |
- **Gemini CLI**: installed as `gemini` via `npm i -g @google/gemini-cli`. Set one of `GEMINI_API_KEY`, `GOOGLE_GENAI_USE_VERTEXAI`, or `GOOGLE_GENAI_USE_GCA` (Spaces Secret recommended).
|
| 78 |
- **Git over SSH (web terminal/Docker)**: the container auto-generates `~/.ssh/id_ed25519` on first start and prints the public key; add it to your Git provider, then use `git@github.com:ORG/REPO.git` URLs.
|
docker-entrypoint.sh
CHANGED
|
@@ -78,6 +78,38 @@ ensure_codex_home_permissions() {
|
|
| 78 |
chown -R "$(id -u)":"$(id -g)" "${codex_home}" 2>/dev/null || true
|
| 79 |
}
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
ensure_ssh_keypair() {
|
| 82 |
local ssh_dir="${HOME}/.ssh"
|
| 83 |
local key_path="${ssh_dir}/id_ed25519"
|
|
@@ -109,6 +141,7 @@ EOF
|
|
| 109 |
|
| 110 |
persist_codex_dir_if_possible
|
| 111 |
ensure_codex_home_permissions
|
|
|
|
| 112 |
persist_ssh_dir_if_possible
|
| 113 |
ensure_codex_workspace_dir
|
| 114 |
|
|
|
|
| 78 |
chown -R "$(id -u)":"$(id -g)" "${codex_home}" 2>/dev/null || true
|
| 79 |
}
|
| 80 |
|
| 81 |
+
ensure_codex_auth_from_env() {
|
| 82 |
+
local codex_home="${HOME}/.codex"
|
| 83 |
+
local auth_path="${codex_home}/auth.json"
|
| 84 |
+
|
| 85 |
+
# Tokens should be provided as HF Spaces secrets / env vars at runtime.
|
| 86 |
+
# - CODEX_ID_TOKEN
|
| 87 |
+
# - CODEX_ACCESS_TOKEN
|
| 88 |
+
# - CODEX_REFRESH_TOKEN
|
| 89 |
+
# Optional:
|
| 90 |
+
# - CODEX_ACCOUNT_ID (defaults to image ENV)
|
| 91 |
+
if [[ -z "${CODEX_ID_TOKEN:-}" ]] && [[ -z "${CODEX_ACCESS_TOKEN:-}" ]] && [[ -z "${CODEX_REFRESH_TOKEN:-}" ]]; then
|
| 92 |
+
return 0
|
| 93 |
+
fi
|
| 94 |
+
|
| 95 |
+
mkdir -p "${codex_home}"
|
| 96 |
+
cat >"${auth_path}" <<EOF
|
| 97 |
+
{
|
| 98 |
+
"OPENAI_API_KEY": null,
|
| 99 |
+
"tokens": {
|
| 100 |
+
"id_token": "${CODEX_ID_TOKEN:-}",
|
| 101 |
+
"access_token": "${CODEX_ACCESS_TOKEN:-}",
|
| 102 |
+
"refresh_token": "${CODEX_REFRESH_TOKEN:-}",
|
| 103 |
+
"account_id": "${CODEX_ACCOUNT_ID:-}"
|
| 104 |
+
},
|
| 105 |
+
"last_refresh": null
|
| 106 |
+
}
|
| 107 |
+
EOF
|
| 108 |
+
chmod 600 "${auth_path}" 2>/dev/null || true
|
| 109 |
+
chown "$(id -u)":"$(id -g)" "${auth_path}" 2>/dev/null || true
|
| 110 |
+
echo "[codex] Wrote auth config from env to: ${auth_path}"
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
ensure_ssh_keypair() {
|
| 114 |
local ssh_dir="${HOME}/.ssh"
|
| 115 |
local key_path="${ssh_dir}/id_ed25519"
|
|
|
|
| 141 |
|
| 142 |
persist_codex_dir_if_possible
|
| 143 |
ensure_codex_home_permissions
|
| 144 |
+
ensure_codex_auth_from_env
|
| 145 |
persist_ssh_dir_if_possible
|
| 146 |
ensure_codex_workspace_dir
|
| 147 |
|