ltxlong/codex2api-sqlite
0
1# syntax=docker/dockerfile:12 3FROM alpine:3.19 AS source4 5WORKDIR /src6 7RUN apk add --no-cache tar8 9ADD https://codeload.github.com/james-6-23/codex2api/tar.gz/refs/heads/main /tmp/codex2api.tar.gz10 11RUN tar -xzf /tmp/codex2api.tar.gz --strip-components=1 -C /src12 13# Upstream currently stops the store twice during shutdown, which causes14# `panic: close of closed channel` on platforms that send SIGTERM during15# health/restart cycles. Remove the deferred stop and keep the explicit16# shutdown path.17RUN sed -i '/defer store.Stop()/d' /src/main.go18 19FROM node:20-alpine AS frontend-builder20 21WORKDIR /frontend22 23COPY --from=source /src/frontend/package.json /src/frontend/package-lock.json ./24 25RUN --mount=type=cache,target=/root/.npm \26 npm ci --no-audit --no-fund27 28COPY --from=source /src/frontend/ .29 30ARG BUILD_VERSION=hf-space31 32RUN VITE_APP_VERSION=${BUILD_VERSION} npm run build33 34FROM golang:1.25-alpine AS go-builder35 36WORKDIR /app37 38COPY --from=source /src/go.mod /src/go.sum ./39 40RUN --mount=type=cache,target=/go/pkg/mod \41 go mod download42 43COPY --from=source /src/ .44COPY --from=frontend-builder /frontend/dist ./frontend/dist45 46RUN --mount=type=cache,target=/go/pkg/mod \47 --mount=type=cache,target=/root/.cache/go-build \48 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /codex2api .49 50FROM alpine:3.1951 52RUN apk --no-cache add ca-certificates tzdata \53 && adduser -D -u 1000 user \54 && mkdir -p /data \55 && chmod 777 /data56 57ENV HOME=/home/user \58 PATH=/home/user/.local/bin:$PATH \59 CODEX_PORT=8080 \60 DATABASE_DRIVER=sqlite \61 CACHE_DRIVER=memory \62 DATABASE_PATH=/data/codex2api.db \63 TZ=Asia/Shanghai64 65USER user66WORKDIR $HOME/app67 68COPY --from=go-builder /codex2api /usr/local/bin/codex2api69 70EXPOSE 808071 72ENTRYPOINT ["/usr/local/bin/codex2api"]73 