Optimizing Docker image builds (#1)

Co-authored-by: pader.zhang <pader.zhang@starlight-sms.com>
This commit is contained in:
paderlol 2024-03-15 14:10:05 +08:00 committed by GitHub
parent 4ce2381182
commit 9adefa80b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
FROM node:16 as builder FROM node:16-slim as builder
WORKDIR /build WORKDIR /build
COPY web/package.json . COPY web/package.json .
@ -7,18 +7,19 @@ COPY ./web .
COPY ./VERSION . COPY ./VERSION .
RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build
FROM golang AS builder2 FROM golang:1.19-alpine AS builder2
RUN apk add build-base
ENV GO111MODULE=on \ ENV GO111MODULE=on \
CGO_ENABLED=1 \ CGO_ENABLED=1 \
GOOS=linux GOOS=linux
WORKDIR /build WORKDIR /build
ADD go.mod go.sum ./ #ADD go.mod go.sum ./
RUN go mod download
COPY . . COPY . .
COPY --from=builder /build/build ./web/build COPY --from=builder /build/build ./web/build
RUN go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o one-api
RUN go mod tidy \
&& go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o one-api
FROM alpine FROM alpine