Files
warewulf/internal/pkg/container/build.go
Jonathon Anderson a1832ad8c1 Complete transfer of Warewulf from HPCng
Warewulf is now being maintained in its own GitHub organization at
github.com/warewulf

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
2024-01-26 21:35:04 -07:00

51 lines
1.0 KiB
Go

package container
import (
"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 {
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 errors.Wrapf(err, "Failed creating directory: %s", imagePath)
}
}
err := util.BuildFsImage(
"VNFS container "+name,
rootfsPath,
imagePath,
[]string{"*"},
ignore,
// ignore cross-device files
true,
"newc")
return err
}