Files
sale/backend/Dockerfile
T
admin dbd2a2b29e
Build and Push Docker Image / build-and-push (push) Successful in 1m35s
Build and Push Docker Image / deploy (push) Failing after 2s
fix(ci): Dockerfile 的 Go 版本与 go.mod 不匹配,导致 CI 全部失败
现象:admin/sale 的 GitHub Actions(Gitea Actions)从 run 783 到 790
连续失败,线上一直是 2026-11-03 的旧镜像。

根因:
    backend/go.mod  →  go 1.25.0
    backend/Dockerfile →  FROM golang:1.24-alpine

构建时报:
    go: go.mod requires go >= 1.25.0 (running go 1.24.13; GOTOOLCHAIN=local)

本地能编译是因为本机 Go 会按 go.mod 自动下载 1.25 toolchain;
容器里 GOTOOLCHAIN=local 禁止了这个行为,于是直接报错退出。

修复:
  1. 基础镜像改为 golang:1.25-alpine
  2. 显式设置 GOTOOLCHAIN=auto,避免以后再被镜像版本卡住
  3. 去掉构建阶段的 go mod tidy —— 它会在 CI 里改写 go.mod/go.sum,
     锁文件应该由提交决定,构建时只做 go mod download
2026-11-19 13:16:15 +08:00

41 lines
1011 B
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
FROM golang:1.25-alpine AS builder
WORKDIR /app
RUN apk add --no-cache git nodejs npm
ENV GOPROXY=https://goproxy.cn,direct
ENV GOFLAGS=-buildvcs=false
# go.mod 声明 go 1.25.0,基础镜像若低于此版本会直接失败
# (GOTOOLCHAIN=local 时不会自动下载 toolchain)。
# 这里显式允许 toolchain 自动切换,避免以后再被镜像版本卡住。
ENV GOTOOLCHAIN=auto
COPY backend/go.mod backend/go.sum ./
# 不跑 go mod tidy:它会在构建过程中改写 go.mod/go.sum,
# 锁文件应该是提交进仓库的,构建时只做下载。
RUN go mod download
COPY backend ./backend
COPY frontend ./frontend
RUN npm ci --prefix frontend
RUN npm run build --prefix frontend
RUN cd backend && CGO_ENABLED=0 GOOS=linux go build -o /app/server ./cmd/server
FROM alpine:latest
WORKDIR /app
RUN apk add --no-cache ca-certificates tzdata
RUN mkdir -p uploads data
COPY --from=builder /app/server .
COPY --from=builder /app/frontend/dist ./static
EXPOSE 8080
CMD ["./server"]