Compare commits

...

2 Commits

Author SHA1 Message Date
Ettore Di Giacinto
bff45b9bd9 🆕 Tag 0.22.7 2022-01-09 14:45:13 +01:00
Ettore Di Giacinto
7e589b07b8 ⚙️ Resolve templates folder when syncing repositories
This fixes #284
2022-01-09 14:44:44 +01:00
7 changed files with 79 additions and 29 deletions

View File

@@ -131,16 +131,21 @@ Build packages specifying multiple definition trees:
generalRecipe := tree.NewCompilerRecipe(db)
if fromRepo {
if err := installer.LoadBuildTree(generalRecipe, db, util.DefaultContext); err != nil {
util.DefaultContext.Warning("errors while loading trees from repositories", err.Error())
}
}
for _, src := range treePaths {
util.DefaultContext.Info("Loading tree", src)
helpers.CheckErr(generalRecipe.Load(src))
}
templateFolders := []string{}
if fromRepo {
bt, err := installer.LoadBuildTree(generalRecipe, db, util.DefaultContext)
if err != nil {
util.DefaultContext.Warning("errors while loading trees from repositories", err.Error())
}
templateFolders = util.TemplateFolders(util.DefaultContext, bt, treePaths)
} else {
templateFolders = util.TemplateFolders(util.DefaultContext, installer.BuildTreeResult{}, treePaths)
}
util.DefaultContext.Info("Building in", dst)
@@ -161,7 +166,7 @@ Build packages specifying multiple definition trees:
options.WithPullRepositories(pullRepo),
options.WithPushRepository(imageRepository),
options.Rebuild(rebuild),
options.WithTemplateFolder(util.TemplateFolders(util.DefaultContext, fromRepo, treePaths)),
options.WithTemplateFolder(templateFolders),
options.WithSolverOptions(opts),
options.Wait(wait),
options.OnlyTarget(onlyTarget),

View File

@@ -30,7 +30,7 @@ var cfgFile string
var Verbose bool
const (
LuetCLIVersion = "0.22.6"
LuetCLIVersion = "0.22.7"
LuetEnvPrefix = "LUET"
)

View File

