wenjiandeniu commited on
Commit
e6ea4f8
·
verified ·
1 Parent(s): 8452c23

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +66 -0
Dockerfile ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ FROM node:20-alpine AS frontend-builder
14
+
15
+ WORKDIR /frontend
16
+
17
+ COPY --from=source /src/frontend/package.json /src/frontend/package-lock.json ./
18
+
19
+ RUN --mount=type=cache,target=/root/.npm \
20
+ npm ci --no-audit --no-fund
21
+
22
+ COPY --from=source /src/frontend/ .
23
+
24
+ ARG BUILD_VERSION=hf-space
25
+
26
+ RUN VITE_APP_VERSION=${BUILD_VERSION} npm run build
27
+
28
+ FROM golang:1.25-alpine AS go-builder
29
+
30
+ WORKDIR /app
31
+
32
+ COPY --from=source /src/go.mod /src/go.sum ./
33
+
34
+ RUN --mount=type=cache,target=/go/pkg/mod \
35
+ go mod download
36
+
37
+ COPY --from=source /src/ .
38
+ COPY --from=frontend-builder /frontend/dist ./frontend/dist
39
+
40
+ RUN --mount=type=cache,target=/go/pkg/mod \
41
+ --mount=type=cache,target=/root/.cache/go-build \
42
+ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /codex2api .
43
+
44
+ FROM alpine:3.19
45
+
46
+ RUN apk --no-cache add ca-certificates tzdata \
47
+ && adduser -D -u 1000 user \
48
+ && mkdir -p /data \
49
+ && chmod 777 /data
50
+
51
+ ENV HOME=/home/user \
52
+ PATH=/home/user/.local/bin:$PATH \
53
+ CODEX_PORT=8080 \
54
+ DATABASE_DRIVER=sqlite \
55
+ CACHE_DRIVER=memory \
56
+ DATABASE_PATH=/data/codex2api.db \
57
+ TZ=Asia/Shanghai
58
+
59
+ USER user
60
+ WORKDIR $HOME/app
61
+
62
+ COPY --from=go-builder /codex2api /usr/local/bin/codex2api
63
+
64
+ EXPOSE 8080
65
+
66
+ ENTRYPOINT ["/usr/local/bin/codex2api"]