feat: better dockerfile

This commit is contained in:
ckt1031 2023-07-11 17:03:22 +08:00
parent 270e366cd9
commit 839dcc3ab2

View File

@ -1,11 +1,11 @@
# Initial stage # Initial stage
FROM python:3.11 as translator FROM python:3.12 as translator
WORKDIR /app WORKDIR /app
COPY . . COPY . .
RUN python ./i18n/translate.py --repository_path . --json_file_path ./i18n/en.json RUN python ./i18n/translate.py --repository_path . --json_file_path ./i18n/en.json
# Node build stage # Node build stage
FROM node:18 as builder FROM node:18-alpine as nodeBuilder
WORKDIR /build WORKDIR /build
COPY ./web/package*.json ./ COPY ./web/package*.json ./
RUN npm ci RUN npm ci
@ -13,7 +13,7 @@ COPY --from=translator /app .
RUN cd web && REACT_APP_VERSION=$(cat VERSION) npm run build RUN cd web && REACT_APP_VERSION=$(cat VERSION) npm run build
# Go build stage # Go build stage
FROM golang AS builder2 FROM golang:1.20.5 AS goBuilder
ENV GO111MODULE=on \ ENV GO111MODULE=on \
CGO_ENABLED=1 \ CGO_ENABLED=1 \
GOOS=linux GOOS=linux
@ -22,13 +22,13 @@ COPY go.mod .
COPY go.sum . COPY go.sum .
RUN go mod download RUN go mod download
COPY --from=translator /app . COPY --from=translator /app .
COPY --from=builder /build/web/build ./web/build COPY --from=nodeBuilder /build/web/build ./web/build
RUN go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o one-api RUN go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o one-api
# Final stage # Final stage
FROM alpine FROM alpine:latest
RUN apk update && apk upgrade && apk add --no-cache ca-certificates tzdata && update-ca-certificates 2>/dev/null || true RUN apk update && apk upgrade && apk add --no-cache ca-certificates tzdata && update-ca-certificates 2>/dev/null || true
WORKDIR /data WORKDIR /data
COPY --from=builder2 /build/one-api / COPY --from=goBuilder /build/one-api /
EXPOSE 3000 EXPOSE 3000
ENTRYPOINT ["/one-api"] ENTRYPOINT ["/one-api"]