@@ -26,6 +26,7 @@ import (
"github.com/mudler/luet/pkg/compiler"
"github.com/mudler/luet/pkg/compiler/backend"
"github.com/mudler/luet/pkg/compiler/types/options"
"github.com/mudler/luet/pkg/installer"
pkg "github.com/mudler/luet/pkg/package"
"github.com/mudler/luet/pkg/solver"
@@ -84,7 +85,7 @@ func NewTreeImageCommand() *cobra.Command {
options.WithContext(util.DefaultContext),
options.WithPushRepository(imageRepository),
options.WithPullRepositories(pullRepo),
options.WithTemplateFolder(util.TemplateFolders(util.DefaultContext, false, treePath)),
options.WithTemplateFolder(util.TemplateFolders(util.DefaultContext, installer.BuildTreeResult{}, treePath)),
options.WithSolverOptions(opts),
)

View File

@@ -17,7 +17,6 @@ package util
import (
"os"
"path/filepath"
"strings"
"github.com/marcsauter/single"
@@ -26,6 +25,7 @@ import (
"github.com/spf13/viper"
"github.com/mudler/luet/pkg/api/core/context"
"github.com/mudler/luet/pkg/api/core/template"
"github.com/mudler/luet/pkg/api/core/types"
"github.com/mudler/luet/pkg/installer"
)
@@ -42,16 +42,15 @@ func ValuesFlags() []string {
}
// TemplateFolders returns the default folders which holds shared template between packages in a given tree path
func TemplateFolders(ctx *context.Context, fromRepo bool, treePaths []string) []string {
func TemplateFolders(ctx *context.Context, i installer.BuildTreeResult, treePaths []string) []string {
templateFolders := []string{}
for _, t := range treePaths {
templateFolders = append(templateFolders, filepath.Join(t, "templates"))
}
if fromRepo {
for _, s := range installer.SystemRepositories(ctx.GetConfig().SystemRepositories) {
templateFolders = append(templateFolders, filepath.Join(s.TreePath, "templates"))
templateFolders = append(templateFolders, template.FindPossibleTemplatesDir(t)...)
}
for _, r := range i.TemplatesDir {
templateFolders = append(templateFolders, r...)
}
return templateFolders
}

View File

@@ -0,0 +1,39 @@
// Copyright © 2022 Ettore Di Giacinto <mudler@mocaccino.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see <http://www.gnu.org/licenses/>.
package template
import (
"os"
"path/filepath"
)
const Directory = "templates"
// FindPossibleTemplatesDir returns templates dir located at root
func FindPossibleTemplatesDir(root string) (res []string) {
var ff = func(currentpath string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if info.IsDir() && info.Name() == Directory {
res = append(res, currentpath)
}
return nil
}
filepath.Walk(root, ff)
return
}

View File

@@ -27,6 +27,7 @@ import (
"strings"
"time"
"github.com/mudler/luet/pkg/api/core/template"
artifact "github.com/mudler/luet/pkg/api/core/types/artifact"
compression "github.com/mudler/luet/pkg/compiler/types/compression"
fileHelper "github.com/mudler/luet/pkg/helpers/file"
@@ -114,9 +115,18 @@ func SystemRepositories(t types.LuetRepositories) Repositories {
return repos
}
type BuildTreeResult struct {
Repositories Repositories
TemplatesDir map[*LuetSystemRepository][]string
}
// LoadBuildTree loads to the tree the compilation specs from the system repositories
func LoadBuildTree(t tree.Builder, db pkg.PackageDatabase, ctx types.Context) error {
func LoadBuildTree(t tree.Builder, db pkg.PackageDatabase, ctx types.Context) (BuildTreeResult, error) {
var reserr error
res := &BuildTreeResult{
TemplatesDir: make(map[*LuetSystemRepository][]string),
}
repos := SystemRepositories(ctx.GetConfig().SystemRepositories)
for _, r := range repos {
repodir, err := ctx.TempDir(r.Name)
@@ -136,11 +146,14 @@ func LoadBuildTree(t tree.Builder, db pkg.PackageDatabase, ctx types.Context) er
}
r.SetTree(generalRecipe)
res.TemplatesDir[r] = template.FindPossibleTemplatesDir(repodir)
}
res.Repositories = repos
repos.SyncDatabase(db)
return reserr
return *res, reserr
}
func (m *LuetSystemRepositoryMetadata) WriteFile(path string) error {
@@ -277,14 +290,12 @@ func GenerateRepository(p ...RepositoryOption) (*LuetSystemRepository, error) {
generalRecipe := tree.NewCompilerRecipe(repodb)
if c.FromRepository {
if err := LoadBuildTree(generalRecipe, repodb, c.context); err != nil {
if _, err := LoadBuildTree(generalRecipe, repodb, c.context); err != nil {
c.context.Warning("errors while loading trees from repositories", err.Error())
}
if err := repodb.Clone(tempTree); err != nil {
c.context.Warning("errors while cloning trees from repositories", err.Error())
}
}
// Pick only atoms in db which have a real metadata for runtime db (tr)

View File

@@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"github.com/mudler/luet/pkg/api/core/template"
"github.com/mudler/luet/pkg/helpers"
fileHelper "github.com/mudler/luet/pkg/helpers/file"
pkg "github.com/mudler/luet/pkg/package"
@@ -72,18 +73,12 @@ func (r *CompilerRecipe) Save(path string) error {
func (r *CompilerRecipe) Load(path string) error {
r.SourcePath = append(r.SourcePath, path)
//tmpfile, err := ioutil.TempFile("", "luet")
//if err != nil {
// return err
//}
c, err := helpers.ChartFiles([]string{filepath.Join(path, "templates")})
c, err := helpers.ChartFiles(template.FindPossibleTemplatesDir(path))
if err != nil {
return err
}
//r.Tree().SetPackageSet(pkg.NewBoltDatabase(tmpfile.Name()))
// TODO: Handle cleaning after? Cleanup implemented in GetPackageSet().Clean()
// the function that handles each file or dir
var ff = func(currentpath string, info os.FileInfo, err error) error {
if err != nil {