Files
warewulf/internal/pkg/container/build.go
Christian Goll 0dd0317740 replaced errors.Wrap with fmt.Errorf
Signed-off-by: Christian Goll <cgoll@suse.com>
2024-11-07 22:57:29 -07:00

53 lines
1.1 KiB
Go

package container
import (
"fmt"
"path"
"github.com/pkg/errors"
"github.com/warewulf/warewulf/internal/pkg/util"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
func Build(name string, buildForce bool) error {
wwlog.Info("Building container: %s", name)
rootfsPath := RootFsDir(name)
imagePath := ImageFile(name)
if !ValidSource(name) {
return errors.Errorf("Container does not exist: %s", name)
}
if !buildForce {
wwlog.Debug("Checking if there have been any updates to the VNFS directory")
if util.PathIsNewer(rootfsPath, imagePath) {
wwlog.Info("Skipping (VNFS is current)")
return nil
}
}
ignore := []string{}
excludes_file := path.Join(rootfsPath, "./etc/warewulf/excludes")
if util.IsFile(excludes_file) {
var err error
ignore, err = util.ReadFile(excludes_file)
if err != nil {
return fmt.Errorf("Failed creating directory: %s: %w", imagePath, err)
}
}
err := util.BuildFsImage(
"VNFS container "+name,
rootfsPath,
imagePath,
[]string{"*"},
ignore,
// ignore cross-device files
true,
"newc")
return err
}