40 lines
1.4 KiB
Docker
40 lines
1.4 KiB
Docker
# Build context: the repository backend/ directory.
|
|
# docker build -f backend/Dockerfile -t REGISTRY/PROJECT/zhinian-go-api:TAG backend/
|
|
#
|
|
# GOLANG_IMAGE and RUNTIME_IMAGE are overridable for build environments whose
|
|
# registry mirror cannot serve the default docker.io images:
|
|
# docker build -f backend/Dockerfile \
|
|
# --build-arg GOLANG_IMAGE=<working-mirror>/golang:1.21-alpine \
|
|
# --build-arg RUNTIME_IMAGE=<working-mirror>/alpine:3.20 \
|
|
# --build-arg GOPROXY=https://<internal-go-proxy>,direct \
|
|
# -t REGISTRY/PROJECT/zhinian-go-api:TAG backend/
|
|
#
|
|
# If no mirror can serve the golang image at all, use backend/Dockerfile.runtime
|
|
# with a prebuilt static binary instead (see backend/README.md).
|
|
ARG GOLANG_IMAGE=golang:1.21-alpine
|
|
ARG RUNTIME_IMAGE=alpine:3.20
|
|
|
|
FROM ${GOLANG_IMAGE} AS build
|
|
WORKDIR /src
|
|
ARG GOPROXY=https://goproxy.cn,direct
|
|
ARG GOSUMDB=sum.golang.google.cn
|
|
ENV CGO_ENABLED=0 \
|
|
GOOS=linux \
|
|
GOPROXY=${GOPROXY} \
|
|
GOSUMDB=${GOSUMDB}
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
COPY . .
|
|
RUN go build -trimpath -ldflags="-s -w" -o /out/zhinian-api ./cmd/zhinian-api
|
|
|
|
FROM ${RUNTIME_IMAGE}
|
|
RUN apk add --no-cache ca-certificates tzdata \
|
|
&& addgroup -S -g 10001 zhinian \
|
|
&& adduser -S -D -H -u 10001 -G zhinian zhinian \
|
|
&& mkdir -p /var/lib/zhinian \
|
|
&& chown -R zhinian:zhinian /var/lib/zhinian
|
|
COPY --from=build /out/zhinian-api /usr/local/bin/zhinian-api
|
|
USER 10001:10001
|
|
EXPOSE 8080
|
|
ENTRYPOINT ["zhinian-api"]
|