From 5a13603eef44ed484a05be8cce5e9e23d0a3316c Mon Sep 17 00:00:00 2001 From: jonjohnsonjr Date: Tue, 14 Dec 2021 15:30:01 -0800 Subject: [PATCH] Fix tarball publisher ctx handling (#545) Previously, we'd use the ctx from the Build invocation, but because remote stashes the remote.WithContext option, when we later go to fetch the actual base image to write it out to a tarball, it will fail because the Build ctx was cancelled. For whatever reason, NewGo takes a ctx, so this change propagates the badness from remote so we can use the NewGo ctx when we fetch base images. --- pkg/build/gobuild.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go index 883cdb78b6..cfce11b2d9 100644 --- a/pkg/build/gobuild.go +++ b/pkg/build/gobuild.go @@ -70,6 +70,7 @@ type platformMatcher struct { } type gobuild struct { + ctx context.Context getBase GetBase creationTime v1.Time kodataCreationTime v1.Time @@ -90,6 +91,7 @@ type gobuild struct { type Option func(*gobuildOpener) error type gobuildOpener struct { + ctx context.Context getBase GetBase creationTime v1.Time kodataCreationTime v1.Time @@ -116,6 +118,7 @@ func (gbo *gobuildOpener) Open() (Interface, error) { gbo.jobs = runtime.GOMAXPROCS(0) } return &gobuild{ + ctx: gbo.ctx, getBase: gbo.getBase, creationTime: gbo.creationTime, kodataCreationTime: gbo.kodataCreationTime, @@ -143,6 +146,7 @@ func (gbo *gobuildOpener) Open() (Interface, error) { // If `dir` is empty, the function uses the current process working directory. func NewGo(ctx context.Context, dir string, options ...Option) (Interface, error) { gbo := &gobuildOpener{ + ctx: ctx, build: build, dir: dir, sbom: spdx("(none)"), @@ -826,7 +830,9 @@ func updatePath(cf *v1.ConfigFile, appPath string) { // Build implements build.Interface func (g *gobuild) Build(ctx context.Context, s string) (Result, error) { // Determine the appropriate base image for this import path. - baseRef, base, err := g.getBase(ctx, s) + // We use the overall gobuild.ctx because the Build ctx gets cancelled + // early, and we lazily use the ctx within ggcr's remote package. + baseRef, base, err := g.getBase(g.ctx, s) if err != nil { return nil, err }