Files
warewulf/internal/pkg/container/build.go
Carter Dodd 379faad51d Refactor of server, logging, building of images, template updates
* Combine provision response handling, add hwaddr and interface to dhcp
* Simplify stage cases, add backward compatible uri parse
* Move control of image compression to client
* Fix kernel search path for ubuntu, buffer template generation
* Implement cpio and gz as functions, add log named functions
* Generalize fs image creation routine
* Combine daemonLogf to generalized wwlog
* Fix template newline insertion, update dhcp and hosts tmpl
* Update IPXE template to handle non-compressed files
* Update DHCP template to set network interfaces and server IP assignment
* Update DHCP/hosts templates to choose a host-name self-consistently
2022-05-13 16:52:59 -05:00

58 lines
1.1 KiB
Go

package container
import (
"path"
"strings"
"github.com/pkg/errors"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/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
}
}
excludes_file := path.Join(rootfsPath, "./etc/warewulf/excludes")
ignore := []string{}
if util.IsFile(excludes_file) {
ignore, err := util.ReadFile(excludes_file)
if err != nil {
return errors.Wrapf(err, "Failed creating directory: %s", imagePath)
}
for i, pattern := range ignore {
if ( strings.HasPrefix(pattern, "/") ) {
ignore[i] = pattern[1:]
}
}
}
err := util.BuildFsImage(
"VNFS container " + name,
rootfsPath,
imagePath,
[]string{"*"},
ignore,
// ignore cross-device files
true,
"newc")
return err
}