clash-linux commited on
Commit
bdfd271
·
verified ·
1 Parent(s): a4553d2

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +1 -84
Dockerfile CHANGED
@@ -1,84 +1 @@
1
- # Stage 0: Fetcher - Get latest code and replace file
2
- # Use an image with git installed
3
- FROM alpine/git:latest AS fetcher
4
-
5
- # Define a build argument to bust the cache
6
- # ARG CACHE_BUSTER -- Removed as it cannot be passed dynamically on HF
7
-
8
- # Set working directory
9
- WORKDIR /app
10
-
11
- # Clone the main repository
12
- # Add date command output to a file to bust cache *before* cloning
13
- RUN date +%s > /tmp/build_timestamp.txt && \
14
- git clone --depth 1 https://github.com/QuantumNous/new-api.git .
15
-
16
- # Copy the custom EditChannel.js from the local build context
17
- COPY EditChannel.js ./web/src/pages/Channel/EditChannel.js
18
- RUN echo "EditChannel.js copied from local context successfully."
19
-
20
- # Stage 1: Frontend Builder - Build the web UI using bun
21
- FROM oven/bun:latest AS frontend-builder
22
-
23
- WORKDIR /build
24
-
25
- # Copy package.json first to leverage Docker cache for dependencies
26
- COPY --from=fetcher /app/web/package.json .
27
- RUN bun install
28
-
29
- # Copy the rest of the web source code and the VERSION file
30
- COPY --from=fetcher /app/web .
31
- COPY --from=fetcher /app/VERSION .
32
-
33
- # Build the frontend, reading version from the VERSION file
34
- RUN DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(cat VERSION) bun run build
35
-
36
-
37
- # Stage 2: Backend Builder - Build the Go application
38
- FROM golang:alpine AS backend-builder
39
-
40
- ENV GO111MODULE=on \
41
- CGO_ENABLED=0 \
42
- GOOS=linux
43
-
44
- WORKDIR /build
45
-
46
- # Copy Go module files first for dependency caching
47
- COPY --from=fetcher /app/go.mod /app/go.sum ./
48
- RUN go mod download
49
-
50
- # Copy the entire application source code from the fetcher stage
51
- COPY --from=fetcher /app .
52
-
53
- # Copy the built frontend assets from the frontend-builder stage
54
- COPY --from=frontend-builder /build/dist ./web/dist
55
-
56
- # Build the Go application, embedding the version
57
- RUN go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)'" -o one-api
58
-
59
-
60
- # Stage 3: Final Stage - Create the final runtime image
61
- FROM alpine
62
-
63
- # Update, upgrade, install runtime dependencies and clean up
64
- RUN apk update && \
65
- apk upgrade && \
66
- apk add --no-cache ca-certificates tzdata ffmpeg && \
67
- update-ca-certificates && \
68
- rm -rf /var/cache/apk/*
69
-
70
- # Copy the built Go application from the backend-builder stage
71
- COPY --from=backend-builder /build/one-api /one-api
72
-
73
- # Create the logs directory and ensure /data is writable by the application user
74
- RUN mkdir -p /data/logs && \
75
- chmod -R a+w /data
76
-
77
- # Expose the application port
78
- EXPOSE 3000
79
-
80
- # Set the working directory for the running container
81
- WORKDIR /data
82
-
83
- # Define the entry point for the container
84
- ENTRYPOINT ["/one-api"]
 
1
+ FROM ghcr.io/fuwei99/new-api-docker:latest