From 4732868966809b9b7e9f27a1d71fd4df7f4b347d Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Sun, 25 Apr 2021 12:25:34 -0700 Subject: [PATCH] Slight modification to Yong's `pigz` conditional --- internal/pkg/container/build.go | 16 ++++++++++------ internal/pkg/kernel/kernel.go | 14 +++++++++----- internal/pkg/overlay/overlay.go | 14 +++++++++----- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/internal/pkg/container/build.go b/internal/pkg/container/build.go index a1b8a200..8f60a7b0 100644 --- a/internal/pkg/container/build.go +++ b/internal/pkg/container/build.go @@ -40,13 +40,17 @@ func Build(name string, buildForce bool) error { return errors.New("Failed creating directory") } - 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) - // use pigz if available - err = exec.Command("/bin/sh", "-c", "command -v pigz").Run() - if err == nil { - cmd = fmt.Sprintf("cd %s; find . | cpio --quiet -o -H newc | pigz -c > \"%s\"", rootfsPath, imagePath) + compressor, err := exec.LookPath("pigz") + if err != nil { + wwlog.Printf(wwlog.VERBOSE, "Could not locate PIGZ, using GZIP\n") + compressor = "gzip" + } else { + wwlog.Printf(wwlog.VERBOSE, "Using PIGZ to compress the container: %s\n", compressor) } + + wwlog.Printf(wwlog.DEBUG, "Building VNFS image: '%s' -> '%s'\n", rootfsPath, imagePath) + cmd := fmt.Sprintf("cd %s; find . | cpio --quiet -o -H newc | %s -c > \"%s\"", rootfsPath, compressor, imagePath) + wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd) err = exec.Command("/bin/sh", "-c", cmd).Run() if err != nil { diff --git a/internal/pkg/kernel/kernel.go b/internal/pkg/kernel/kernel.go index 2fa8387e..961041c4 100644 --- a/internal/pkg/kernel/kernel.go +++ b/internal/pkg/kernel/kernel.go @@ -99,12 +99,16 @@ func Build(kernelVersion string, root string) (string, error) { wwlog.Printf(wwlog.VERBOSE, "Building Kernel driver image\n") if _, err := os.Stat(kernelDrivers); err == nil { - cmd := fmt.Sprintf("cd /; find .%s | cpio --quiet -o -H newc | gzip -c > \"%s\"", kernelDrivers, driversDestination) - // use pigz if available - err := exec.Command("/bin/sh", "-c", "command -v pigz").Run() - if err == nil { - cmd = fmt.Sprintf("cd /; find .%s | cpio --quiet -o -H newc | pigz -c > \"%s\"", kernelDrivers, driversDestination) + compressor, err := exec.LookPath("pigz") + if err != nil { + wwlog.Printf(wwlog.VERBOSE, "Could not locate PIGZ, using GZIP\n") + compressor = "gzip" + } else { + wwlog.Printf(wwlog.VERBOSE, "Using PIGZ to compress the container: %s\n", compressor) } + + cmd := fmt.Sprintf("cd /; find .%s | cpio --quiet -o -H newc | %s -c > \"%s\"", kernelDrivers, compressor, driversDestination) + wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd) err = exec.Command("/bin/sh", "-c", cmd).Run() if err != nil { diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index eb29f043..cbeb072c 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -254,12 +254,16 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error { wwlog.Printf(wwlog.VERBOSE, "Finished generating overlay directory for: %s\n", n.Id.Get()) - cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc | gzip -c > \"%s\"", tmpDir, OverlayFile) - // use pigz if available - err = exec.Command("/bin/sh", "-c", "command -v pigz").Run() - if err == nil { - cmd = fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc | pigz -c > \"%s\"", tmpDir, OverlayFile) + compressor, err := exec.LookPath("pigz") + if err != nil { + wwlog.Printf(wwlog.VERBOSE, "Could not locate PIGZ, using GZIP\n") + compressor = "gzip" + } else { + wwlog.Printf(wwlog.VERBOSE, "Using PIGZ to compress the container: %s\n", compressor) } + + cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc | %s -c > \"%s\"", tmpDir, compressor, OverlayFile) + wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd) err = exec.Command("/bin/sh", "-c", cmd).Run() if err != nil {