diff --git a/cmd/build.go b/cmd/build.go index 0a429f30..4a7b36b1 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -72,6 +72,7 @@ Build packages specifying multiple definition trees: viper.BindPFlag("nodeps", cmd.Flags().Lookup("nodeps")) viper.BindPFlag("onlydeps", cmd.Flags().Lookup("onlydeps")) viper.BindPFlag("values", cmd.Flags().Lookup("values")) + viper.BindPFlag("backend-args", cmd.Flags().Lookup("backend-args")) viper.BindPFlag("image-repository", cmd.Flags().Lookup("image-repository")) viper.BindPFlag("push", cmd.Flags().Lookup("push")) @@ -84,6 +85,7 @@ Build packages specifying multiple definition trees: LuetCfg.Viper.BindPFlag("solver.rate", cmd.Flags().Lookup("solver-rate")) LuetCfg.Viper.BindPFlag("solver.max_attempts", cmd.Flags().Lookup("solver-attempts")) LuetCfg.Viper.BindPFlag("general.show_build_output", cmd.Flags().Lookup("live-output")) + LuetCfg.Viper.BindPFlag("backend-args", cmd.Flags().Lookup("backend-args")) }, Run: func(cmd *cobra.Command, args []string) { @@ -109,6 +111,7 @@ Build packages specifying multiple definition trees: full, _ := cmd.Flags().GetBool("full") concurrent, _ := cmd.Flags().GetBool("solver-concurrent") var results Results + backendArgs := viper.GetStringSlice("backend-args") out, _ := cmd.Flags().GetString("output") if out != "terminal" { @@ -180,6 +183,7 @@ Build packages specifying multiple definition trees: } luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase(), opts, solverOpts) + luetCompiler.SetBackendArgs(backendArgs) luetCompiler.SetConcurrency(concurrency) luetCompiler.SetCompressionType(compiler.CompressionImplementation(compressionType)) if full { @@ -297,6 +301,7 @@ func init() { if err != nil { Fatal(err) } + buildCmd.Flags().StringSliceP("tree", "t", []string{path}, "Path of the tree to use.") buildCmd.Flags().String("backend", "docker", "backend used (docker,img)") buildCmd.Flags().Bool("privileged", false, "Privileged (Keep permissions)") @@ -305,6 +310,7 @@ func init() { buildCmd.Flags().Bool("all", false, "Build all specfiles in the tree") buildCmd.Flags().Bool("full", false, "Build all packages (optimized)") buildCmd.Flags().String("values", "", "Build values file to interpolate with each package") + buildCmd.Flags().StringSliceP("backend-args", "a", []string{}, "Backend args") buildCmd.Flags().String("destination", filepath.Join(path, "build"), "Destination folder") buildCmd.Flags().String("compression", "none", "Compression alg: none, gzip, zstd") diff --git a/pkg/compiler/backend/common.go b/pkg/compiler/backend/common.go index db558e44..0c6f80cb 100644 --- a/pkg/compiler/backend/common.go +++ b/pkg/compiler/backend/common.go @@ -74,3 +74,13 @@ func runCommand(cmd *exec.Cmd) error { return nil } + +func genBuildCommand(opts compiler.CompilerBackendOptions) []string { + context := opts.Context + + if context == "" { + context = "." + } + buildarg := append(opts.BackendArgs, "-f", opts.DockerFileName, "-t", opts.ImageName, context) + return append([]string{"build"}, buildarg...) +} diff --git a/pkg/compiler/backend/simpledocker.go b/pkg/compiler/backend/simpledocker.go index 6c0e6d56..f8a86d2e 100644 --- a/pkg/compiler/backend/simpledocker.go +++ b/pkg/compiler/backend/simpledocker.go @@ -44,18 +44,11 @@ func NewSimpleDockerBackend() compiler.CompilerBackend { // TODO: Missing still: labels, and build args expansion func (*SimpleDocker) BuildImage(opts compiler.CompilerBackendOptions) error { name := opts.ImageName - path := opts.SourcePath - dockerfileName := opts.DockerFileName - context := opts.Context - - if context == "" { - context = "." - } - buildarg := []string{"build", "-f", dockerfileName, "-t", name, context} + buildarg := genBuildCommand(opts) Info(":whale2: Building image " + name) cmd := exec.Command("docker", buildarg...) - cmd.Dir = path + cmd.Dir = opts.SourcePath err := runCommand(cmd) if err != nil { return err diff --git a/pkg/compiler/backend/simpleimg.go b/pkg/compiler/backend/simpleimg.go index 67075513..82c45cf2 100644 --- a/pkg/compiler/backend/simpleimg.go +++ b/pkg/compiler/backend/simpleimg.go @@ -35,20 +35,13 @@ func NewSimpleImgBackend() compiler.CompilerBackend { // TODO: Missing still: labels, and build args expansion func (*SimpleImg) BuildImage(opts compiler.CompilerBackendOptions) error { name := opts.ImageName - path := opts.SourcePath - context := opts.Context - if context == "" { - context = "." - } - dockerfileName := opts.DockerFileName - - buildarg := []string{"build", "-f", dockerfileName, "-t", name, context} + buildarg := genBuildCommand(opts) Info(":tea: Building image " + name) cmd := exec.Command("img", buildarg...) - cmd.Dir = path + cmd.Dir = opts.SourcePath err := runCommand(cmd) if err != nil { return err diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index ba7bd903..87aecda6 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -51,6 +51,7 @@ type LuetCompiler struct { CompressionType CompressionImplementation Options CompilerOptions SolverOptions solver.Options + BackedArgs []string } func NewLuetCompiler(backend CompilerBackend, db pkg.PackageDatabase, opt *CompilerOptions, solvopts solver.Options) Compiler { @@ -70,7 +71,9 @@ func NewLuetCompiler(backend CompilerBackend, db pkg.PackageDatabase, opt *Compi SolverOptions: solvopts, } } - +func (cs *LuetCompiler) SetBackendArgs(args []string) { + cs.BackedArgs = args +} func (cs *LuetCompiler) SetConcurrency(i int) { cs.Concurrency = i } @@ -381,12 +384,14 @@ func (cs *LuetCompiler) buildPackageImage(image, buildertaggedImage, packageImag SourcePath: buildDir, DockerFileName: p.GetPackage().GetFingerPrint() + "-builder.dockerfile", Destination: p.Rel(p.GetPackage().GetFingerPrint() + "-builder.image.tar"), + BackendArgs: cs.BackedArgs, } runnerOpts = CompilerBackendOptions{ ImageName: packageImage, SourcePath: buildDir, DockerFileName: p.GetPackage().GetFingerPrint() + ".dockerfile", Destination: p.Rel(p.GetPackage().GetFingerPrint() + ".image.tar"), + BackendArgs: cs.BackedArgs, } buildAndPush := func(opts CompilerBackendOptions) error { diff --git a/pkg/compiler/interface.go b/pkg/compiler/interface.go index 012484f3..c1516048 100644 --- a/pkg/compiler/interface.go +++ b/pkg/compiler/interface.go @@ -34,6 +34,8 @@ type Compiler interface { FromDatabase(db pkg.PackageDatabase, minimum bool, dst string) ([]CompilationSpec, error) SetBackend(CompilerBackend) GetBackend() CompilerBackend + + SetBackendArgs([]string) SetCompressionType(t CompressionImplementation) } @@ -43,6 +45,7 @@ type CompilerBackendOptions struct { DockerFileName string Destination string Context string + BackendArgs []string } type CompilerOptions struct {