Add luet build --wait

It allows to wait for intermediate images to be available instead of
building all of them
This commit is contained in:
Ettore Di Giacinto
2020-12-18 23:19:18 +01:00
parent 34bba0319b
commit 2b6fe2baa1
3 changed files with 18 additions and 1 deletions

View File

@@ -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")

View File

@@ -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
}

View File

@@ -51,6 +51,7 @@ type CompilerOptions struct {
CompressionType CompressionImplementation
KeepImageExport bool
Wait bool
OnlyDeps bool
NoDeps bool
SolverOptions config.LuetSolverOptions