mirror of
https://github.com/mudler/luet.git
synced 2025-09-03 16:25:19 +00:00
Add --backend-args
Allow to add arguments to the backend build arguments Fixes #146
This commit is contained in:
@@ -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")
|
||||
|
@@ -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...)
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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 {
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user