Files
jiang13-bbs/deploy/Dockerfile.api

36 lines
1.4 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 构建上下文:仓库根。不含源码与工具链。
# syntax=docker/dockerfile:1
FROM golang:1.27-bookworm AS build
WORKDIR /src
ENV GOTOOLCHAIN=local
COPY backend/go.mod backend/go.sum ./
RUN go mod download
COPY backend/ ./
ARG VERSION=dev
ARG COMMIT=unknown
# -tags nodynamic:gen2brain/webp 默认经 purego dlopen libwebp.so,会把二进制动态链接到
# glibc(INTERP /lib64/ld-linux),Alpine 无法 exec(0.2.1 首版事故)。该标签强制走
# wasm2go 转译的纯 Go 实现,保持 CGO_ENABLED=0 全静态。
RUN CGO_ENABLED=0 GOOS=linux go build -tags nodynamic \
-trimpath \
-ldflags="-s -w -X github.com/freefire/jiang13-bbs/version.Version=${VERSION} -X github.com/freefire/jiang13-bbs/version.Commit=${COMMIT}" \
-o /out/jiang13 ./cmd/jiang13
FROM alpine:3.21
RUN apk add --no-cache ca-certificates tzdata wget su-exec \
&& adduser -D -H -u 1000 jiang13 \
&& mkdir -p /var/lib/jiang13/data
COPY --from=build /out/jiang13 /usr/local/bin/jiang13
COPY deploy/api-entrypoint.sh /usr/local/bin/api-entrypoint.sh
RUN sed -i 's/\r$//' /usr/local/bin/api-entrypoint.sh && chmod +x /usr/local/bin/api-entrypoint.sh
ENV JIANG13_WORK_PATH=/var/lib/jiang13 \
HTTP_PORT=3001 \
DEV_MODE=false \
TZ=UTC
WORKDIR /var/lib/jiang13
EXPOSE 3001
HEALTHCHECK --interval=10s --timeout=3s --start-period=20s --retries=5 \
CMD wget -qO- http://127.0.0.1:3001/health || exit 1
ENTRYPOINT ["/usr/local/bin/api-entrypoint.sh"]