Debian上加速Golang打包的实用方案
一 构建链与环境优化
二 利用缓存与分布式编译
三 Debian打包流程与工具选择
四 二进制体积与传输优化(可选)
五 一键加速示例脚本
本地与 CI 可复用的示例(按需调整包名与路径): #!/usr/bin/env bash set -Eeuo pipefail
export GOMAXPROCS=$(nproc) export GOGC=20 go env -w GOPROXY=https://goproxy.cn,direct
go mod tidy go list -m all > /dev/null
CGO_ENABLED=0 go build
-trimpath
-ldflags “-s -w”
-o myapp .
debuild -us -uc
如需在 CI 中进一步提速,请为 GOPATH/pkg/mod 与 sccache 配置持久化缓存卷。