2025-12-04 20:21:57 +08:00
|
|
|
|
# ------------------------------
|
|
|
|
|
|
# Stage 1 — Build
|
|
|
|
|
|
# ------------------------------
|
2026-01-23 23:34:46 +08:00
|
|
|
|
FROM golang:1.25.1 AS builder
|
2025-12-04 20:21:57 +08:00
|
|
|
|
|
2026-01-21 16:49:49 +08:00
|
|
|
|
ARG GOPROXY
|
|
|
|
|
|
ENV GOPROXY=${GOPROXY}
|
|
|
|
|
|
|
2025-12-05 00:38:33 +08:00
|
|
|
|
WORKDIR /src
|
2025-12-04 23:37:22 +08:00
|
|
|
|
|
2025-12-05 00:38:33 +08:00
|
|
|
|
# 先复制 go.mod / go.sum,使 Docker 构建缓存层可复用
|
|
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
|
|
RUN go mod download
|
2025-12-04 23:37:22 +08:00
|
|
|
|
|
2025-12-05 00:38:33 +08:00
|
|
|
|
# 再复制源码
|
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
# 编译
|
2026-01-21 16:49:49 +08:00
|
|
|
|
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o account ./cmd/accountsvc/main.go
|
2025-12-02 15:31:02 +08:00
|
|
|
|
|
2025-12-04 20:21:57 +08:00
|
|
|
|
# ------------------------------
|
|
|
|
|
|
# Stage 2 — Runtime
|
|
|
|
|
|
# ------------------------------
|
2025-12-05 00:38:33 +08:00
|
|
|
|
FROM ubuntu:24.04
|
|
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
2025-12-04 15:07:23 +08:00
|
|
|
|
|
2025-12-02 15:31:02 +08:00
|
|
|
|
RUN apt-get update \
|
2026-01-21 16:49:49 +08:00
|
|
|
|
&& apt-get install -y --no-install-recommends ca-certificates stunnel4 gettext-base netcat-openbsd curl \
|
2026-01-20 21:05:30 +08:00
|
|
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
|
|
|
|
&& mkdir -p /var/run/stunnel \
|
|
|
|
|
|
&& chown -R nobody:nogroup /var/run/stunnel
|
2025-12-02 15:31:02 +08:00
|
|
|
|
|
2025-12-05 00:38:33 +08:00
|
|
|
|
COPY --from=builder /src/account /usr/local/bin/account
|
2025-12-04 21:47:00 +08:00
|
|
|
|
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
2026-01-20 21:05:30 +08:00
|
|
|
|
COPY config /app/config
|
2025-12-04 20:21:57 +08:00
|
|
|
|
|
2025-12-05 00:38:33 +08:00
|
|
|
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
2025-12-02 15:31:02 +08:00
|
|
|
|
|
|
|
|
|
|
EXPOSE 8080
|
2025-12-05 00:38:33 +08:00
|
|
|
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|