Skip to content

Commit

Permalink
Fix tarball publisher ctx handling (ko-build#545)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonjohnsonjr authored Dec 14, 2021
1 parent 22c9a52 commit 5a13603
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type platformMatcher struct {
}

type gobuild struct {
ctx context.Context
getBase GetBase
creationTime v1.Time
kodataCreationTime v1.Time
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)"),
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5a13603

Please sign in to comment.