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
# 安装 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
# 使用国内镜像加速,避免 proxy.golang.org 超时
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 ./
RUN go mod download
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
COPY . .
# 使用 cache mount 持久化模块缓存和编译缓存CI 重复构建大幅加速
# CGO_ENABLED=1 必须开启hraban/opus 是 CGO 库)
# -trimpath 去除本地路径信息(安全性)
# -ldflags="-s -w" 去除调试符号(缩减二进制大小)
RUN CGO_ENABLED=1 GOOS=linux \
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=1 GOOS=linux \
go build \
-trimpath \
-ldflags="-s -w" \