Check only if package image exists

We don't need to look after the builder image as its optional. In this
way we can also reduce the compiler options, as we don't require a
--clean flag anymore. --only-target-package is sufficient to determine
what we can skip and how.
This commit is contained in:
Ettore Di Giacinto
2020-12-14 18:41:39 +01:00
parent ef034d87b0
commit 70f05f41e8
3 changed files with 4 additions and 11 deletions

View File

@@ -60,7 +60,6 @@ Build packages specifying multiple definition trees:
$ luet build --tree overlay/path --tree overlay/path2 utils/yq ... $ luet build --tree overlay/path --tree overlay/path2 utils/yq ...
`, PreRun: func(cmd *cobra.Command, args []string) { `, PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("clean", cmd.Flags().Lookup("clean"))
viper.BindPFlag("tree", cmd.Flags().Lookup("tree")) viper.BindPFlag("tree", cmd.Flags().Lookup("tree"))
viper.BindPFlag("destination", cmd.Flags().Lookup("destination")) viper.BindPFlag("destination", cmd.Flags().Lookup("destination"))
viper.BindPFlag("backend", cmd.Flags().Lookup("backend")) viper.BindPFlag("backend", cmd.Flags().Lookup("backend"))
@@ -87,7 +86,6 @@ Build packages specifying multiple definition trees:
}, },
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
clean := viper.GetBool("clean")
treePaths := viper.GetStringSlice("tree") treePaths := viper.GetStringSlice("tree")
dst := viper.GetString("destination") dst := viper.GetString("destination")
concurrency := LuetCfg.GetGeneral().Concurrency concurrency := LuetCfg.GetGeneral().Concurrency
@@ -172,7 +170,6 @@ Build packages specifying multiple definition trees:
opts := compiler.NewDefaultCompilerOptions() opts := compiler.NewDefaultCompilerOptions()
opts.SolverOptions = *LuetCfg.GetSolverOptions() opts.SolverOptions = *LuetCfg.GetSolverOptions()
opts.ImageRepository = imageRepository opts.ImageRepository = imageRepository
opts.Clean = clean
opts.PullFirst = pull opts.PullFirst = pull
opts.KeepImg = keepImages opts.KeepImg = keepImages
opts.Push = push opts.Push = push
@@ -306,7 +303,6 @@ func init() {
if err != nil { if err != nil {
Fatal(err) Fatal(err)
} }
buildCmd.Flags().Bool("clean", true, "Build all packages locally without considering the packages present or images available")
buildCmd.Flags().StringSliceP("tree", "t", []string{}, "Path of the tree to use.") buildCmd.Flags().StringSliceP("tree", "t", []string{}, "Path of the tree to use.")
buildCmd.Flags().String("backend", "docker", "backend used (docker,img)") buildCmd.Flags().String("backend", "docker", "backend used (docker,img)")
buildCmd.Flags().Bool("privileged", false, "Privileged (Keep permissions)") buildCmd.Flags().Bool("privileged", false, "Privileged (Keep permissions)")

View File

@@ -67,7 +67,6 @@ func NewLuetCompiler(backend CompilerBackend, db pkg.PackageDatabase, opt *Compi
CompressionType: opt.CompressionType, CompressionType: opt.CompressionType,
KeepImg: opt.KeepImg, KeepImg: opt.KeepImg,
Concurrency: opt.Concurrency, Concurrency: opt.Concurrency,
Clean: opt.Clean,
Options: *opt, Options: *opt,
SolverOptions: solvopts, SolverOptions: solvopts,
} }
@@ -505,14 +504,14 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
keepPermissions, keepImg bool, keepPermissions, keepImg bool,
p CompilationSpec, generateArtifact bool) (Artifact, error) { p CompilationSpec, generateArtifact bool) (Artifact, error) {
if !cs.Clean { if !generateArtifact {
exists := cs.Backend.ImageExists(buildertaggedImage) && cs.Backend.ImageExists(packageImage) exists := cs.Backend.ImageExists(packageImage)
if art, err := LoadArtifactFromYaml(p); err == nil && exists { // If YAML is correctly loaded, and both images exists, no reason to rebuild. if art, err := LoadArtifactFromYaml(p); err == nil && exists { // If YAML is correctly loaded, and both images exists, no reason to rebuild.
Debug("Artifact reloaded from YAML. Skipping build") Debug("Artifact reloaded from YAML. Skipping build")
return art, err return art, err
} }
available := cs.Backend.ImageAvailable(buildertaggedImage) && cs.Backend.ImageAvailable(packageImage) available := cs.Backend.ImageAvailable(packageImage)
if (exists || available) && !generateArtifact { if exists || available {
return &PackageArtifact{}, nil return &PackageArtifact{}, nil
} }
} }

View File

@@ -49,7 +49,6 @@ type CompilerOptions struct {
PullFirst, KeepImg, Push bool PullFirst, KeepImg, Push bool
Concurrency int Concurrency int
CompressionType CompressionImplementation CompressionType CompressionImplementation
Clean bool
KeepImageExport bool KeepImageExport bool
OnlyDeps bool OnlyDeps bool
@@ -68,7 +67,6 @@ func NewDefaultCompilerOptions() *CompilerOptions {
CompressionType: None, CompressionType: None,
KeepImg: true, KeepImg: true,
Concurrency: runtime.NumCPU(), Concurrency: runtime.NumCPU(),
Clean: true,
OnlyDeps: false, OnlyDeps: false,
NoDeps: false, NoDeps: false,
} }