Files
SiteProxy/Dockerfile
2025-12-15 01:57:05 +08:00

40 lines
766 B
Docker

# Dockerfile
FROM golang:1.25-alpine AS builder
WORKDIR /app
# 安装依赖
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 -ldflags="-s -w" -o siteproxy .
# 运行阶段
FROM alpine:latest
RUN apk --no-cache add ca-certificates tzdata
WORKDIR /app
# 从构建阶段复制二进制文件和模板
COPY --from=builder /app/siteproxy .
COPY --from=builder /app/templates ./templates
# 暴露端口
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"]