wenjiandeniu commited on
Commit
30bc326
·
1 Parent(s): a713f1a

upgrade: base image to latest ghcr official image with automated updates

Browse files
Files changed (1) hide show
  1. Dockerfile +5 -49
Dockerfile CHANGED
@@ -1,52 +1,6 @@
1
  # syntax=docker/dockerfile:1
2
 
3
- FROM alpine:3.19 AS source
4
-
5
- WORKDIR /src
6
-
7
- RUN apk add --no-cache tar
8
-
9
- ADD https://codeload.github.com/james-6-23/codex2api/tar.gz/refs/heads/main /tmp/codex2api.tar.gz
10
-
11
- RUN tar -xzf /tmp/codex2api.tar.gz --strip-components=1 -C /src
12
-
13
- # Upstream currently stops the store twice during shutdown, which causes
14
- # `panic: close of closed channel` on platforms that send SIGTERM during
15
- # health/restart cycles. Remove the deferred stop and keep the explicit
16
- # shutdown path.
17
- RUN sed -i '/defer store.Stop()/d' /src/main.go
18
-
19
- FROM node:20-alpine AS frontend-builder
20
-
21
- WORKDIR /frontend
22
-
23
- COPY --from=source /src/frontend/package.json /src/frontend/package-lock.json ./
24
-
25
- RUN --mount=type=cache,target=/root/.npm \
26
- npm ci --no-audit --no-fund
27
-
28
- COPY --from=source /src/frontend/ .
29
-
30
- ARG BUILD_VERSION=hf-space
31
-
32
- RUN VITE_APP_VERSION=${BUILD_VERSION} npm run build
33
-
34
- FROM golang:1.25-alpine AS go-builder
35
-
36
- WORKDIR /app
37
-
38
- COPY --from=source /src/go.mod /src/go.sum ./
39
-
40
- RUN --mount=type=cache,target=/go/pkg/mod \
41
- go mod download
42
-
43
- COPY --from=source /src/ .
44
- COPY --from=frontend-builder /frontend/dist ./frontend/dist
45
-
46
- RUN --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
-
50
  FROM alpine:3.19
51
 
52
  RUN apk --no-cache add ca-certificates tzdata \
@@ -54,6 +8,7 @@ RUN apk --no-cache add ca-certificates tzdata \
54
  && mkdir -p /data \
55
  && chmod 777 /data
56
 
 
57
  ENV HOME=/home/user \
58
  PATH=/home/user/.local/bin:$PATH \
59
  CODEX_PORT=8080 \
@@ -62,11 +17,12 @@ ENV HOME=/home/user \
62
  DATABASE_PATH=/data/codex2api.db \
63
  TZ=Asia/Shanghai
64
 
 
 
 
65
  USER user
66
  WORKDIR $HOME/app
67
 
68
- COPY --from=go-builder /codex2api /usr/local/bin/codex2api
69
-
70
  EXPOSE 8080
71
 
72
  ENTRYPOINT ["/usr/local/bin/codex2api"]
 
1
  # syntax=docker/dockerfile:1
2
 
3
+ # 1. 继承原版 alpine:3.19 作为底座,确保 Hugging Face 平台的 UID 1000 权限完全兼容
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  FROM alpine:3.19
5
 
6
  RUN apk --no-cache add ca-certificates tzdata \
 
8
  && mkdir -p /data \
9
  && chmod 777 /data
10
 
11
+ # 2. 声明云端环境运行在 SQLite 和内存缓存模式下
12
  ENV HOME=/home/user \
13
  PATH=/home/user/.local/bin:$PATH \
14
  CODEX_PORT=8080 \
 
17
  DATABASE_PATH=/data/codex2api.db \
18
  TZ=Asia/Shanghai
19
 
20
+ # 3. 直接从官方发布的最新 Docker 镜像中,提取已经编译且嵌入前端的最新可执行程序
21
+ COPY --from=ghcr.io/james-6-23/codex2api:latest /usr/local/bin/codex2api /usr/local/bin/codex2api
22
+
23
  USER user
24
  WORKDIR $HOME/app
25
 
 
 
26
  EXPOSE 8080
27
 
28
  ENTRYPOINT ["/usr/local/bin/codex2api"]