From 8ed2fdf710bb054c6dd0f5e60814ee55fdf3ecb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=96=B9=E6=88=90?= Date: Fri, 17 Oct 2025 01:16:16 +0800 Subject: [PATCH] =?UTF-8?q?build(Dockerfile):=20=E4=BC=98=E5=8C=96Go?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E4=B8=8B=E8=BD=BD=E5=B9=B6=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加Go环境变量配置和代理设置,并实现依赖下载的重试机制以提高构建可靠性 --- Dockerfile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b8a7b87..2593009 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,22 @@ RUN apk add --no-cache git ca-certificates tzdata # Copy go mod files COPY go.mod go.sum ./ -# Download dependencies -RUN go mod download +# Set Go environment variables and proxy +ENV GO111MODULE=on \ + CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 \ + GOPROXY=https://goproxy.cn,https://goproxy.io,direct \ + GOSUMDB=sum.golang.google.cn + +# Download dependencies with retry mechanism +RUN go mod download || \ + (echo "Retrying with different proxy..." && \ + go env -w GOPROXY=https://goproxy.io,https://mirrors.aliyun.com/goproxy/,direct && \ + go mod download) || \ + (echo "Final retry with direct mode..." && \ + go env -w GOPROXY=direct && \ + go mod download) # Copy source code COPY . .