fix build bug
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 50m38s

This commit is contained in:
repair-agent 2026-03-03 14:13:02 +08:00
parent 790878ff4d
commit c3a171163a

View File

@ -8,23 +8,25 @@
FROM golang:1.23-alpine AS builder FROM golang:1.23-alpine AS builder
# 安装 CGO 编译所需的 C 工具链和 libopus 开发头文件 # 安装 CGO 编译所需的 C 工具链和 libopus 开发头文件
RUN apk add --no-cache gcc musl-dev opus-dev RUN apk add --no-cache gcc musl-dev opus-dev opusfile-dev
WORKDIR /app WORKDIR /app
# 使用国内镜像加速,避免 proxy.golang.org 超时 # 使用国内镜像加速,避免 proxy.golang.org 超时
ENV GOPROXY=https://goproxy.cn,direct ENV GOPROXY=https://goproxy.cn,direct
# 先拷贝 go.mod/go.sum 利用 Docker 层缓存(依赖未变时跳过 go mod download # 先拷贝 go.mod/go.sum,利用 cache mount 持久化模块缓存
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
COPY . . COPY . .
# 使用 cache mount 持久化模块缓存和编译缓存CI 重复构建大幅加速
# CGO_ENABLED=1 必须开启hraban/opus 是 CGO 库) # CGO_ENABLED=1 必须开启hraban/opus 是 CGO 库)
# -trimpath 去除本地路径信息(安全性) RUN --mount=type=cache,target=/go/pkg/mod \
# -ldflags="-s -w" 去除调试符号(缩减二进制大小) --mount=type=cache,target=/root/.cache/go-build \
RUN CGO_ENABLED=1 GOOS=linux \ CGO_ENABLED=1 GOOS=linux \
go build \ go build \
-trimpath \ -trimpath \
-ldflags="-s -w" \ -ldflags="-s -w" \