perf: BuildKit cache mount 加速 Docker 构建

优化:
- Dockerfile 加 # syntax=docker/dockerfile:1 启用 BuildKit frontend
- go mod download / go build 加 --mount=type=cache (GOMODCACHE + GOCACHE)
- apk add 加 --mount=type=cache=/var/cache/apk
- alpine:latest → alpine:3.20 固定版本(避免 :latest 变动导致全量 cache miss)
- run.sh 加 DOCKER_BUILDKIT=1 + COMPOSE_DOCKER_CLI_BUILD=1

效果:
- 首次构建不变(需填充缓存)
- 第二次起: go build 增量编译(仅重编译改动包),apk 从缓存恢复
- 预估: 13分钟 → 2分钟
This commit is contained in:
attacker committed 2026-06-21 21:55:03 +08:00
1 parent b3d2011243
commit 8c272a6fa6
2 files changed
+33 -10

No files matched your search

+5
View File
@@ -325,6 +325,11 @@ cmd_docker() {
info "使用: $DOCKER_COMPOSE"
info "版本: $VERSION (构建时间: $BUILD_TIME)"
# 启用 BuildKit 加速构建(cache mount 跨构建复用 go mod/apk 缓存)// Logan.Li
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
info "BuildKit: 已启用 (增量编译 + 缓存复用)"
case "$action" in
up)
banner "========== Docker Compose 启动 =========="