mirror of
https://github.com/mudler/luet.git
synced 2025-09-15 23:00:04 +00:00
⚙️ Add ability to build from Dockerfiles directly
This commit is contained in:
committed by
mudler
parent
4e2a2adfc1
commit
e70a543f42
@@ -35,12 +35,14 @@ const (
|
||||
CompilerDefinitionFile = "build.yaml"
|
||||
)
|
||||
|
||||
var DefaultCompilerParsers = []FileParser{
|
||||
BuildCollectionParser,
|
||||
BuildDefinitionParser,
|
||||
}
|
||||
|
||||
func NewCompilerRecipe(d types.PackageDatabase, fp ...FileParser) Builder {
|
||||
if len(fp) == 0 {
|
||||
fp = []FileParser{
|
||||
BuildCollectionParser,
|
||||
BuildDefinitionParser,
|
||||
}
|
||||
fp = DefaultCompilerParsers
|
||||
}
|
||||
return &CompilerRecipe{Recipe: Recipe{Database: d}, fileParsers: fp}
|
||||
}
|
||||
|
62
pkg/tree/dockerfile_parser.go
Normal file
62
pkg/tree/dockerfile_parser.go
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright © 2022 Ettore Di Giacinto <mudler@luet.io>
|
||||
//
|
||||
// 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 tree
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mudler/luet/pkg/api/core/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func RuntimeDockerfileParser(srcDir, currentpath, name string, templates []string, db types.PackageDatabase) error {
|
||||
if !strings.Contains(name, "Dockerfile") {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Path is set only internally when tree is loaded from disk
|
||||
_, err := db.CreatePackage(&types.Package{Name: filepath.Base(filepath.Dir(currentpath)), Path: filepath.Dir(currentpath), TreeDir: srcDir})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error creating package "+currentpath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func BuildDockerfileParser(srcDir, currentpath, name string, templates []string, db types.PackageDatabase) error {
|
||||
if !strings.Contains(name, "Dockerfile") {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Simply imply the name package from the directory name
|
||||
// TODO: Read specific labels from dockerfile as we do read the image already
|
||||
p := &types.Package{
|
||||
Name: filepath.Base(filepath.Dir(currentpath)),
|
||||
Path: filepath.Dir(currentpath),
|
||||
TreeDir: srcDir}
|
||||
|
||||
err := p.SetOriginalDockerfile(currentpath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error reading file "+currentpath)
|
||||
}
|
||||
|
||||
// Path is set only internally when tree is loaded from disk
|
||||
_, err = db.CreatePackage(p)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error creating package "+currentpath)
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -26,6 +26,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mudler/luet/pkg/api/core/template"
|
||||
"github.com/mudler/luet/pkg/api/core/types"
|
||||
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
||||
|
||||
@@ -36,12 +37,14 @@ const (
|
||||
FinalizerFile = "finalize.yaml"
|
||||
)
|
||||
|
||||
var DefaultInstallerParsers = []FileParser{
|
||||
RuntimeCollectionParser,
|
||||
RuntimeDefinitionParser,
|
||||
}
|
||||
|
||||
func NewInstallerRecipe(db types.PackageDatabase, fp ...FileParser) Builder {
|
||||
if len(fp) == 0 {
|
||||
fp = []FileParser{
|
||||
RuntimeCollectionParser,
|
||||
RuntimeDefinitionParser,
|
||||
}
|
||||
fp = DefaultInstallerParsers
|
||||
}
|
||||
return &InstallerRecipe{Database: db, fileParsers: fp}
|
||||
}
|
||||
@@ -87,20 +90,24 @@ func (r *InstallerRecipe) Load(path string) error {
|
||||
|
||||
r.SourcePath = append(r.SourcePath, path)
|
||||
|
||||
c, err := template.FilesInDir(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 {
|
||||
for _, p := range r.fileParsers {
|
||||
if err := p(path, currentpath, info.Name(), []string{}, r.Database); err != nil {
|
||||
if err := p(path, currentpath, info.Name(), c, r.Database); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
err := filepath.Walk(path, ff)
|
||||
err = filepath.Walk(path, ff)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -36,10 +36,7 @@ import (
|
||||
|
||||
func NewGeneralRecipe(db types.PackageDatabase, fp ...FileParser) Builder {
|
||||
if len(fp) == 0 {
|
||||
fp = []FileParser{
|
||||
RuntimeCollectionParser,
|
||||
RuntimeDefinitionParser,
|
||||
}
|
||||
fp = DefaultInstallerParsers
|
||||
}
|
||||
return &Recipe{Database: db, fileParsers: fp}
|
||||
}
|
||||
|
Reference in New Issue
Block a user