Files
warewulf/internal/pkg/image/build.go
Jonathon Anderson c2cfe513d7 Remove remaining gRPC references with additional tests
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
2026-03-23 06:54:44 -06:00

51 lines
1.0 KiB
Go

package image
import (
"fmt"
"path"
"github.com/warewulf/warewulf/internal/pkg/util"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
func Build(name string, buildForce bool) error {
wwlog.Info("Building image: %s", name)
rootfsPath := RootFsDir(name)
imagePath := ImageFile(name)
if !ValidSource(name) {
return fmt.Errorf("image does not exist: %s", name)
}
if !buildForce {
wwlog.Debug("Checking if there have been any updates to the image source directory")
if util.PathIsNewer(rootfsPath, imagePath) {
wwlog.Info("Skipping (Image 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 reading excludes file: %s: %w", excludes_file, err)
}
}
err := util.BuildFsImage(
"Image "+name,
rootfsPath,
imagePath,
[]string{"*"},
ignore,
// ignore cross-device files
true,
"newc")
return err
}