From 229030ded869dabffd78460c9540257eef0a8521 Mon Sep 17 00:00:00 2001 From: XOF Date: Mon, 15 Dec 2025 01:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5952cf2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# Dockerfile +FROM golang:1.25-alpine AS builder + +WORKDIR /app + +# 复制 go.mod 和源代码 +COPY go.mod ./ +COPY . . + +# 编译 +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o siteproxy . + +# 运行阶段 +FROM alpine:latest + +RUN apk --no-cache add ca-certificates + +WORKDIR /root/ + +# 从构建阶段复制二进制文件 +COPY --from=builder /app/siteproxy . + +# 暴露端口 +EXPOSE 8080 + +# 健康检查 +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1 + +# 运行 +CMD ["./siteproxy"]