dockerfile调整更新
This commit is contained in:
+17
-9
@@ -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"]
|
||||
Reference in New Issue
Block a user