dockerfile调整更新
This commit is contained in:
+17
-9
@@ -1,14 +1,19 @@
|
|||||||
# 多阶段构建
|
# 多阶段构建
|
||||||
FROM golang:alpine AS builder
|
FROM golang:alpine AS builder
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# 构建参数:版本信息(由 deploy.sh 传入)
|
||||||
|
# ============================================================
|
||||||
|
ARG VERSION
|
||||||
|
ARG IMAGE_TAG
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 复制依赖文件
|
# 复制依赖文件
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
# 降级 go.mod 并整理依赖
|
# 降级 go.mod 并整理依赖
|
||||||
RUN sed -i 's/go 1.2[6-9].*/go 1.21/' go.mod && \
|
RUN sed -i 's/go 1.2[6-9].*/go 1.21/' go.mod && go mod tidy
|
||||||
go mod tidy
|
|
||||||
|
|
||||||
# 设置代理
|
# 设置代理
|
||||||
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
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
|
RUN go mod download
|
||||||
|
|
||||||
# 复制全部源码(包括 version.ini、static 等)
|
# 复制全部源码
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# 编译
|
# ============================================================
|
||||||
|
# 编译:注入版本信息
|
||||||
|
# ============================================================
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build \
|
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 .
|
-o frpc-console .
|
||||||
|
|
||||||
# 【调试】确认二进制文件已生成
|
# 调试:确认二进制文件存在
|
||||||
RUN ls -l /app/frpc-console
|
RUN ls -lh /app/frpc-console
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
# 运行镜像
|
# 运行镜像
|
||||||
|
# ============================================================
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
# 安装工具
|
# 安装工具
|
||||||
@@ -38,10 +47,9 @@ WORKDIR /app
|
|||||||
# 从构建阶段复制二进制
|
# 从构建阶段复制二进制
|
||||||
COPY --from=builder /app/frpc-console /app/frpc-console
|
COPY --from=builder /app/frpc-console /app/frpc-console
|
||||||
|
|
||||||
# 复制静态文件(从本地直接复制,确保存在)
|
# 复制静态文件
|
||||||
COPY static/ /app/static/
|
COPY static/ /app/static/
|
||||||
|
|
||||||
# 暴露端口
|
|
||||||
EXPOSE 9300
|
EXPOSE 9300
|
||||||
|
|
||||||
ENTRYPOINT ["/app/frpc-console"]
|
ENTRYPOINT ["/app/frpc-console"]
|
||||||
Reference in New Issue
Block a user