From dd2ba2e816b7b1fcd917ca268e3cb0eb50683537 Mon Sep 17 00:00:00 2001 From: Kevin Minehart <5140827+kminehart@users.noreply.github.com> Date: Thu, 26 Jun 2025 09:16:58 -0500 Subject: [PATCH] CI: Add GOCACHEPROG to the backend builder if GOCACHEPROG is set on the host (#107256) --- pkg/build/daggerbuild/artifacts/backend.go | 8 ++++++++ pkg/build/daggerbuild/backend/builder.go | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/pkg/build/daggerbuild/artifacts/backend.go b/pkg/build/daggerbuild/artifacts/backend.go index 64d820bc86c..b4bb62085de 100644 --- a/pkg/build/daggerbuild/artifacts/backend.go +++ b/pkg/build/daggerbuild/artifacts/backend.go @@ -3,6 +3,7 @@ package artifacts import ( "context" "log/slog" + "os" "path/filepath" "dagger.io/dagger" @@ -191,10 +192,17 @@ func NewBackendFromString(ctx context.Context, log *slog.Logger, artifact string return nil, err } + goCacheProg := "" + // If the caller has GOCACHEPROG set, then reuse it + if val, ok := os.LookupEnv("GOCACHEPROG"); ok { + goCacheProg = val + } + bopts := &backend.BuildOpts{ Version: p.Version, Enterprise: p.Enterprise, ExperimentalFlags: experiments, + GoCacheProg: goCacheProg, Static: static, WireTag: wireTag, Tags: tags, diff --git a/pkg/build/daggerbuild/backend/builder.go b/pkg/build/daggerbuild/backend/builder.go index 3846b6a887d..9a27c60a8c0 100644 --- a/pkg/build/daggerbuild/backend/builder.go +++ b/pkg/build/daggerbuild/backend/builder.go @@ -16,6 +16,7 @@ type BuildOpts struct { ExperimentalFlags []string Tags []string WireTag string + GoCacheProg string Static bool Enterprise bool } @@ -154,6 +155,10 @@ func Builder( WithMountedCache("/root/.cache/go", goBuildCache). WithEnvVariable("GOCACHE", "/root/.cache/go") + if prog := opts.GoCacheProg; prog != "" { + builder = builder.WithEnvVariable("GOCACHEPROG", prog) + } + commitInfo := GetVCSInfo(src, version, opts.Enterprise) builder = withCue(builder, src).