From 087fef11e01c4dad0fc7d6d085862ccb72a1a560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=96=8C?= <259278618@qq.com> Date: Mon, 8 Jun 2026 16:43:58 +0800 Subject: [PATCH] =?UTF-8?q?ci/cd=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 47cd6a5..c2ff48b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,42 @@ -# 最小化Docker镜像 -FROM busybox:uclibc +# 阶段1: 构建 +FROM golang:alpine AS builder + +RUN apk add --no-cache git ca-certificates tzdata + +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +ENV GO111MODULE=on +ENV GOPROXY=https://goproxy.cn,direct +ENV CGO_ENABLED=0 +ENV GOTOOLCHAIN=auto +ENV GOPRIVATE=gitea.com/red-future/common + +# 配置git使用私有Gitea仓库 +RUN git config --global url."http://x-token-auth:9b31146aa8c10a7cb4f2e49dcee0934a223be1076289810e1ad98b968066c2bc@116.204.74.41:3000/red-future/common.git".insteadOf "https://gitea.com/red-future/common.git" && \ + git config --global credential.helper store + +WORKDIR /build + +COPY . . + +RUN go mod download && go mod tidy + +RUN go build -ldflags="-s -w" -o main ./main.go + +# 阶段2: 运行 +FROM alpine:3.19 + +RUN apk add --no-cache ca-certificates tzdata + +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone WORKDIR /app -# 复制时区数据 -COPY timezone/localtime /etc/localtime -COPY timezone/timezone /etc/timezone -COPY timezone/Shanghai /usr/share/zoneinfo/Asia/Shanghai - # 复制预构建的二进制文件和配置文件 COPY app ./main COPY manifest/config/config.yaml ./manifest/config/config.yaml -COPY manifest/config/config-dev.yaml ./manifest/config/config-dev.yaml -COPY manifest/config/config-master.yaml ./manifest/config/config-master.yaml COPY resource ./resource # 创建日志目录