Skip to content

extract RunCacheProbe function #284

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 10 commits into from
Jul 31, 2024
14 changes: 14 additions & 0 deletions cmd/envbuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func envbuilderCmd() serpent.Command {
Use: "envbuilder",
Options: o.CLI(),
Handler: func(inv *serpent.Invocation) error {
o.SetDefaults()
o.Logger = log.New(os.Stderr, o.Verbose)
if o.CoderAgentURL != "" {
if o.CoderAgentToken == "" {
Expand Down Expand Up @@ -63,6 +64,19 @@ func envbuilderCmd() serpent.Command {
}
}

if o.GetCachedImage {
img, err := envbuilder.RunCacheProbe(inv.Context(), o)
if err != nil {
o.Logger(log.LevelError, "error: %s", err)
}
digest, err := img.Digest()
if err != nil {
return fmt.Errorf("get cached image digest: %w", err)
}
_, _ = fmt.Fprintf(inv.Stdout, "ENVBUILDER_CACHED_IMAGE=%s@%s\n", o.CacheRepo, digest.String())
return nil
}

err := envbuilder.Run(inv.Context(), o)
if err != nil {
o.Logger(log.LevelError, "error: %s", err)
Expand Down
Loading