diff --git a/tools/packaging/scripts/apply_patches.sh b/tools/packaging/scripts/apply_patches.sh new file mode 100755 index 0000000000..aa6b19b609 --- /dev/null +++ b/tools/packaging/scripts/apply_patches.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Copyright (c) 2020 Red Hat, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +# This script apply patches. +# +set -e + +script_dir="$(realpath $(dirname $0))" +patches_dir="$1" + +if [ -z "$patches_dir" ]; then + cat <<-EOT + Apply patches to the sources at the current directory. + + Patches are expected to be named in the standard git-format-patch(1) format where + the first part of the filename represents the patch ordering (lowest numbers + apply first): + 'NUMBER-DASHED_DESCRIPTION.patch' + + For example, + + 0001-fix-the-bad-thing.patch + 0002-improve-the-fix-the-bad-thing-fix.patch + 0003-correct-compiler-warnings.patch + + Usage: + $0 PATCHES_DIR + Where: + PATCHES_DIR is the directory containing the patches + EOT + exit 1 +fi + +echo "INFO: Apply patches from $patches_dir" +if [ -d "$patches_dir" ]; then + patches=($(find "$patches_dir" -name '*.patch'|sort -t- -k1,1n)) + echo "INFO: Found ${#patches[@]} patches" + for patch in ${patches[@]}; do + echo "INFO: Apply $patch" + git apply "$patch" || \ + { echo >&2 "ERROR: Not applied. Exiting..."; exit 1; } + done +else + echo "INFO: Patches directory does not exist" +fi diff --git a/tools/packaging/static-build/qemu-virtiofs/Dockerfile b/tools/packaging/static-build/qemu-virtiofs/Dockerfile index 380e9eb855..0caa064514 100644 --- a/tools/packaging/static-build/qemu-virtiofs/Dockerfile +++ b/tools/packaging/static-build/qemu-virtiofs/Dockerfile @@ -61,12 +61,10 @@ ADD static-build /root/static-build # Apply experimental specific patches # Patches to quick fix virtiofs fork ENV VIRTIOFS_PATCHES_DIR=/root/kata_qemu/patches/${QEMU_VIRTIOFS_TAG}/ -RUN if [ -d ${VIRTIOFS_PATCHES_DIR} ]; then \ - echo "Patches to apply for virtiofs fixes:"; \ - for patch in $(find "${VIRTIOFS_PATCHES_DIR}" -name '*.patch' -type f |sort -t- -k1,1n); do \ - git apply $patch; \ - done;fi -RUN /root/kata_qemu/apply_patches.sh +RUN /root/apply_patches.sh ${VIRTIOFS_PATCHES_DIR} +# Apply the stable branch patches +RUN stable_branch=$(cat VERSION | awk 'BEGIN{FS=OFS="."}{print $1 "." $2 ".x"}') && \ + /root/apply_patches.sh "/root/kata_qemu/patches/${stable_branch}" RUN PREFIX="${PREFIX}" /root/configure-hypervisor.sh -s kata-qemu | sed -e 's|--disable-seccomp||g' | xargs ./configure \ --with-pkgversion=kata-static diff --git a/tools/packaging/static-build/qemu/Dockerfile b/tools/packaging/static-build/qemu/Dockerfile index 26fc6c811c..502b9018ad 100644 --- a/tools/packaging/static-build/qemu/Dockerfile +++ b/tools/packaging/static-build/qemu/Dockerfile @@ -58,7 +58,8 @@ ADD qemu /root/kata_qemu ADD scripts/apply_patches.sh /root/apply_patches.sh ADD static-build /root/static-build -RUN /root/kata_qemu/apply_patches.sh +RUN stable_branch=$(cat VERSION | awk 'BEGIN{FS=OFS="."}{print $1 "." $2 ".x"}') && \ + /root/apply_patches.sh "/root/kata_qemu/patches/${stable_branch}" RUN PREFIX="${PREFIX}" /root/configure-hypervisor.sh -s kata-qemu | xargs ./configure \ --with-pkgversion=kata-static