mirror of
https://github.com/mudler/luet.git
synced 2025-09-02 07:45:02 +00:00
Add only-target-package option to luet build
This commit is contained in:
@@ -78,6 +78,7 @@ var buildCmd = &cobra.Command{
|
|||||||
nodeps := viper.GetBool("nodeps")
|
nodeps := viper.GetBool("nodeps")
|
||||||
onlydeps := viper.GetBool("onlydeps")
|
onlydeps := viper.GetBool("onlydeps")
|
||||||
keepExportedImages := viper.GetBool("keep-exported-images")
|
keepExportedImages := viper.GetBool("keep-exported-images")
|
||||||
|
onlyTarget, _ := cmd.Flags().GetBool("only-target-package")
|
||||||
full, _ := cmd.Flags().GetBool("full")
|
full, _ := cmd.Flags().GetBool("full")
|
||||||
skip, _ := cmd.Flags().GetBool("skip-if-metadata-exists")
|
skip, _ := cmd.Flags().GetBool("skip-if-metadata-exists")
|
||||||
|
|
||||||
@@ -145,6 +146,7 @@ var buildCmd = &cobra.Command{
|
|||||||
opts.NoDeps = nodeps
|
opts.NoDeps = nodeps
|
||||||
opts.KeepImageExport = keepExportedImages
|
opts.KeepImageExport = keepExportedImages
|
||||||
opts.SkipIfMetadataExists = skip
|
opts.SkipIfMetadataExists = skip
|
||||||
|
opts.PackageTargetOnly = onlyTarget
|
||||||
|
|
||||||
luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase(), opts)
|
luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase(), opts)
|
||||||
luetCompiler.SetConcurrency(concurrency)
|
luetCompiler.SetConcurrency(concurrency)
|
||||||
@@ -234,7 +236,7 @@ func init() {
|
|||||||
buildCmd.Flags().Bool("onlydeps", false, "Build only package dependencies")
|
buildCmd.Flags().Bool("onlydeps", false, "Build only package dependencies")
|
||||||
buildCmd.Flags().Bool("keep-exported-images", false, "Keep exported images used during building")
|
buildCmd.Flags().Bool("keep-exported-images", false, "Keep exported images used during building")
|
||||||
buildCmd.Flags().Bool("skip-if-metadata-exists", false, "Skip package if metadata exists")
|
buildCmd.Flags().Bool("skip-if-metadata-exists", false, "Skip package if metadata exists")
|
||||||
|
buildCmd.Flags().Bool("only-target-package", false, "Build packages of only the required target. Otherwise builds all the necessary ones not present in the destination")
|
||||||
buildCmd.Flags().String("solver-type", "", "Solver strategy")
|
buildCmd.Flags().String("solver-type", "", "Solver strategy")
|
||||||
buildCmd.Flags().Float32("solver-rate", 0.7, "Solver learning rate")
|
buildCmd.Flags().Float32("solver-rate", 0.7, "Solver learning rate")
|
||||||
buildCmd.Flags().Float32("solver-discount", 1.0, "Solver discount rate")
|
buildCmd.Flags().Float32("solver-discount", 1.0, "Solver discount rate")
|
||||||
|
@@ -17,11 +17,12 @@ package compiler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ghodss/yaml"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/ghodss/yaml"
|
||||||
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -232,7 +233,7 @@ func (cs *LuetCompiler) stripIncludesFromRootfs(includes []string, rootfs string
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage string, concurrency int, keepPermissions, keepImg bool, p CompilationSpec) (Artifact, error) {
|
func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage string, concurrency int, keepPermissions, keepImg bool, p CompilationSpec, generateArtifact bool) (Artifact, error) {
|
||||||
|
|
||||||
pkgTag := ":package: " + p.GetPackage().GetName()
|
pkgTag := ":package: " + p.GetPackage().GetName()
|
||||||
|
|
||||||
@@ -339,12 +340,6 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
|
|||||||
Destination: p.Rel(p.GetPackage().GetFingerPrint() + ".image.tar"),
|
Destination: p.Rel(p.GetPackage().GetFingerPrint() + ".image.tar"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// if !keepPackageImg {
|
|
||||||
// err = cs.Backend.ImageDefinitionToTar(runnerOpts)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, errors.Wrap(err, "Could not export image to tar")
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
buildPackageImage := true
|
buildPackageImage := true
|
||||||
if cs.Options.PullFirst {
|
if cs.Options.PullFirst {
|
||||||
//Best effort pull
|
//Best effort pull
|
||||||
@@ -373,7 +368,6 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
|
|||||||
return nil, errors.Wrap(err, "Could not push image: "+image+" "+builderOpts.DockerFileName)
|
return nil, errors.Wrap(err, "Could not push image: "+image+" "+builderOpts.DockerFileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
var artifact Artifact
|
var artifact Artifact
|
||||||
unpack := p.ImageUnpack()
|
unpack := p.ImageUnpack()
|
||||||
@@ -413,8 +407,11 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if unpack {
|
if !generateArtifact {
|
||||||
|
return &PackageArtifact{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if unpack {
|
||||||
if p.GetPackageDir() != "" {
|
if p.GetPackageDir() != "" {
|
||||||
Info(":tophat: Packing from output dir", p.GetPackageDir())
|
Info(":tophat: Packing from output dir", p.GetPackageDir())
|
||||||
rootfs = filepath.Join(rootfs, p.GetPackageDir())
|
rootfs = filepath.Join(rootfs, p.GetPackageDir())
|
||||||
@@ -566,7 +563,7 @@ func (cs *LuetCompiler) compile(concurrency int, keepPermissions bool, p Compila
|
|||||||
// - If image is set we just generate a plain dockerfile
|
// - If image is set we just generate a plain dockerfile
|
||||||
// Treat last case (easier) first. The image is provided and we just compute a plain dockerfile with the images listed as above
|
// Treat last case (easier) first. The image is provided and we just compute a plain dockerfile with the images listed as above
|
||||||
if p.GetImage() != "" {
|
if p.GetImage() != "" {
|
||||||
return cs.compileWithImage(p.GetImage(), "", targetPackageHash, concurrency, keepPermissions, cs.KeepImg, p)
|
return cs.compileWithImage(p.GetImage(), "", targetPackageHash, concurrency, keepPermissions, cs.KeepImg, p, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - If image is not set, we read a base_image. Then we will build one image from it to kick-off our build based
|
// - If image is not set, we read a base_image. Then we will build one image from it to kick-off our build based
|
||||||
@@ -580,6 +577,7 @@ func (cs *LuetCompiler) compile(concurrency int, keepPermissions bool, p Compila
|
|||||||
depsN := 0
|
depsN := 0
|
||||||
currentN := 0
|
currentN := 0
|
||||||
|
|
||||||
|
packageDeps := !cs.Options.PackageTargetOnly
|
||||||
if !cs.Options.NoDeps {
|
if !cs.Options.NoDeps {
|
||||||
Info(":deciduous_tree: Build dependencies for " + p.GetPackage().HumanReadableString())
|
Info(":deciduous_tree: Build dependencies for " + p.GetPackage().HumanReadableString())
|
||||||
for _, assertion := range dependencies { //highly dependent on the order
|
for _, assertion := range dependencies { //highly dependent on the order
|
||||||
@@ -605,7 +603,7 @@ func (cs *LuetCompiler) compile(concurrency int, keepPermissions bool, p Compila
|
|||||||
lastHash = currentPackageImageHash
|
lastHash = currentPackageImageHash
|
||||||
if compileSpec.GetImage() != "" {
|
if compileSpec.GetImage() != "" {
|
||||||
Debug(pkgTag, " :wrench: Compiling "+compileSpec.GetPackage().HumanReadableString()+" from image")
|
Debug(pkgTag, " :wrench: Compiling "+compileSpec.GetPackage().HumanReadableString()+" from image")
|
||||||
artifact, err := cs.compileWithImage(compileSpec.GetImage(), buildImageHash, currentPackageImageHash, concurrency, keepPermissions, cs.KeepImg, compileSpec)
|
artifact, err := cs.compileWithImage(compileSpec.GetImage(), buildImageHash, currentPackageImageHash, concurrency, keepPermissions, cs.KeepImg, compileSpec, packageDeps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Failed compiling "+compileSpec.GetPackage().HumanReadableString())
|
return nil, errors.Wrap(err, "Failed compiling "+compileSpec.GetPackage().HumanReadableString())
|
||||||
}
|
}
|
||||||
@@ -615,7 +613,7 @@ func (cs *LuetCompiler) compile(concurrency int, keepPermissions bool, p Compila
|
|||||||
}
|
}
|
||||||
|
|
||||||
Debug(pkgTag, " :wrench: Compiling "+compileSpec.GetPackage().HumanReadableString()+" from tree")
|
Debug(pkgTag, " :wrench: Compiling "+compileSpec.GetPackage().HumanReadableString()+" from tree")
|
||||||
artifact, err := cs.compileWithImage(buildImageHash, "", currentPackageImageHash, concurrency, keepPermissions, cs.KeepImg, compileSpec)
|
artifact, err := cs.compileWithImage(buildImageHash, "", currentPackageImageHash, concurrency, keepPermissions, cs.KeepImg, compileSpec, packageDeps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Failed compiling "+compileSpec.GetPackage().HumanReadableString())
|
return nil, errors.Wrap(err, "Failed compiling "+compileSpec.GetPackage().HumanReadableString())
|
||||||
// deperrs = append(deperrs, err)
|
// deperrs = append(deperrs, err)
|
||||||
@@ -631,7 +629,7 @@ func (cs *LuetCompiler) compile(concurrency int, keepPermissions bool, p Compila
|
|||||||
|
|
||||||
if !cs.Options.OnlyDeps {
|
if !cs.Options.OnlyDeps {
|
||||||
Info(":package:", p.GetPackage().HumanReadableString(), ":cyclone: Building package target from:", lastHash)
|
Info(":package:", p.GetPackage().HumanReadableString(), ":cyclone: Building package target from:", lastHash)
|
||||||
artifact, err := cs.compileWithImage(lastHash, "", targetPackageHash, concurrency, keepPermissions, cs.KeepImg, p)
|
artifact, err := cs.compileWithImage(lastHash, "", targetPackageHash, concurrency, keepPermissions, cs.KeepImg, p, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return artifact, err
|
return artifact, err
|
||||||
}
|
}
|
||||||
|
@@ -56,6 +56,8 @@ type CompilerOptions struct {
|
|||||||
NoDeps bool
|
NoDeps bool
|
||||||
SolverOptions config.LuetSolverOptions
|
SolverOptions config.LuetSolverOptions
|
||||||
SkipIfMetadataExists bool
|
SkipIfMetadataExists bool
|
||||||
|
|
||||||
|
PackageTargetOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultCompilerOptions() *CompilerOptions {
|
func NewDefaultCompilerOptions() *CompilerOptions {
|
||||||
|
Reference in New Issue
Block a user