From c3a171163ae94b05d505153b69c36b25b9bffa4a Mon Sep 17 00:00:00 2001 From: repair-agent Date: Tue, 3 Mar 2026 14:13:02 +0800 Subject: [PATCH] fix build bug --- hw_service_go/Dockerfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw_service_go/Dockerfile b/hw_service_go/Dockerfile index e82611a..cc3b4c1 100644 --- a/hw_service_go/Dockerfile +++ b/hw_service_go/Dockerfile @@ -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" \