From c8fa58d0e3d575c4ee0f172254cd9933f6bcc42b Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Tue, 21 Jul 2026 17:14:33 +0800 Subject: [PATCH] 1 --- Dockerfile | 34 +++++++--------------------------- web/templates/index.html | 1 + 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index fe55c77..78b5c9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,63 +5,43 @@ FROM golang:1.26-alpine AS builder WORKDIR /app -# 安装构建工具 RUN apk add --no-cache git make -# 配置 Go 代理(国内加速) -ENV GOPROXY=https://goproxy.cn,https://goproxy.io,direct -ENV GOSUMDB=sum.golang.google.cn - -# 复制依赖文件并下载 COPY go.mod go.sum ./ RUN go mod download && go mod verify -# 复制全部源码 COPY . . -# 编译二进制文件 RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ -ldflags="-s -w" \ -o /app/sdk-generator \ . # ============================================================ -# 阶段2: 运行 +# 阶段2: 运行(使用带 Go 的轻量镜像) # ============================================================ -FROM alpine:latest +FROM golang:1.26-alpine AS runner -# 安装运行时依赖 -RUN apk add --no-cache ca-certificates tzdata +RUN apk add --no-cache git -# 创建非 root 用户 -RUN adduser -D -g '' appuser - -# 设置时区 ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -# 设置工作目录 +RUN adduser -D -g '' appuser + WORKDIR /app -# 复制二进制文件 COPY --from=builder /app/sdk-generator /app/sdk-generator - -# 复制静态文件(web 目录) COPY --chown=appuser:appuser ./web /app/web -# 创建数据目录并设置权限 RUN mkdir -p /app/outputs /app/uploads && \ chown -R appuser:appuser /app -# 切换到非 root 用户 USER appuser -# 暴露端口 -EXPOSE 5002 +EXPOSE 8080 -# 健康检查 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost:5002/health || exit 1 + CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1 -# 启动应用 ENTRYPOINT ["/app/sdk-generator"] \ No newline at end of file diff --git a/web/templates/index.html b/web/templates/index.html index 3478a80..b31e7d9 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -4,6 +4,7 @@