Skip to content

Commit

Permalink
Pull the new run image by name before restore, and by identifier afte…
Browse files Browse the repository at this point in the history
…r restore

When building to a daemon we need to pull the run image before restore in order to get target data

Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano committed May 14, 2024
1 parent b30f3e5 commit 75b16b6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
6 changes: 2 additions & 4 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,17 +866,15 @@ func testAcceptance(
h.SkipIf(t, !lifecycle.SupportsFeature(config.RunImageExtensions), "")
})

// FIXME: now that we pull the run image AFTER the restore phases, the restorer fails to access the non-existent run image when it does restore checks
it.Pend("uses the 5 phases, and tries to pull the new run image before restore", func() {
it("uses the 5 phases, and tries to pull the new run image by name before restore, and by identifier after restore", func() {
output, _ := pack.Run(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--network", "host",
"-B", builderName,
"--env", "EXT_RUN_SWITCH=1",
)
h.AssertContains(t, output, "ERROR: failed to build: executing lifecycle: resolve auth for ref some-not-exist-run-image!")
h.AssertNotContains(t, output, "RESTORING")
h.AssertContains(t, output, "Pulling image 'busybox:latest'")
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ if [[ -z "$EXT_RUN_SWITCH" ]]; then
else
echo "Generating run.Dockerfile for run image switch..."
cat >>"${output_dir}/run.Dockerfile" <<EOL
FROM some-not-exist-run-image!
FROM busybox:latest
EOL
fi
23 changes: 15 additions & 8 deletions internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,31 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF
}
}

var (
ephemeralRunImage string
err error
)
if l.runImageChanged() || l.hasExtensionsForRun() {
// Pull the run image by name in case we fail to pull it by identifier later.
if ephemeralRunImage, err = l.opts.FetchRunImageWithLifecycleLayer(l.runImageNameAfterExtensions()); err != nil {
return err
}
}

l.logger.Info(style.Step("RESTORING"))
if l.opts.ClearCache && l.PlatformAPI().LessThan("0.10") {
l.logger.Info("Skipping 'restore' due to clearing cache")
} else if err := l.Restore(ctx, buildCache, kanikoCache, phaseFactory); err != nil {
return err
}

var (
ephemeralRunImage string
err error
)
if l.runImageChanged() || l.hasExtensionsForRun() {
if ephemeralRunImage, err = l.opts.FetchRunImageWithLifecycleLayer(l.runImageIdentifierAfterExtensions()); err != nil {
if newEphemeralRunImage, err := l.opts.FetchRunImageWithLifecycleLayer(l.runImageIdentifierAfterExtensions()); err == nil {
// If the run image was switched by extensions, the run image reference as written by the __restorer__ will be a digest reference
// that is pullable from a registry.
// However, if the run image is only extended (not switched), the run image reference as written by the __analyzer__ may be an image identifier
// (in the daemon case), and will not be pullable.
if ephemeralRunImage, err = l.opts.FetchRunImageWithLifecycleLayer(l.runImageNameAfterExtensions()); err != nil {
return err
}
ephemeralRunImage = newEphemeralRunImage
}
}

Expand Down Expand Up @@ -543,6 +548,8 @@ func (l *LifecycleExecution) Restore(ctx context.Context, buildCache Cache, kani
registryOp,
layoutOp,
layoutBindOp,
If(l.hasExtensions(), WithPostContainerRunOperations(
CopyOutToMaybe(filepath.Join(l.mountPaths.layersDir(), "analyzed.toml"), l.tmpDir))),
)

restore := phaseFactory.New(configProvider)
Expand Down
5 changes: 3 additions & 2 deletions internal/build/lifecycle_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,9 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
return fakePhaseFactory
})
h.AssertNil(t, err)
h.AssertEq(t, fakeFetcher.calledWithArgAtCall[0], "some-new-run-image-identifier")
h.AssertEq(t, fakeFetcher.callCount, 1)
h.AssertEq(t, fakeFetcher.callCount, 2)
h.AssertEq(t, fakeFetcher.calledWithArgAtCall[0], "some-new-run-image")
h.AssertEq(t, fakeFetcher.calledWithArgAtCall[1], "some-new-run-image-identifier")
})
})
})
Expand Down

0 comments on commit 75b16b6

Please sign in to comment.