From 013f80e381cd01c284694ceb41675878858d3fd8 Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Mon, 26 Oct 2020 14:31:31 +0100 Subject: [PATCH] Provide a way to apply upstream patches to the image This change allows users to apply patches to the images during build time directly from gerrit using the new arg PATCH. At the moment, it's limited to upstream projects with patches on gerrit; future changes will allow different sources, including local directories. --- Dockerfile | 5 +++-- README.md | 12 ++++++++++++ patch-image.sh | 29 +++++++++++++++++++++++++++++ prepare-image.sh | 4 ++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100755 patch-image.sh diff --git a/Dockerfile b/Dockerfile index b59ec3a99..a9bebeba3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,9 +32,10 @@ RUN if [ $(uname -m) = "x86_64" ]; then \ FROM docker.io/centos:centos8 ARG PKGS_LIST=main-packages-list.txt +ARG PATCH_LIST -COPY ${PKGS_LIST} /tmp/main-packages-list.txt -COPY prepare-image.sh /bin/ +COPY ${PKGS_LIST} ${PATCH_LIST} /tmp/ +COPY prepare-image.sh patch-image.sh /bin/ RUN prepare-image.sh && \ rm -f /bin/prepare-image.sh diff --git a/README.md b/README.md index a116b3a7c..e3d9c4c66 100644 --- a/README.md +++ b/README.md @@ -43,3 +43,15 @@ The ironic configuration can be overridden by various environment variables. The - OS_CONDUCTOR__INSPECT_TIMEOUT=1800 - timeout (seconds) for waiting for node inspection - OS_CONDUCTOR__CLEAN_CALLBACK_TIMEOUT=1800 - timeout (seconds) to wait for a callback from the ramdisk doing the cleaning - OS_PXE__BOOT_RETRY_TIMEOUT=1200 - timeout (seconds) to enable boot retries. + +Applying Patches to the image +----------------------------- + +When building the image, it is possible to specify a patch of one or more +upstream projects to apply to the image, passing a file with the patch list +using the PATCH_LIST build argument. + +Each line of the file is in the form "project_dir refspec" where: +- project is the last part of the project url including the org, for example openstack/ironic +- refspec is the gerrit refspec of the patch we want to test, for example refs/changes/67/759567/1 + diff --git a/patch-image.sh b/patch-image.sh new file mode 100755 index 000000000..1766fc0aa --- /dev/null +++ b/patch-image.sh @@ -0,0 +1,29 @@ +#!/usr/bin/bash +set -ex + +patch_file="/tmp/${PATCH_LIST}" + +while IFS= read -r line +do + # each line is in the form "project_dir refsspec" where: + # - project is the last part of the project url including the org, + # for example openstack/ironic + # - refspec is the gerrit refspec of the patch we want to test, + # for example refs/changes/67/759567/1 + PROJECT=$(echo $line | cut -d " " -f1) + PROJ_NAME=$(echo $PROJECT | cut -d "/" -f2) + PROJ_URL="https://opendev.org/$PROJECT" + REFSPEC=$(echo $line | cut -d " " -f2) + + cd /tmp + git clone "$PROJ_URL" + cd "$PROJ_NAME" + git fetch "$PROJ_URL" "$REFSPEC" + git checkout FETCH_HEAD + + SKIP_GENERATE_AUTHORS=1 SKIP_WRITE_GIT_CHANGELOG=1 python3 setup.py sdist + pip3 install dist/*.tar.gz +done < "$patch_file" + +cd / + diff --git a/prepare-image.sh b/prepare-image.sh index 25bd59aa8..089ff992d 100755 --- a/prepare-image.sh +++ b/prepare-image.sh @@ -8,3 +8,7 @@ dnf upgrade -y dnf --setopt=install_weak_deps=False install -y $(cat /tmp/main-packages-list.txt) dnf clean all rm -rf /var/cache/{yum,dnf}/* +if [ -s "/tmp/${PATCH_LIST}" ]; then + /bin/patch-image.sh; +fi +rm -f /bin/patch-image.sh