From e9a40cf4dbfa10b2e5236bdc0b2d48e3c5c89208 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 3 Jul 2023 17:11:47 -0400 Subject: [PATCH 1/2] USHIFT-1388: provide a tool for quickly rebuilding source images for scenario tests --- test/bin/build_images.sh | 34 ++++++++++++++--------- test/bin/rebuild_source_images.sh | 45 +++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 12 deletions(-) create mode 100755 test/bin/rebuild_source_images.sh diff --git a/test/bin/build_images.sh b/test/bin/build_images.sh index 85f2dad835..1cbd4a2bd5 100755 --- a/test/bin/build_images.sh +++ b/test/bin/build_images.sh @@ -10,6 +10,14 @@ source "${SCRIPTDIR}/common.sh" mkdir -p "${IMAGEDIR}" +if [ $# -ne 0 ]; then + TEMPLATES="$*" + BUILD_INSTALLER=false +else + TEMPLATES="${TESTDIR}/image-blueprints/*.toml" + BUILD_INSTALLER=true +fi + # Determine the version of the RPM in the local repo so we can use it # in the blueprint templates. if [ ! -d "${LOCAL_REPO}" ]; then @@ -66,7 +74,7 @@ BUILDIDS="" mkdir -p "${IMAGEDIR}/blueprints" mkdir -p "${IMAGEDIR}/builds" # shellcheck disable=SC2231 # allow glob expansion without quotes in for loop -for template in ${TESTDIR}/image-blueprints/*.toml; do +for template in ${TEMPLATES}; do echo echo "Blueprint ${template}" @@ -98,17 +106,19 @@ for template in ${TESTDIR}/image-blueprints/*.toml; do BUILDIDS="${BUILDIDS} ${buildid}" done -# In the future we may need to build multiple images with different -# formats but for now we just have one special case to build an -# installer image in a different format. -echo "Building image-installer from ${INSTALLER_IMAGE_BLUEPRINT}" -buildid=$(sudo composer-cli compose start \ - "${INSTALLER_IMAGE_BLUEPRINT}" \ - image-installer \ - | awk '{print $2}') -echo "Build ID ${buildid}" -echo "${buildid}" > "${IMAGEDIR}/builds/${blueprint}.image-installer" -BUILDIDS="${BUILDIDS} ${buildid}" +if ${BUILD_INSTALLER}; then + # In the future we may need to build multiple images with different + # formats but for now we just have one special case to build an + # installer image in a different format. + echo "Building image-installer from ${INSTALLER_IMAGE_BLUEPRINT}" + buildid=$(sudo composer-cli compose start \ + "${INSTALLER_IMAGE_BLUEPRINT}" \ + image-installer \ + | awk '{print $2}') + echo "Build ID ${buildid}" + echo "${buildid}" > "${IMAGEDIR}/builds/${blueprint}.image-installer" + BUILDIDS="${BUILDIDS} ${buildid}" +fi echo "Waiting for builds to complete..." # shellcheck disable=SC2086 # pass command arguments quotes to allow word splitting diff --git a/test/bin/rebuild_source_images.sh b/test/bin/rebuild_source_images.sh new file mode 100755 index 0000000000..f343909be4 --- /dev/null +++ b/test/bin/rebuild_source_images.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# +# This script should be run on the image build server (usually the +# same as the hypervisor). + +set -euo pipefail + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "${SCRIPTDIR}/common.sh" + +# Rebuild the RPM from source +cd "${ROOTDIR}" +rm -rf _output/rpmbuild +make rpm + +cd "${TESTDIR}" + +# Update the local repository +"./bin/create_local_repo.sh" + +# Given a blueprint filename, extract the name value. It does not have +# to match the filename, but some commands take the file and others +# take the name, so we need to be able to have both. +get_blueprint_name() { + local filename="${1}" + tomcli-get "${filename}" name +} + +TO_BUILD="" + +# shellcheck disable=SC2231 # allow glob expansion without quotes in for loop +for template in ${TESTDIR}/image-blueprints/*.toml; do + name=$(get_blueprint_name "${template}") + if [[ "${name}" =~ source ]]; then + TO_BUILD="${TO_BUILD} ${template}" + fi +done + +# shellcheck disable=SC2086 # pass command arguments quotes to allow word splitting +./bin/build_images.sh ${TO_BUILD} + +# Downloading the images again assumes that all of them are still in +# the composer cache. The logic for building the ostree repo does not +# currently cope with replacing content or updating individual images. +./bin/download_images.sh From e626ef7f391763abd1e2ef3c22a1e7d43e6a8391 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 6 Jul 2023 17:28:43 -0400 Subject: [PATCH 2/2] USHIFT-1388: add a script to prepare a local host by building all of the needed images --- test/bin/setup_local.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 test/bin/setup_local.sh diff --git a/test/bin/setup_local.sh b/test/bin/setup_local.sh new file mode 100755 index 0000000000..0f0a9f1a41 --- /dev/null +++ b/test/bin/setup_local.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# This script runs on the hypervisor, from the iso-build step. + +set -euo pipefail + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "${SCRIPTDIR}/common.sh" + +# Log output automatically +LOGDIR="${ROOTDIR}/_output/ci-logs" +LOGFILE="${LOGDIR}/$(basename "$0" .sh).log" +if [ ! -d "${LOGDIR}" ]; then + mkdir -p "${LOGDIR}" +fi +echo "Logging to ${LOGFILE}" +# Set fd 1 and 2 to write to the log file +exec &> >(tee >(awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush() }' >"${LOGFILE}")) + +(cd .. && make rpm) + +cd "${TESTDIR}" + +./bin/ci_phase_iso_build.sh + +# Start the web server to host the kickstart files and ostree commit +# repository. +./bin/start_webserver.sh + +echo "Set up complete. Run the scenarios you want by hand, then run" +echo "./bin/manage_vm_connections.sh local"