From b6e5ada0b18238bf81c4e6ed751449badf057439 Mon Sep 17 00:00:00 2001 From: XOF Date: Mon, 15 Dec 2025 01:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5952cf2..a43b0de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,22 +3,29 @@ FROM golang:1.25-alpine AS builder WORKDIR /app -# 复制 go.mod 和源代码 -COPY go.mod ./ +# 安装依赖 +RUN apk add --no-cache git + +# 复制 go.mod 和 go.sum +COPY go.mod go.sum* ./ +RUN go mod download + +# 复制源代码 COPY . . # 编译 -RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o siteproxy . +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o siteproxy . # 运行阶段 FROM alpine:latest -RUN apk --no-cache add ca-certificates +RUN apk --no-cache add ca-certificates tzdata -WORKDIR /root/ +WORKDIR /app -# 从构建阶段复制二进制文件 +# 从构建阶段复制二进制文件和模板 COPY --from=builder /app/siteproxy . +COPY --from=builder /app/templates ./templates # 暴露端口 EXPOSE 8080 @@ -29,3 +36,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ # 运行 CMD ["./siteproxy"] +