From 5e59a1c334f3be9bb4f57353c6ef2feffce6674b Mon Sep 17 00:00:00 2001 From: Denozordec Date: Tue, 19 May 2026 14:12:10 +0700 Subject: [PATCH] docker: refactor cache handling in Docker bake configuration - Renamed cache functions for Go and web targets to clarify their purpose and prevent race conditions during parallel builds. - Updated targets to use the new cache export functions, ensuring proper cache management. - Revised README to reflect changes in cache usage and provide guidance on resolving potential CI issues related to cache schema changes. --- deploy/docker/README.md | 8 ++++++-- deploy/docker/docker-bake.hcl | 19 +++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/deploy/docker/README.md b/deploy/docker/README.md index 6558269..25a9819 100644 --- a/deploy/docker/README.md +++ b/deploy/docker/README.md @@ -13,11 +13,15 @@ Кэш registry (переменные bake): -- `git.shts.su//evobgp-buildcache:go-buildcache` -- `git.shts.su//evobgp-buildcache:web-buildcache` +- `git.shts.su//evobgp-buildcache:go-buildcache` — **запись** только из target `go-build-all` +- `git.shts.su//evobgp-buildcache:web-buildcache` — **запись** только из target `web-build` + +Остальные bake-target’ы только `cache-from` (чтение). Параллельный `cache-to` в один ref ломает manifest в registry (`content descriptor … not found`). Локально BuildKit также кэширует `/go/pkg/mod` и `~/.cache/go-build` через `RUN --mount=type=cache`. +Если CI падает на «not found» после смены схемы кэша — один раз удалите теги `evobgp-buildcache:go-buildcache` и `:web-buildcache` в registry и пересоберите. + ## Локальная сборка Из корня репозитория: diff --git a/deploy/docker/docker-bake.hcl b/deploy/docker/docker-bake.hcl index 77eccdd..514b66f 100644 --- a/deploy/docker/docker-bake.hcl +++ b/deploy/docker/docker-bake.hcl @@ -32,7 +32,10 @@ function "go-cache-from" { result = notequal("", CACHE_REF_GO) ? ["type=registry,ref=${CACHE_REF_GO}"] : [] } -function "go-cache-to" { +# Экспорт кэша — только go-build-all / web-build (один writer на ref). +# Несколько target с cache-to в один ref и mode=max дают гонку в registry +# (content descriptor not found при параллельном bake). +function "go-cache-to-export" { params = [] result = notequal("", CACHE_REF_GO) ? ["type=registry,ref=${CACHE_REF_GO},mode=max"] : [] } @@ -42,7 +45,7 @@ function "web-cache-from" { result = notequal("", CACHE_REF_WEB) ? ["type=registry,ref=${CACHE_REF_WEB}"] : [] } -function "web-cache-to" { +function "web-cache-to-export" { params = [] result = notequal("", CACHE_REF_WEB) ? ["type=registry,ref=${CACHE_REF_WEB},mode=max"] : [] } @@ -76,7 +79,6 @@ target "go-deps" { target = "deps" platforms = ["linux/amd64"] cache-from = go-cache-from() - cache-to = go-cache-to() } target "go-build-all" { @@ -88,7 +90,7 @@ target "go-build-all" { deps = "target:go-deps" } cache-from = go-cache-from() - cache-to = go-cache-to() + cache-to = go-cache-to-export() } target "go-birdc" { @@ -97,7 +99,6 @@ target "go-birdc" { target = "birdc" platforms = ["linux/amd64"] cache-from = go-cache-from() - cache-to = go-cache-to() } target "_go-runtime" { @@ -109,7 +110,6 @@ target "_go-runtime" { build-all = "target:go-build-all" } cache-from = go-cache-from() - cache-to = go-cache-to() } target "_go-runtime-birdc" { @@ -122,7 +122,6 @@ target "_go-runtime-birdc" { birdc = "target:go-birdc" } cache-from = go-cache-from() - cache-to = go-cache-to() } function "image-tags" { @@ -187,7 +186,6 @@ target "evobgp-agent" { build-all = "target:go-build-all" } cache-from = go-cache-from() - cache-to = go-cache-to() tags = image-tags("evobgp-agent") } @@ -199,7 +197,6 @@ target "web-deps" { target = "deps" platforms = ["linux/amd64"] cache-from = web-cache-from() - cache-to = web-cache-to() } target "web-build" { @@ -211,7 +208,7 @@ target "web-build" { deps = "target:web-deps" } cache-from = web-cache-from() - cache-to = web-cache-to() + cache-to = web-cache-to-export() } target "evobgp-web" { @@ -224,7 +221,6 @@ target "evobgp-web" { } args = { EVOBGP_UPSTREAM = "evobgp-api" } cache-from = web-cache-from() - cache-to = web-cache-to() tags = image-tags("evobgp-web") } @@ -238,7 +234,6 @@ target "evobgp-web-all" { } args = { EVOBGP_UPSTREAM = "evobgp-all" } cache-from = web-cache-from() - cache-to = web-cache-to() tags = image-tags("evobgp-web-all") }