This commit is contained in:
renzhiyuan 2026-07-21 17:27:44 +08:00
parent c8fa58d0e3
commit 18771c745f
1 changed files with 14 additions and 4 deletions

View File

@ -5,10 +5,17 @@ FROM golang:1.26-alpine AS builder
WORKDIR /app
# ✅ 设置 Go 代理(解决网络问题)
ENV GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct
ENV GOSUMDB=off
ENV GO111MODULE=on
RUN apk add --no-cache git make
COPY go.mod go.sum ./
RUN go mod download && go mod verify
# ✅ 先尝试下载依赖,如果失败则重试
RUN go mod download || go mod download
COPY . .
@ -18,13 +25,16 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
.
# ============================================================
# 阶段2: 运行(使用带 Go 的轻量镜像)
# 阶段2: 运行
# ============================================================
FROM golang:1.26-alpine AS runner
FROM alpine:latest
RUN apk add --no-cache git
RUN apk add --no-cache ca-certificates tzdata git go
ENV TZ=Asia/Shanghai
ENV GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct
ENV GOSUMDB=off
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN adduser -D -g '' appuser