From 5bc9e87da1165692562eecb3b4ffd698bf7f1ce7 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 26 Apr 2022 17:22:46 +1000 Subject: [PATCH] centos: avoid head pipe failure I just saw in the trace output of a failure > grep -o 'CentOS-.[^>]*GenericCloud-.[^>]*.qcow2' > sort -r > head -1 sort: fflush failed: 'standard output': Broken pipe sort: write error i.e. the "head -1" has exited after reading one line, but "sort -r" still wants to write and thus has hit a pipe failure, and because we run with "-o pipefail" this has halted the script. This seems like it has been there more or less forever, maybe we just got lucky hitting it now? Anyway, we can work around this by using a process substitution and passing the output of this into head, this way we won't hit a pipe failure. I also updated the fedora path as it does the same thing. Change-Id: I44d97e5bb31702aacf396e0229329a2ef9c64f2f --- diskimage_builder/elements/centos/root.d/10-centos-cloud-image | 2 +- diskimage_builder/elements/fedora/root.d/10-fedora-cloud-image | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/diskimage_builder/elements/centos/root.d/10-centos-cloud-image b/diskimage_builder/elements/centos/root.d/10-centos-cloud-image index de79e4d9..d2529046 100755 --- a/diskimage_builder/elements/centos/root.d/10-centos-cloud-image +++ b/diskimage_builder/elements/centos/root.d/10-centos-cloud-image @@ -61,7 +61,7 @@ else else dib_release_path=${DIB_RELEASE} fi - BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$(curl -s https://cloud.centos.org/centos/${dib_release_path}/${ARCH}/images/ | grep -o "CentOS-.[^>]*${DIB_FLAVOR}-.[^>]*.qcow2" | sort -r | head -1)} + BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$(head -1 < <(curl -s https://cloud.centos.org/centos/${dib_release_path}/${ARCH}/images/ | grep -o "CentOS-.[^>]*${DIB_FLAVOR}-.[^>]*.qcow2" | sort -r))} fi BASE_IMAGE_TAR=$BASE_IMAGE_FILE.tgz IMAGE_LOCATION=$DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE diff --git a/diskimage_builder/elements/fedora/root.d/10-fedora-cloud-image b/diskimage_builder/elements/fedora/root.d/10-fedora-cloud-image index 38793674..f3eb7bb1 100755 --- a/diskimage_builder/elements/fedora/root.d/10-fedora-cloud-image +++ b/diskimage_builder/elements/fedora/root.d/10-fedora-cloud-image @@ -44,7 +44,7 @@ else exit 1 ;; esac - SUBRELEASE=$(curl -Ls $DIB_CLOUD_IMAGES/ | grep -o -P '(?<=Fedora-Cloud-Base-'${DIB_RELEASE}'-).*?(?=.'${ARCH}'.qcow2")' | sort -r | head -1) + SUBRELEASE=$(head -1 < <(curl -Ls $DIB_CLOUD_IMAGES/ | grep -o -P '(?<=Fedora-Cloud-Base-'${DIB_RELEASE}'-).*?(?=.'${ARCH}'.qcow2")' | sort -r)) BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-Fedora-Cloud-Base-$DIB_RELEASE-$SUBRELEASE.$ARCH.qcow2} BASE_IMAGE_TAR=Fedora-Cloud-Base-$DIB_RELEASE-$SUBRELEASE.$ARCH.tgz IMAGE_LOCATION=$DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE