Skip to content

feat: prefix cached image with ENVBUILDER_CACHED_IMAGE in log output #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ ENTRYPOINT [%q]`, exePath, exePath, exePath)
return nil, xerrors.Errorf("get cached image digest: %w", err)
}
endStage("🏗️ Found cached image!")
_, _ = fmt.Fprintf(os.Stdout, "%s@%s\n", options.CacheRepo, digest.String())
_, _ = fmt.Fprintf(os.Stdout, "ENVBUILDER_CACHED_IMAGE=%s@%s\n", options.CacheRepo, digest.String())
os.Exit(0)
}

Expand Down
15 changes: 13 additions & 2 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1172,19 +1172,30 @@ func TestPushImage(t *testing.T) {
}

// Then: re-running envbuilder with GET_CACHED_IMAGE should succeed
_, err = runEnvbuilder(t, options{env: []string{
ctrID, err := runEnvbuilder(t, options{env: []string{
envbuilderEnv("GIT_URL", srv.URL),
envbuilderEnv("CACHE_REPO", testRepo),
envbuilderEnv("GET_CACHED_IMAGE", "1"),
}})
require.NoError(t, err)

// When: we pull the image we just built
// Then: the cached image ref should be emitted in the container logs
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
require.NoError(t, err)
defer cli.Close()
logs, err := cli.ContainerLogs(ctx, ctrID, container.LogsOptions{
ShowStdout: true,
ShowStderr: true,
})
require.NoError(t, err)
defer logs.Close()
logBytes, err := io.ReadAll(logs)
require.NoError(t, err)
require.Regexp(t, `ENVBUILDER_CACHED_IMAGE=(\S+)`, string(logBytes))

// When: we pull the image we just built
rc, err := cli.ImagePull(ctx, ref.String(), image.PullOptions{})
require.NoError(t, err)
t.Cleanup(func() { _ = rc.Close() })
Expand Down