mirror of
https://github.com/mudler/luet.git
synced 2025-09-03 16:25:19 +00:00
Fixup luet tree pkglist/images while having shared templates
This commit is contained in:
74
cmd/build.go
74
cmd/build.go
@@ -36,7 +36,6 @@ import (
|
|||||||
tree "github.com/mudler/luet/pkg/tree"
|
tree "github.com/mudler/luet/pkg/tree"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var buildCmd = &cobra.Command{
|
var buildCmd = &cobra.Command{
|
||||||
@@ -66,23 +65,23 @@ 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("tree", cmd.Flags().Lookup("tree"))
|
LuetCfg.Viper.BindPFlag("tree", cmd.Flags().Lookup("tree"))
|
||||||
viper.BindPFlag("destination", cmd.Flags().Lookup("destination"))
|
LuetCfg.Viper.BindPFlag("destination", cmd.Flags().Lookup("destination"))
|
||||||
viper.BindPFlag("backend", cmd.Flags().Lookup("backend"))
|
LuetCfg.Viper.BindPFlag("backend", cmd.Flags().Lookup("backend"))
|
||||||
viper.BindPFlag("privileged", cmd.Flags().Lookup("privileged"))
|
LuetCfg.Viper.BindPFlag("privileged", cmd.Flags().Lookup("privileged"))
|
||||||
viper.BindPFlag("revdeps", cmd.Flags().Lookup("revdeps"))
|
LuetCfg.Viper.BindPFlag("revdeps", cmd.Flags().Lookup("revdeps"))
|
||||||
viper.BindPFlag("all", cmd.Flags().Lookup("all"))
|
LuetCfg.Viper.BindPFlag("all", cmd.Flags().Lookup("all"))
|
||||||
viper.BindPFlag("compression", cmd.Flags().Lookup("compression"))
|
LuetCfg.Viper.BindPFlag("compression", cmd.Flags().Lookup("compression"))
|
||||||
viper.BindPFlag("nodeps", cmd.Flags().Lookup("nodeps"))
|
LuetCfg.Viper.BindPFlag("nodeps", cmd.Flags().Lookup("nodeps"))
|
||||||
viper.BindPFlag("onlydeps", cmd.Flags().Lookup("onlydeps"))
|
LuetCfg.Viper.BindPFlag("onlydeps", cmd.Flags().Lookup("onlydeps"))
|
||||||
util.BindValuesFlags(cmd)
|
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"))
|
LuetCfg.Viper.BindPFlag("image-repository", cmd.Flags().Lookup("image-repository"))
|
||||||
viper.BindPFlag("push", cmd.Flags().Lookup("push"))
|
LuetCfg.Viper.BindPFlag("push", cmd.Flags().Lookup("push"))
|
||||||
viper.BindPFlag("pull", cmd.Flags().Lookup("pull"))
|
LuetCfg.Viper.BindPFlag("pull", cmd.Flags().Lookup("pull"))
|
||||||
viper.BindPFlag("wait", cmd.Flags().Lookup("wait"))
|
LuetCfg.Viper.BindPFlag("wait", cmd.Flags().Lookup("wait"))
|
||||||
viper.BindPFlag("keep-images", cmd.Flags().Lookup("keep-images"))
|
LuetCfg.Viper.BindPFlag("keep-images", cmd.Flags().Lookup("keep-images"))
|
||||||
|
|
||||||
util.BindSolverFlags(cmd)
|
util.BindSolverFlags(cmd)
|
||||||
|
|
||||||
@@ -92,29 +91,29 @@ Build packages specifying multiple definition trees:
|
|||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
treePaths := viper.GetStringSlice("tree")
|
treePaths := LuetCfg.Viper.GetStringSlice("tree")
|
||||||
dst := viper.GetString("destination")
|
dst := LuetCfg.Viper.GetString("destination")
|
||||||
concurrency := LuetCfg.GetGeneral().Concurrency
|
concurrency := LuetCfg.GetGeneral().Concurrency
|
||||||
backendType := viper.GetString("backend")
|
backendType := LuetCfg.Viper.GetString("backend")
|
||||||
privileged := viper.GetBool("privileged")
|
privileged := LuetCfg.Viper.GetBool("privileged")
|
||||||
revdeps := viper.GetBool("revdeps")
|
revdeps := LuetCfg.Viper.GetBool("revdeps")
|
||||||
all := viper.GetBool("all")
|
all := LuetCfg.Viper.GetBool("all")
|
||||||
compressionType := viper.GetString("compression")
|
compressionType := LuetCfg.Viper.GetString("compression")
|
||||||
imageRepository := viper.GetString("image-repository")
|
imageRepository := LuetCfg.Viper.GetString("image-repository")
|
||||||
values := util.ValuesFlags()
|
values := util.ValuesFlags()
|
||||||
wait := viper.GetBool("wait")
|
wait := LuetCfg.Viper.GetBool("wait")
|
||||||
push := viper.GetBool("push")
|
push := LuetCfg.Viper.GetBool("push")
|
||||||
pull := viper.GetBool("pull")
|
pull := LuetCfg.Viper.GetBool("pull")
|
||||||
keepImages := viper.GetBool("keep-images")
|
keepImages := LuetCfg.Viper.GetBool("keep-images")
|
||||||
nodeps := viper.GetBool("nodeps")
|
nodeps := LuetCfg.Viper.GetBool("nodeps")
|
||||||
onlydeps := viper.GetBool("onlydeps")
|
onlydeps := LuetCfg.Viper.GetBool("onlydeps")
|
||||||
onlyTarget, _ := cmd.Flags().GetBool("only-target-package")
|
onlyTarget, _ := cmd.Flags().GetBool("only-target-package")
|
||||||
full, _ := cmd.Flags().GetBool("full")
|
full, _ := cmd.Flags().GetBool("full")
|
||||||
rebuild, _ := cmd.Flags().GetBool("rebuild")
|
rebuild, _ := cmd.Flags().GetBool("rebuild")
|
||||||
|
|
||||||
concurrent, _ := cmd.Flags().GetBool("solver-concurrent")
|
concurrent, _ := cmd.Flags().GetBool("solver-concurrent")
|
||||||
var results Results
|
var results Results
|
||||||
backendArgs := viper.GetStringSlice("backend-args")
|
backendArgs := LuetCfg.Viper.GetStringSlice("backend-args")
|
||||||
|
|
||||||
out, _ := cmd.Flags().GetString("output")
|
out, _ := cmd.Flags().GetString("output")
|
||||||
if out != "terminal" {
|
if out != "terminal" {
|
||||||
@@ -160,17 +159,6 @@ Build packages specifying multiple definition trees:
|
|||||||
opts.Options = solver.Options{Type: solver.SingleCoreSimple, Concurrency: concurrency}
|
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(),
|
luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase(),
|
||||||
options.NoDeps(nodeps),
|
options.NoDeps(nodeps),
|
||||||
options.WithBackendType(backendType),
|
options.WithBackendType(backendType),
|
||||||
@@ -179,7 +167,7 @@ Build packages specifying multiple definition trees:
|
|||||||
options.WithPullRepositories(pullRepo),
|
options.WithPullRepositories(pullRepo),
|
||||||
options.WithPushRepository(imageRepository),
|
options.WithPushRepository(imageRepository),
|
||||||
options.Rebuild(rebuild),
|
options.Rebuild(rebuild),
|
||||||
options.WithTemplateFolder(templateFolders),
|
options.WithTemplateFolder(util.TemplateFolders(fromRepo, treePaths)),
|
||||||
options.WithSolverOptions(*opts),
|
options.WithSolverOptions(*opts),
|
||||||
options.Wait(wait),
|
options.Wait(wait),
|
||||||
options.OnlyTarget(onlyTarget),
|
options.OnlyTarget(onlyTarget),
|
||||||
|
@@ -86,6 +86,7 @@ func NewTreeImageCommand() *cobra.Command {
|
|||||||
options.WithBuildValues(values),
|
options.WithBuildValues(values),
|
||||||
options.WithPushRepository(imageRepository),
|
options.WithPushRepository(imageRepository),
|
||||||
options.WithPullRepositories(pullRepo),
|
options.WithPullRepositories(pullRepo),
|
||||||
|
options.WithTemplateFolder(util.TemplateFolders(false, treePath)),
|
||||||
options.WithSolverOptions(opts),
|
options.WithSolverOptions(opts),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -167,78 +167,79 @@ func NewTreePkglistCommand() *cobra.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if addPkg {
|
if !addPkg {
|
||||||
if revdeps {
|
continue
|
||||||
packs, _ := reciper.GetDatabase().GetRevdeps(p)
|
}
|
||||||
for _, revdep := range packs {
|
|
||||||
|
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 {
|
if full {
|
||||||
pkgstr = pkgDetail(revdep)
|
pkgstr = pkgDetail(pa.Package)
|
||||||
} else if verbose {
|
} else if verbose {
|
||||||
pkgstr = revdep.HumanReadableString()
|
pkgstr = pa.Package.HumanReadableString()
|
||||||
} else {
|
} 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)
|
plist = append(plist, pkgstr)
|
||||||
results.Packages = append(results.Packages, TreePackageResult{
|
results.Packages = append(results.Packages, TreePackageResult{
|
||||||
Name: revdep.GetName(),
|
Name: pa.Package.GetName(),
|
||||||
Version: revdep.GetVersion(),
|
Version: pa.Package.GetVersion(),
|
||||||
Category: revdep.GetCategory(),
|
Category: pa.Package.GetCategory(),
|
||||||
Path: revdep.GetPath(),
|
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)
|
y, err := yaml.Marshal(results)
|
||||||
|
@@ -17,13 +17,14 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"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/config"
|
. "github.com/mudler/luet/pkg/config"
|
||||||
|
"github.com/mudler/luet/pkg/installer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BindSystemFlags(cmd *cobra.Command) {
|
func BindSystemFlags(cmd *cobra.Command) {
|
||||||
@@ -40,11 +41,11 @@ func BindSolverFlags(cmd *cobra.Command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BindValuesFlags(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 {
|
func ValuesFlags() []string {
|
||||||
return viper.GetStringSlice("values")
|
return LuetCfg.Viper.GetStringSlice("values")
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetSystemConfig() {
|
func SetSystemConfig() {
|
||||||
@@ -91,3 +92,18 @@ func SetCliFinalizerEnvs(finalizerEnvs []string) error {
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user