-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathDockerfile
More file actions
77 lines (56 loc) · 2.56 KB
/
Dockerfile
File metadata and controls
77 lines (56 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# ── Stage 1: Build native TLS addon (Rust → .node) ──────────────────
FROM rust:1-slim AS native-builder
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential python3 curl ca-certificates gnupg && \
rm -rf /var/lib/apt/lists/*
# Install Node.js 20 (needed by napi-rs CLI)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y --no-install-recommends nodejs && \
rm -rf /var/lib/apt/lists/*
WORKDIR /native
# Cache Cargo deps first
COPY native/Cargo.toml native/Cargo.lock native/build.rs ./
RUN mkdir src && echo '#[allow(dead_code)] fn main(){}' > src/lib.rs && \
cargo build --release 2>/dev/null || true
# Build real addon
COPY native/ ./
RUN npm ci && npm run build
# ── Stage 2: Application ────────────────────────────────────────────
FROM node:20-slim
# curl: needed by setup-curl.ts and full-update.ts
# unzip: needed by full-update.ts to extract Codex.app
# gosu: needed by entrypoint to drop from root to node user
RUN apt-get update && \
apt-get install -y --no-install-recommends curl unzip ca-certificates gosu && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# 1) Backend deps (postinstall runs tsx scripts/setup-curl.ts)
COPY package*.json tsconfig.json ./
COPY scripts/ scripts/
RUN npm ci
# Fail fast if curl-impersonate wasn't downloaded
RUN test -f bin/curl-impersonate || \
(echo "FATAL: curl-impersonate not downloaded. Check network." && exit 1)
# 2) Web deps (separate layer for cache efficiency)
COPY web/package*.json web/
RUN cd web && npm ci
# 3) Copy source
COPY . .
# 4) Copy native addon from builder stage (overwrite macOS .node if present)
COPY --from=native-builder /native/codex-tls.linux-*.node /app/native/
# 5) Build frontend (Vite → public/) + backend (tsc → dist/)
RUN cd web && npm run build && cd .. && npx tsc
# 6) Prune dev deps, re-add tsx (needed at runtime by update-checker fork())
RUN npm prune --omit=dev && npm install --no-save tsx
EXPOSE 8080
# Ensure data dir exists in the image (bind mount may override at runtime)
RUN mkdir -p /app/data
# Backup default configs so entrypoint can seed empty bind mounts
RUN cp -r /app/config /defaults
COPY docker-entrypoint.sh /
COPY docker-healthcheck.sh /
RUN chmod +x /docker-entrypoint.sh /docker-healthcheck.sh
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD /docker-healthcheck.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["node", "dist/index.js"]