Cleanups and minor fixups
This commit is contained in:
@@ -2,6 +2,7 @@ package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/errors"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"os"
|
||||
@@ -9,46 +10,40 @@ import (
|
||||
"path"
|
||||
)
|
||||
|
||||
func Build(name string, buildForce bool) {
|
||||
func Build(name string, buildForce bool) (string, error) {
|
||||
|
||||
rootfsPath := RootFsDir(name)
|
||||
imagePath := ImageFile(name)
|
||||
|
||||
if ValidSource(name) == false {
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Skipping (bad path)\n", name)
|
||||
return
|
||||
return "", errors.New("Container does not exist")
|
||||
}
|
||||
|
||||
if buildForce == false {
|
||||
wwlog.Printf(wwlog.DEBUG, "Checking if there have been any updates to the VNFS directory\n")
|
||||
if util.PathIsNewer(rootfsPath, imagePath) {
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, VNFS is current\n", name)
|
||||
return
|
||||
return "Skipping (VNFS is current)", nil
|
||||
}
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Making parent directory for: %s\n", name)
|
||||
err := os.MkdirAll(path.Dir(imagePath), 0755)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
return "Failed creating directory", err
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Making parent directory for: %s\n", rootfsPath)
|
||||
err = os.MkdirAll(path.Dir(rootfsPath), 0755)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
return "Failed creating directory", err
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Building VNFS image: '%s' -> '%s'\n", rootfsPath, imagePath)
|
||||
cmd := fmt.Sprintf("cd %s; find . | cpio --quiet -o -H newc | gzip -c > \"%s\"", rootfsPath, imagePath)
|
||||
err = exec.Command("/bin/sh", "-c", cmd).Run()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Failed building VNFS: %s\n", err)
|
||||
return
|
||||
return "Failed building VNFS", err
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", name)
|
||||
|
||||
return "Done", nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user