30 lines
776 B
Docker
30 lines
776 B
Docker
FROM golang:1.23-alpine AS build
|
|
|
|
WORKDIR /src
|
|
RUN apk add --no-cache git ca-certificates tzdata
|
|
|
|
# 解决部分网络环境无法访问 proxy.golang.org 的问题(可在构建时覆盖)
|
|
ARG GOPROXY=https://goproxy.cn,direct
|
|
ARG GOSUMDB=sum.golang.google.cn
|
|
ENV GOPROXY=$GOPROXY
|
|
ENV GOSUMDB=$GOSUMDB
|
|
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
COPY . .
|
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/server
|
|
|
|
FROM alpine:3.20
|
|
WORKDIR /app
|
|
RUN apk add --no-cache ca-certificates tzdata su-exec && adduser -D -H appuser
|
|
|
|
COPY --from=build /out/server /app/server
|
|
COPY --from=build /src/static /app/static
|
|
COPY --from=build /src/scripts /app/scripts
|
|
|
|
ENV APP_PORT=8080
|
|
EXPOSE 8080
|
|
|
|
ENTRYPOINT ["/app/scripts/entrypoint.sh"]
|