diskimage-builder/diskimage_builder/elements/centos/root.d/10-centos-cloud-image
Ian Wienand 5bc9e87da1 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
2022-04-26 17:28:00 +10:00

71 lines
2.5 KiB
Bash
Executable file

#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
[ -n "$ARCH" ]
[ -n "$TARGET_ROOT" ]
if [[ "${DIB_RELEASE}" = 7 ]]; then
if [[ "amd64 x86_64" =~ "$ARCH" ]]; then
ARCH="x86_64"
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-https://cloud.centos.org/centos/${DIB_RELEASE}/images}
elif [[ "arm64 aarch64" =~ "$ARCH" ]]; then
ARCH="aarch64"
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-https://cloud.centos.org/altarch/${DIB_RELEASE}/images/aarch64}
elif [[ "ppc64le" =~ "$ARCH" ]]; then
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-https://cloud.centos.org/altarch/${DIB_RELEASE}/images/ppc64le}
else
echo 'centos root element only support the x86_64, aarch64 and ppc64le values for $ARCH'
exit 1
fi
else
if [[ "amd64 x86_64 arm64 aarch64 ppc64le" =~ "$ARCH" ]]; then
if [[ "amd64" =~ "$ARCH" ]]; then
ARCH="x86_64"
elif [[ "arm64" =~ "$ARCH" ]]; then
ARCH="aarch64"
fi
if [[ "${DIB_RELEASE}" == "9" ]]; then
dib_release_path=9-stream
else
dib_release_path=${DIB_RELEASE}
fi
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-https://cloud.centos.org/centos/${dib_release_path}/${ARCH}/images}
else
echo 'centos root element only support the x86_64, aarch64 and ppc64le values for $ARCH'
exit 1
fi
fi
DIB_LOCAL_IMAGE=${DIB_LOCAL_IMAGE:-}
if [ -n "$DIB_LOCAL_IMAGE" ]; then
IMAGE_LOCATION=$DIB_LOCAL_IMAGE
# No need to copy a local image into the cache directory, so just specify
# the cached path as the original path.
CACHED_IMAGE=$IMAGE_LOCATION
BASE_IMAGE_FILE=$(basename $DIB_LOCAL_IMAGE)
BASE_IMAGE_TAR=$BASE_IMAGE_FILE.tgz
else
DIB_FLAVOR=${DIB_FLAVOR:-GenericCloud}
if [[ "${DIB_RELEASE}" = 7 ]]; then
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-CentOS-${DIB_RELEASE}-${ARCH}-${DIB_FLAVOR}.qcow2.xz}
else
if [[ "${DIB_RELEASE}" == "9" ]]; then
dib_release_path=9-stream
else
dib_release_path=${DIB_RELEASE}
fi
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
CACHED_IMAGE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
fi
$TMP_HOOKS_PATH/bin/extract-image $BASE_IMAGE_FILE $BASE_IMAGE_TAR $IMAGE_LOCATION $CACHED_IMAGE