diff --git a/cmd/build.go b/cmd/build.go index 7a0b5ee6..08fc59cd 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -36,7 +36,6 @@ import ( tree "github.com/mudler/luet/pkg/tree" "github.com/spf13/cobra" - "github.com/spf13/viper" ) var buildCmd = &cobra.Command{ @@ -66,23 +65,23 @@ Build packages specifying multiple definition trees: $ luet build --tree overlay/path --tree overlay/path2 utils/yq ... `, PreRun: func(cmd *cobra.Command, args []string) { - viper.BindPFlag("tree", cmd.Flags().Lookup("tree")) - viper.BindPFlag("destination", cmd.Flags().Lookup("destination")) - viper.BindPFlag("backend", cmd.Flags().Lookup("backend")) - viper.BindPFlag("privileged", cmd.Flags().Lookup("privileged")) - viper.BindPFlag("revdeps", cmd.Flags().Lookup("revdeps")) - viper.BindPFlag("all", cmd.Flags().Lookup("all")) - viper.BindPFlag("compression", cmd.Flags().Lookup("compression")) - viper.BindPFlag("nodeps", cmd.Flags().Lookup("nodeps")) - viper.BindPFlag("onlydeps", cmd.Flags().Lookup("onlydeps")) + LuetCfg.Viper.BindPFlag("tree", cmd.Flags().Lookup("tree")) + LuetCfg.Viper.BindPFlag("destination", cmd.Flags().Lookup("destination")) + LuetCfg.Viper.BindPFlag("backend", cmd.Flags().Lookup("backend")) + LuetCfg.Viper.BindPFlag("privileged", cmd.Flags().Lookup("privileged")) + LuetCfg.Viper.BindPFlag("revdeps", cmd.Flags().Lookup("revdeps")) + LuetCfg.Viper.BindPFlag("all", cmd.Flags().Lookup("all")) + LuetCfg.Viper.BindPFlag("compression", cmd.Flags().Lookup("compression")) + LuetCfg.Viper.BindPFlag("nodeps", cmd.Flags().Lookup("nodeps")) + LuetCfg.Viper.BindPFlag("onlydeps", cmd.Flags().Lookup("onlydeps")) util.BindValuesFlags(cmd) - viper.BindPFlag("backend-args", cmd.Flags().Lookup("backend-args")) + LuetCfg.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")) - 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("image-repository", cmd.Flags().Lookup("image-repository")) + LuetCfg.Viper.BindPFlag("push", cmd.Flags().Lookup("push")) + LuetCfg.Viper.BindPFlag("pull", cmd.Flags().Lookup("pull")) + LuetCfg.Viper.BindPFlag("wait", cmd.Flags().Lookup("wait")) + LuetCfg.Viper.BindPFlag("keep-images", cmd.Flags().Lookup("keep-images")) util.BindSolverFlags(cmd) @@ -92,29 +91,29 @@ Build packages specifying multiple definition trees: }, Run: func(cmd *cobra.Command, args []string) { - treePaths := viper.GetStringSlice("tree") - dst := viper.GetString("destination") + treePaths := LuetCfg.Viper.GetStringSlice("tree") + dst := LuetCfg.Viper.GetString("destination") concurrency := LuetCfg.GetGeneral().Concurrency - backendType := viper.GetString("backend") - privileged := viper.GetBool("privileged") - revdeps := viper.GetBool("revdeps") - all := viper.GetBool("all") - compressionType := viper.GetString("compression") - imageRepository := viper.GetString("image-repository") + backendType := LuetCfg.Viper.GetString("backend") + privileged := LuetCfg.Viper.GetBool("privileged") + revdeps := LuetCfg.Viper.GetBool("revdeps") + all := LuetCfg.Viper.GetBool("all") + compressionType := LuetCfg.Viper.GetString("compression") + imageRepository := LuetCfg.Viper.GetString("image-repository") values := util.ValuesFlags() - wait := viper.GetBool("wait") - push := viper.GetBool("push") - pull := viper.GetBool("pull") - keepImages := viper.GetBool("keep-images") - nodeps := viper.GetBool("nodeps") - onlydeps := viper.GetBool("onlydeps") + wait := LuetCfg.Viper.GetBool("wait") + push := LuetCfg.Viper.GetBool("push") + pull := LuetCfg.Viper.GetBool("pull") + keepImages := LuetCfg.Viper.GetBool("keep-images") + nodeps := LuetCfg.Viper.GetBool("nodeps") + onlydeps := LuetCfg.Viper.GetBool("onlydeps") onlyTarget, _ := cmd.Flags().GetBool("only-target-package") full, _ := cmd.Flags().GetBool("full") rebuild, _ := cmd.Flags().GetBool("rebuild") concurrent, _ := cmd.Flags().GetBool("solver-concurrent") var results Results - backendArgs := viper.GetStringSlice("backend-args") + backendArgs := LuetCfg.Viper.GetStringSlice("backend-args") out, _ := cmd.Flags().GetString("output") if out != "terminal" { @@ -160,17 +159,6 @@ Build packages specifying multiple definition trees: opts.Options = solver.Options{Type: solver.SingleCoreSimple, Concurrency: concurrency} } - templateFolders := []string{} - if !fromRepo { - for _, t := range treePaths { - templateFolders = append(templateFolders, filepath.Join(t, "templates")) - } - } else { - for _, s := range installer.SystemRepositories(LuetCfg) { - templateFolders = append(templateFolders, filepath.Join(s.TreePath, "templates")) - } - } - luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase(), options.NoDeps(nodeps), options.WithBackendType(backendType), @@ -179,7 +167,7 @@ Build packages specifying multiple definition trees: options.WithPullRepositories(pullRepo), options.WithPushRepository(imageRepository), options.Rebuild(rebuild), - options.WithTemplateFolder(templateFolders), + options.WithTemplateFolder(util.TemplateFolders(fromRepo, treePaths)), options.WithSolverOptions(*opts), options.Wait(wait), options.OnlyTarget(onlyTarget), diff --git a/cmd/tree/images.go b/cmd/tree/images.go index 40e4a04b..f470432f 100644 --- a/cmd/tree/images.go +++ b/cmd/tree/images.go @@ -86,6 +86,7 @@ func NewTreeImageCommand() *cobra.Command { options.WithBuildValues(values), options.WithPushRepository(imageRepository), options.WithPullRepositories(pullRepo), + options.WithTemplateFolder(util.TemplateFolders(false, treePath)), options.WithSolverOptions(opts), ) diff --git a/cmd/tree/pkglist.go b/cmd/tree/pkglist.go index 84f59de7..a2d90960 100644 --- a/cmd/tree/pkglist.go +++ b/cmd/tree/pkglist.go @@ -167,78 +167,79 @@ func NewTreePkglistCommand() *cobra.Command { } } - if addPkg { - if revdeps { - packs, _ := reciper.GetDatabase().GetRevdeps(p) - for _, revdep := range packs { + if !addPkg { + continue + } + + if revdeps { + packs, _ := reciper.GetDatabase().GetRevdeps(p) + for i := range packs { + revdep := packs[i] + if full { + pkgstr = pkgDetail(revdep) + } else if verbose { + pkgstr = revdep.HumanReadableString() + } else { + pkgstr = fmt.Sprintf("%s/%s", revdep.GetCategory(), revdep.GetName()) + } + plist = append(plist, pkgstr) + results.Packages = append(results.Packages, TreePackageResult{ + Name: revdep.GetName(), + Version: revdep.GetVersion(), + Category: revdep.GetCategory(), + Path: revdep.GetPath(), + }) + } + } else if deps { + + solution, err := depSolver.Install(pkg.Packages{p}) + if err != nil { + Fatal(err.Error()) + } + ass := solution.SearchByName(p.GetPackageName()) + solution, err = solution.Order(reciper.GetDatabase(), ass.Package.GetFingerPrint()) + if err != nil { + Fatal(err.Error()) + } + + for _, pa := range solution { + + if pa.Value { + // Exclude itself + if pa.Package.GetName() == p.GetName() && pa.Package.GetCategory() == p.GetCategory() { + continue + } + if full { - pkgstr = pkgDetail(revdep) + pkgstr = pkgDetail(pa.Package) } else if verbose { - pkgstr = revdep.HumanReadableString() + pkgstr = pa.Package.HumanReadableString() } else { - pkgstr = fmt.Sprintf("%s/%s", revdep.GetCategory(), revdep.GetName()) + pkgstr = fmt.Sprintf("%s/%s", pa.Package.GetCategory(), pa.Package.GetName()) } plist = append(plist, pkgstr) results.Packages = append(results.Packages, TreePackageResult{ - Name: revdep.GetName(), - Version: revdep.GetVersion(), - Category: revdep.GetCategory(), - Path: revdep.GetPath(), + Name: pa.Package.GetName(), + Version: pa.Package.GetVersion(), + Category: pa.Package.GetCategory(), + Path: pa.Package.GetPath(), }) } - } else if deps { - - Spinner(32) - solution, err := depSolver.Install(pkg.Packages{p}) - if err != nil { - Fatal(err.Error()) - } - ass := solution.SearchByName(p.GetPackageName()) - solution, err = solution.Order(reciper.GetDatabase(), ass.Package.GetFingerPrint()) - if err != nil { - Fatal(err.Error()) - } - SpinnerStop() - - for _, pa := range solution { - - if pa.Value { - // Exclude itself - if pa.Package.GetName() == p.GetName() && pa.Package.GetCategory() == p.GetCategory() { - continue - } - - if full { - pkgstr = pkgDetail(pa.Package) - } else if verbose { - pkgstr = pa.Package.HumanReadableString() - } else { - pkgstr = fmt.Sprintf("%s/%s", pa.Package.GetCategory(), pa.Package.GetName()) - } - plist = append(plist, pkgstr) - results.Packages = append(results.Packages, TreePackageResult{ - Name: pa.Package.GetName(), - Version: pa.Package.GetVersion(), - Category: pa.Package.GetCategory(), - Path: pa.Package.GetPath(), - }) - } - - } - - } else { - - plist = append(plist, pkgstr) - results.Packages = append(results.Packages, TreePackageResult{ - Name: p.GetName(), - Version: p.GetVersion(), - Category: p.GetCategory(), - Path: p.GetPath(), - }) } + } else { + + plist = append(plist, pkgstr) + results.Packages = append(results.Packages, TreePackageResult{ + Name: p.GetName(), + Version: p.GetVersion(), + Category: p.GetCategory(), + Path: p.GetPath(), + }) + } + } y, err := yaml.Marshal(results) diff --git a/cmd/util/cli.go b/cmd/util/cli.go index 2134bb1b..04037630 100644 --- a/cmd/util/cli.go +++ b/cmd/util/cli.go @@ -17,13 +17,14 @@ package util import ( "errors" + "path/filepath" "strings" "github.com/spf13/cobra" - "github.com/spf13/viper" "github.com/mudler/luet/pkg/config" . "github.com/mudler/luet/pkg/config" + "github.com/mudler/luet/pkg/installer" ) func BindSystemFlags(cmd *cobra.Command) { @@ -40,11 +41,11 @@ func BindSolverFlags(cmd *cobra.Command) { } func BindValuesFlags(cmd *cobra.Command) { - viper.BindPFlag("values", cmd.Flags().Lookup("values")) + LuetCfg.Viper.BindPFlag("values", cmd.Flags().Lookup("values")) } func ValuesFlags() []string { - return viper.GetStringSlice("values") + return LuetCfg.Viper.GetStringSlice("values") } func SetSystemConfig() { @@ -91,3 +92,18 @@ func SetCliFinalizerEnvs(finalizerEnvs []string) error { return nil } + +// TemplateFolders returns the default folders which holds shared template between packages in a given tree path +func TemplateFolders(fromRepo bool, treePaths []string) []string { + templateFolders := []string{} + if !fromRepo { + for _, t := range treePaths { + templateFolders = append(templateFolders, filepath.Join(t, "templates")) + } + } else { + for _, s := range installer.SystemRepositories(LuetCfg) { + templateFolders = append(templateFolders, filepath.Join(s.TreePath, "templates")) + } + } + return templateFolders +}