全新优化的部署流程

This commit is contained in:
2026-07-30 00:08:44 +08:00
parent 1748cee251
commit 826ce399e7
4 changed files with 235 additions and 332 deletions
+2 -27
View File
@@ -1,53 +1,28 @@
# 多阶段构建
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 go env -w GOPROXY=https://goproxy.cn,direct
# 下载依赖
RUN go mod download
# 复制全部源码
COPY . .
# ============================================================
# 编译:注入版本信息
# ============================================================
# 编译时不注入任何版本信息(纯净二进制)
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-s -w -X main.buildVersion=${VERSION} -X main.buildImageTag=${IMAGE_TAG}" \
-ldflags="-s -w" \
-o frpc-console .
# 调试:确认二进制文件存在
RUN ls -lh /app/frpc-console
# ============================================================
# 运行镜像
# ============================================================
FROM alpine:latest
# 安装工具
RUN apk --no-cache add ca-certificates tzdata sqlite
WORKDIR /app
# 从构建阶段复制二进制
COPY --from=builder /app/frpc-console /app/frpc-console
# 复制静态文件
COPY static/ /app/static/
EXPOSE 9300