From 8a5a541bc605e9382e3034a06c2f63888e8dc7a6 Mon Sep 17 00:00:00 2001 From: lxh2875931338 Date: Wed, 29 Jul 2026 23:45:51 +0800 Subject: [PATCH] =?UTF-8?q?dockerfile=E8=B0=83=E6=95=B4=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index a0ca689..af992ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,19 @@ # 多阶段构建 FROM golang:alpine AS builder +# ============================================================ +# 构建参数:版本信息(由 deploy.sh 传入) +# ============================================================ +ARG VERSION +ARG IMAGE_TAG + WORKDIR /app # 复制依赖文件 COPY go.mod go.sum ./ # 降级 go.mod 并整理依赖 -RUN sed -i 's/go 1.2[6-9].*/go 1.21/' go.mod && \ - go mod tidy +RUN sed -i 's/go 1.2[6-9].*/go 1.21/' go.mod && go mod tidy # 设置代理 RUN go env -w GOPROXY=https://goproxy.cn,direct @@ -16,18 +21,22 @@ RUN go env -w GOPROXY=https://goproxy.cn,direct # 下载依赖 RUN go mod download -# 复制全部源码(包括 version.ini、static 等) +# 复制全部源码 COPY . . -# 编译 +# ============================================================ +# 编译:注入版本信息 +# ============================================================ RUN CGO_ENABLED=0 GOOS=linux go build \ - -ldflags="-s -w" \ + -ldflags="-s -w -X main.buildVersion=${VERSION} -X main.buildImageTag=${IMAGE_TAG}" \ -o frpc-console . -# 【调试】确认二进制文件已生成 -RUN ls -l /app/frpc-console +# 调试:确认二进制文件存在 +RUN ls -lh /app/frpc-console +# ============================================================ # 运行镜像 +# ============================================================ FROM alpine:latest # 安装工具 @@ -38,10 +47,9 @@ WORKDIR /app # 从构建阶段复制二进制 COPY --from=builder /app/frpc-console /app/frpc-console -# 复制静态文件(从本地直接复制,确保存在) +# 复制静态文件 COPY static/ /app/static/ -# 暴露端口 EXPOSE 9300 ENTRYPOINT ["/app/frpc-console"] \ No newline at end of file