diff --git a/cmd/build.go b/cmd/build.go index 78ad2026..edb1126c 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -75,6 +75,7 @@ Build packages specifying multiple definition trees: viper.BindPFlag("image-repository", cmd.Flags().Lookup("image-repository")) viper.BindPFlag("push", cmd.Flags().Lookup("push")) viper.BindPFlag("pull", cmd.Flags().Lookup("pull")) + viper.BindPFlag("wait", cmd.Flags().Lookup("wait")) viper.BindPFlag("keep-images", cmd.Flags().Lookup("keep-images")) LuetCfg.Viper.BindPFlag("keep-exported-images", cmd.Flags().Lookup("keep-exported-images")) @@ -97,7 +98,7 @@ Build packages specifying multiple definition trees: compressionType := viper.GetString("compression") imageRepository := viper.GetString("image-repository") values := viper.GetString("values") - + wait := viper.GetBool("wait") push := viper.GetBool("push") pull := viper.GetBool("pull") keepImages := viper.GetBool("keep-images") @@ -175,6 +176,7 @@ Build packages specifying multiple definition trees: opts.Push = push opts.OnlyDeps = onlydeps opts.NoDeps = nodeps + opts.Wait = wait opts.KeepImageExport = keepExportedImages opts.PackageTargetOnly = onlyTarget opts.BuildValuesFile = values @@ -317,6 +319,7 @@ func init() { buildCmd.Flags().String("image-repository", "luet/cache", "Default base image string for generated image") buildCmd.Flags().Bool("push", false, "Push images to a hub") buildCmd.Flags().Bool("pull", false, "Pull images from a hub") + buildCmd.Flags().Bool("wait", false, "Don't build all intermediate images, but wait for them until they are available") buildCmd.Flags().Bool("keep-images", true, "Keep built docker images in the host") buildCmd.Flags().Bool("nodeps", false, "Build only the target packages, skipping deps (it works only if you already built the deps locally, or by using --pull) ") buildCmd.Flags().Bool("onlydeps", false, "Build only package dependencies") diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index cb7a8252..11c58332 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -507,6 +507,18 @@ func (cs *LuetCompiler) genArtifact(p CompilationSpec, builderOpts, runnerOpts C return artifact, nil } +func (cs *LuetCompiler) waitForImage(image string) { + if cs.Options.PullFirst && cs.Options.Wait && !cs.Backend.ImageAvailable(image) { + Info(fmt.Sprintf("Waiting for image %s to be available... :zzz:", image)) + Spinner(22) + defer SpinnerStop() + for !cs.Backend.ImageAvailable(image) { + Info(fmt.Sprintf("Image %s not available yet, sleeping", image)) + time.Sleep(5 * time.Second) + } + } +} + func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage string, concurrency int, keepPermissions, keepImg bool, @@ -518,6 +530,7 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage Debug("Artifact reloaded from YAML. Skipping build") return art, err } + cs.waitForImage(packageImage) if cs.Options.PullFirst && cs.Backend.ImageAvailable(packageImage) { return &PackageArtifact{}, nil } diff --git a/pkg/compiler/interface.go b/pkg/compiler/interface.go index 1263ea2f..5288a1b4 100644 --- a/pkg/compiler/interface.go +++ b/pkg/compiler/interface.go @@ -51,6 +51,7 @@ type CompilerOptions struct { CompressionType CompressionImplementation KeepImageExport bool + Wait bool OnlyDeps bool NoDeps bool SolverOptions config.LuetSolverOptions