[gce] Use pigz if available to compress fx disk image
fx gce create-fuchsia-image constructs a fuchsia disk image suitable
for GCE; the image is a raw disk image inside a gzipped tarball.
One of the slower steps of constructing the disk image is gzipping
the tarball; use pigz (parallel gzip) if available to save time.
On a Xeon 'Skylake' 24 vCPU GCE instance, reduces the time for
compression in create-fuchsia-image from 2 min to 9 seconds.
Change-Id: Ic880890737f6af585f6e91406655097cd79dbab6
diff --git a/gce/create-fuchsia-image.sh b/gce/create-fuchsia-image.sh
index 6416dc2..94b3bcd 100755
--- a/gce/create-fuchsia-image.sh
+++ b/gce/create-fuchsia-image.sh
@@ -21,7 +21,12 @@
cd "$tmp"
mv "$diskimage" disk.raw
-tar -Sczf "$FUCHSIA_OUT_DIR/$FUCHSIA_GCE_IMAGE.tar.gz" disk.raw
+tar -Scf "$FUCHSIA_OUT_DIR/$FUCHSIA_GCE_IMAGE.tar" disk.raw
+if [ -x "$(command -v pigz)" ]; then
+ pigz -f "$FUCHSIA_OUT_DIR/$FUCHSIA_GCE_IMAGE.tar"
+else
+ gzip -f "$FUCHSIA_OUT_DIR/$FUCHSIA_GCE_IMAGE.tar"
+fi
gsutil cp "$FUCHSIA_OUT_DIR/$FUCHSIA_GCE_IMAGE.tar.gz" "gs://$FUCHSIA_GCE_PROJECT/$FUCHSIA_GCE_USER/$FUCHSIA_GCE_IMAGE.tar.gz"
gcloud -q compute images delete "$FUCHSIA_GCE_IMAGE"
gcloud -q compute images create "$FUCHSIA_GCE_IMAGE" --source-uri "gs://$FUCHSIA_GCE_PROJECT/$FUCHSIA_GCE_USER/$FUCHSIA_GCE_IMAGE.tar.gz" --guest-os-features=UEFI_COMPATIBLE