From 8226384cf071719ccc011864f860ee3919af9a9a Mon Sep 17 00:00:00 2001 From: Carlos Goncalves Date: Tue, 24 Sep 2019 12:46:12 +0200 Subject: [PATCH] Add CentOS 8 support * Add "centos" element, a CentOS version-independent element. This is in line with the same work done for RHEL in Stein cycle. * Deprecate the centos7 element. CentOS 7 support itself it not deprecated though. The new "centos" element provides the same support level as the "centos7" element. * Add functional testing The default CentOS version is 8. You can adjust it using the DIB_RELEASE environment variable. Change-Id: I373ba2296c4613765676e59aabd9c651345298d1 --- .zuul.d/jobs.yaml | 1 + diskimage_builder/elements/centos/README.rst | 26 ++++++++ .../elements/centos/element-deps | 5 ++ .../{centos7 => centos}/element-provides | 0 .../environment.d/10-centos-distro-name.bash | 2 + .../centos/environment.d/11-yum-dnf.bash | 7 +++ .../centos/pre-install.d/01-set-centos-mirror | 23 +++++++ .../centos/pre-install.d/02-set-machine-id | 23 +++++++ .../centos/root.d/10-centos-cloud-image | 62 +++++++++++++++++++ .../test-elements/8-build-succeeds/README.rst | 1 + .../8-build-succeeds/element-deps | 3 + .../environment.d/10-set-distro.bash | 1 + .../8-build-succeeds/test-output-formats | 1 + diskimage_builder/elements/centos7/README.rst | 7 +++ .../elements/centos7/element-deps | 6 +- .../00-centos7-element-deprecation.bash | 1 + .../environment.d/09-centos7-distro-name.bash | 7 +++ .../pre-install.d/01-set-centos-mirror | 15 ----- .../centos7/root.d/10-centos7-cloud-image | 42 ------------- ...add-centos-8-support-4fd28eb04e11ba43.yaml | 8 +++ 20 files changed, 179 insertions(+), 62 deletions(-) create mode 100644 diskimage_builder/elements/centos/README.rst create mode 100644 diskimage_builder/elements/centos/element-deps rename diskimage_builder/elements/{centos7 => centos}/element-provides (100%) create mode 100644 diskimage_builder/elements/centos/environment.d/10-centos-distro-name.bash create mode 100644 diskimage_builder/elements/centos/environment.d/11-yum-dnf.bash create mode 100755 diskimage_builder/elements/centos/pre-install.d/01-set-centos-mirror create mode 100755 diskimage_builder/elements/centos/pre-install.d/02-set-machine-id create mode 100755 diskimage_builder/elements/centos/root.d/10-centos-cloud-image create mode 100644 diskimage_builder/elements/centos/test-elements/8-build-succeeds/README.rst create mode 100644 diskimage_builder/elements/centos/test-elements/8-build-succeeds/element-deps create mode 100644 diskimage_builder/elements/centos/test-elements/8-build-succeeds/environment.d/10-set-distro.bash create mode 100644 diskimage_builder/elements/centos/test-elements/8-build-succeeds/test-output-formats create mode 100644 diskimage_builder/elements/centos7/environment.d/00-centos7-element-deprecation.bash create mode 100644 diskimage_builder/elements/centos7/environment.d/09-centos7-distro-name.bash delete mode 100755 diskimage_builder/elements/centos7/pre-install.d/01-set-centos-mirror delete mode 100755 diskimage_builder/elements/centos7/root.d/10-centos7-cloud-image create mode 100644 releasenotes/notes/add-centos-8-support-4fd28eb04e11ba43.yaml diff --git a/.zuul.d/jobs.yaml b/.zuul.d/jobs.yaml index e5ce73c0..bbd0b7ac 100644 --- a/.zuul.d/jobs.yaml +++ b/.zuul.d/jobs.yaml @@ -42,6 +42,7 @@ vars: dib_functests: - centos7/build-succeeds + - centos/8-build-succeeds - opensuse/build-succeeds - opensuse/opensuse15-build-succeeds - fedora/build-succeeds diff --git a/diskimage_builder/elements/centos/README.rst b/diskimage_builder/elements/centos/README.rst new file mode 100644 index 00000000..687bc533 --- /dev/null +++ b/diskimage_builder/elements/centos/README.rst @@ -0,0 +1,26 @@ +====== +centos +====== + +Use CentOS cloud images as the baseline for built disk images. + +For further details see the redhat-common README. + +Environment Variables +--------------------- + +DIB_DISTRIBUTION_MIRROR: + :Required: No + :Default: None + :Description: To use a CentOS Yum mirror, set this variable to the mirror URL + before running bin/disk-image-create. This URL should point to + the directory containing the ``7/8`` directories. + :Example: ``DIB_DISTRIBUTION_MIRROR=http://amirror.com/centos`` + +DIB_CLOUD_IMAGES: + :Required: No + :Description: Set the desired URL to fetch the images from. ppc64le: + Currently the CentOS community is working on providing the + ppc64le images. Until then you'll need to set this to a local + image file. + :Example: ``DIB_CLOUD_IMAGES=/path/to/my/centos/8/CentOS-8-GenericCloud-x86_64.qcow2`` diff --git a/diskimage_builder/elements/centos/element-deps b/diskimage_builder/elements/centos/element-deps new file mode 100644 index 00000000..1bc6150a --- /dev/null +++ b/diskimage_builder/elements/centos/element-deps @@ -0,0 +1,5 @@ +cache-url +redhat-common +rpm-distro +source-repositories +yum diff --git a/diskimage_builder/elements/centos7/element-provides b/diskimage_builder/elements/centos/element-provides similarity index 100% rename from diskimage_builder/elements/centos7/element-provides rename to diskimage_builder/elements/centos/element-provides diff --git a/diskimage_builder/elements/centos/environment.d/10-centos-distro-name.bash b/diskimage_builder/elements/centos/environment.d/10-centos-distro-name.bash new file mode 100644 index 00000000..9864057d --- /dev/null +++ b/diskimage_builder/elements/centos/environment.d/10-centos-distro-name.bash @@ -0,0 +1,2 @@ +export DISTRO_NAME=centos +export DIB_RELEASE=${DIB_RELEASE:-8} diff --git a/diskimage_builder/elements/centos/environment.d/11-yum-dnf.bash b/diskimage_builder/elements/centos/environment.d/11-yum-dnf.bash new file mode 100644 index 00000000..f14bdc3b --- /dev/null +++ b/diskimage_builder/elements/centos/environment.d/11-yum-dnf.bash @@ -0,0 +1,7 @@ +# since CentOS 8, dnf is the yum replacement. + +if [[ ${DIB_RELEASE} == '8' ]]; then + export YUM=dnf +elif [[ ${DIB_RELEASE} == '7' ]]; then + export YUM=yum +fi diff --git a/diskimage_builder/elements/centos/pre-install.d/01-set-centos-mirror b/diskimage_builder/elements/centos/pre-install.d/01-set-centos-mirror new file mode 100755 index 00000000..dffb1705 --- /dev/null +++ b/diskimage_builder/elements/centos/pre-install.d/01-set-centos-mirror @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +DIB_DISTRIBUTION_MIRROR=${DIB_DISTRIBUTION_MIRROR:-} + +[ -n "$DIB_DISTRIBUTION_MIRROR" ] || exit 0 + +# Only set the mirror for the Base, Extras and Updates repositories +# The others aren't enabled and do not exist on all mirrors +if [[ ${DIB_RELEASE} == '7' ]]; then + sed -e "s|^#baseurl=http[s]*://mirror.centos.org/centos|baseurl=$DIB_DISTRIBUTION_MIRROR|;/^mirrorlist=/d" -i /etc/yum.repos.d/CentOS-Base.repo +elif [[ ${DIB_RELEASE} == '8' ]]; then + sed -e "s|^#baseurl=http[s]*://mirror.centos.org/|baseurl=$DIB_DISTRIBUTION_MIRROR|;/^mirrorlist=/d" -i /etc/yum.repos.d/CentOS-Base.repo + sed -e "s|^#baseurl=http[s]*://mirror.centos.org/|baseurl=$DIB_DISTRIBUTION_MIRROR|;/^mirrorlist=/d" -i /etc/yum.repos.d/CentOS-AppStream.repo + sed -e "s|^#baseurl=http[s]*://mirror.centos.org/|baseurl=$DIB_DISTRIBUTION_MIRROR|;/^mirrorlist=/d" -i /etc/yum.repos.d/CentOS-centosplus.repo + sed -e "s|^#baseurl=http[s]*://mirror.centos.org/|baseurl=$DIB_DISTRIBUTION_MIRROR|;/^mirrorlist=/d" -i /etc/yum.repos.d/CentOS-Extras.repo + sed -e "s|^#baseurl=http[s]*://mirror.centos.org/|baseurl=$DIB_DISTRIBUTION_MIRROR|;/^mirrorlist=/d" -i /etc/yum.repos.d/CentOS-PowerTools.repo +fi diff --git a/diskimage_builder/elements/centos/pre-install.d/02-set-machine-id b/diskimage_builder/elements/centos/pre-install.d/02-set-machine-id new file mode 100755 index 00000000..76ef05a5 --- /dev/null +++ b/diskimage_builder/elements/centos/pre-install.d/02-set-machine-id @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +# Set a machine-id. The .qcow2 image doesn't have one, and sometimes +# one will get made (if systemd is upgraded as part of the build +# process) and sometimes not. The problem is that certain kernel +# install scripts bail silently without it; kernel packages end up +# being installed but the initramfs etc isn't copied into place. +# +# Note this is cleared out in the sysprep role. +# +# See also: +# 768c5e188c1b4bff01da14a49b96b51301db4c03 : similar thing for fedora +# https://bugzilla.redhat.com/show_bug.cgi?id=1737355 : upstream bug +# https://bugzilla.redhat.com/show_bug.cgi?id=1486124 : unresolved +# bug about kernel install requiring machine-id + +systemd-machine-id-setup diff --git a/diskimage_builder/elements/centos/root.d/10-centos-cloud-image b/diskimage_builder/elements/centos/root.d/10-centos-cloud-image new file mode 100755 index 00000000..19b8d04d --- /dev/null +++ b/diskimage_builder/elements/centos/root.d/10-centos-cloud-image @@ -0,0 +1,62 @@ +#!/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:-http://cloud.centos.org/centos/${DIB_RELEASE}/images} + elif [[ "arm64 aarch64" =~ "$ARCH" ]]; then + ARCH="aarch64" + DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud.centos.org/altarch/${DIB_RELEASE}/images/aarch64} + elif [[ "ppc64le" =~ "$ARCH" ]]; then + DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://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 + DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud.centos.org/centos/${DIB_RELEASE}/${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 + LATEST_IMAGE_FILE=$(curl -s https://cloud.centos.org/centos/${DIB_RELEASE}/${ARCH}/images/ | grep -o "CentOS-${DIB_RELEASE}-${DIB_FLAVOR}-.[^>]*.qcow2" | head -1) + BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$LATEST_IMAGE_FILE} + 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 diff --git a/diskimage_builder/elements/centos/test-elements/8-build-succeeds/README.rst b/diskimage_builder/elements/centos/test-elements/8-build-succeeds/README.rst new file mode 100644 index 00000000..88104d7d --- /dev/null +++ b/diskimage_builder/elements/centos/test-elements/8-build-succeeds/README.rst @@ -0,0 +1 @@ +Centos 8 test diff --git a/diskimage_builder/elements/centos/test-elements/8-build-succeeds/element-deps b/diskimage_builder/elements/centos/test-elements/8-build-succeeds/element-deps new file mode 100644 index 00000000..3a391e3e --- /dev/null +++ b/diskimage_builder/elements/centos/test-elements/8-build-succeeds/element-deps @@ -0,0 +1,3 @@ +base +epel +openstack-ci-mirrors diff --git a/diskimage_builder/elements/centos/test-elements/8-build-succeeds/environment.d/10-set-distro.bash b/diskimage_builder/elements/centos/test-elements/8-build-succeeds/environment.d/10-set-distro.bash new file mode 100644 index 00000000..d6c89677 --- /dev/null +++ b/diskimage_builder/elements/centos/test-elements/8-build-succeeds/environment.d/10-set-distro.bash @@ -0,0 +1 @@ +export DIB_RELEASE='8' diff --git a/diskimage_builder/elements/centos/test-elements/8-build-succeeds/test-output-formats b/diskimage_builder/elements/centos/test-elements/8-build-succeeds/test-output-formats new file mode 100644 index 00000000..7895a833 --- /dev/null +++ b/diskimage_builder/elements/centos/test-elements/8-build-succeeds/test-output-formats @@ -0,0 +1 @@ +qcow2 \ No newline at end of file diff --git a/diskimage_builder/elements/centos7/README.rst b/diskimage_builder/elements/centos7/README.rst index cfec0d04..1c896d2b 100644 --- a/diskimage_builder/elements/centos7/README.rst +++ b/diskimage_builder/elements/centos7/README.rst @@ -1,6 +1,13 @@ ======= centos7 ======= + +.. warning:: + + This element is deprecated and is left only for backward compatibility. + Use the `centos` element instead. Note that you should set DIB_RELEASE to 7 + to indicate which release you are using. Please read the notes. + Use CentOS 7 cloud images as the baseline for built disk images. For further details see the redhat-common README. diff --git a/diskimage_builder/elements/centos7/element-deps b/diskimage_builder/elements/centos7/element-deps index 1bc6150a..b813af90 100644 --- a/diskimage_builder/elements/centos7/element-deps +++ b/diskimage_builder/elements/centos7/element-deps @@ -1,5 +1 @@ -cache-url -redhat-common -rpm-distro -source-repositories -yum +centos diff --git a/diskimage_builder/elements/centos7/environment.d/00-centos7-element-deprecation.bash b/diskimage_builder/elements/centos7/environment.d/00-centos7-element-deprecation.bash new file mode 100644 index 00000000..8de1e776 --- /dev/null +++ b/diskimage_builder/elements/centos7/environment.d/00-centos7-element-deprecation.bash @@ -0,0 +1 @@ +echo "The centos7 element is deprecated and will be removed in future releases. Use the centos element instead." diff --git a/diskimage_builder/elements/centos7/environment.d/09-centos7-distro-name.bash b/diskimage_builder/elements/centos7/environment.d/09-centos7-distro-name.bash new file mode 100644 index 00000000..dc87ae51 --- /dev/null +++ b/diskimage_builder/elements/centos7/environment.d/09-centos7-distro-name.bash @@ -0,0 +1,7 @@ +# For backward compat (centos vs centos7) +export DIB_FLAVOR=${DIB_RELEASE:-GenericCloud} +export DIB_RELEASE=7 + +# Useful for elements that work with fedora (dnf) & centos +export YUM=${YUM:-yum} + diff --git a/diskimage_builder/elements/centos7/pre-install.d/01-set-centos-mirror b/diskimage_builder/elements/centos7/pre-install.d/01-set-centos-mirror deleted file mode 100755 index 8dd9b2d9..00000000 --- a/diskimage_builder/elements/centos7/pre-install.d/01-set-centos-mirror +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -DIB_DISTRIBUTION_MIRROR=${DIB_DISTRIBUTION_MIRROR:-} - -[ -n "$DIB_DISTRIBUTION_MIRROR" ] || exit 0 - -# Only set the mirror for the Base, Extras and Updates repositories -# The others arn't enabled and do not exist on all mirrors -sed -e "s|^#baseurl=http[s]*://mirror.centos.org/centos|baseurl=$DIB_DISTRIBUTION_MIRROR|;/^mirrorlist=/d" -i /etc/yum.repos.d/CentOS-Base.repo diff --git a/diskimage_builder/elements/centos7/root.d/10-centos7-cloud-image b/diskimage_builder/elements/centos7/root.d/10-centos7-cloud-image deleted file mode 100755 index 8b46afa4..00000000 --- a/diskimage_builder/elements/centos7/root.d/10-centos7-cloud-image +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -[ -n "$ARCH" ] -[ -n "$TARGET_ROOT" ] - -if [[ "amd64 x86_64" =~ "$ARCH" ]]; then - ARCH="x86_64" - DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud.centos.org/centos/7/images} -elif [[ "arm64 aarch64" =~ "$ARCH" ]]; then - ARCH="aarch64" - DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud.centos.org/altarch/7/images/aarch64} -elif [[ "ppc64le" =~ "$ARCH" ]]; then - DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud.centos.org/altarch/7/images/ppc64le} -else - echo 'centos7 root element only support the x86_64, aarch64 and ppc64le values for $ARCH' - exit 1 -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_CENTOS7_CLOUD_RELEASE=${DIB_CENTOS7_CLOUD_RELEASE:-GenericCloud} - BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-CentOS-7-${ARCH}-$DIB_CENTOS7_CLOUD_RELEASE.qcow2.xz} - 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 diff --git a/releasenotes/notes/add-centos-8-support-4fd28eb04e11ba43.yaml b/releasenotes/notes/add-centos-8-support-4fd28eb04e11ba43.yaml new file mode 100644 index 00000000..ed15044e --- /dev/null +++ b/releasenotes/notes/add-centos-8-support-4fd28eb04e11ba43.yaml @@ -0,0 +1,8 @@ +--- +features: + - Added CentOS 8 support. +deprecations: + - | + The ``centos7`` element is deprecated and is left only for backward + compatibility. Use the ``centos`` element instead. Note that you should set + ``DIB_RELEASE`` to ``7`` when using the ``centos`` element.