From 4a0fd6c24ec39e83c08cfbc289ab01d652eeaa99 Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Tue, 22 Sep 2020 17:24:22 -0400 Subject: [PATCH] packaging/qemu: Add common code to apply patches The qemu and qemu-virtiofs Dockerfile files repeat the code to apply patches based on QEMU stable branch being built. Instead, this adds a common script (qemu/apply_patches.sh) and make it called by the respective Dockerfile files. Signed-off-by: Wainer dos Santos Moschetta --- tools/packaging/qemu/apply_patches.sh | 27 +++++++++++++++++++ .../static-build/qemu-virtiofs/Dockerfile | 13 +++------ tools/packaging/static-build/qemu/Dockerfile | 10 ++----- 3 files changed, 32 insertions(+), 18 deletions(-) create mode 100755 tools/packaging/qemu/apply_patches.sh diff --git a/tools/packaging/qemu/apply_patches.sh b/tools/packaging/qemu/apply_patches.sh new file mode 100755 index 0000000000..6cd0ef18c2 --- /dev/null +++ b/tools/packaging/qemu/apply_patches.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Copyright (c) 2020 Red Hat, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +# This script apply the needed for Kata Containers patches on QEMU. +# Note: It should be executed from inside the QEMU source directory. +# +set -e + +script_dir="$(realpath $(dirname $0))" + +qemu_version="$(cat VERSION)" +stable_branch=$(echo $qemu_version | \ + awk 'BEGIN{FS=OFS="."}{print $1 "." $2 ".x"}') +patches_dir="${script_dir}/patches/${stable_branch}" + +echo "Handle patches for QEMU $qemu_version (stable ${stable_branch})" +if [ -d $patches_dir ]; then + for patch in $(find $patches_dir -name '*.patch'); do + echo "Apply $patch" + git apply "$patch" + done +else + echo "No patches to apply" +fi diff --git a/tools/packaging/static-build/qemu-virtiofs/Dockerfile b/tools/packaging/static-build/qemu-virtiofs/Dockerfile index 399df608cc..d916a1140e 100644 --- a/tools/packaging/static-build/qemu-virtiofs/Dockerfile +++ b/tools/packaging/static-build/qemu-virtiofs/Dockerfile @@ -49,23 +49,16 @@ RUN cd .. && git clone "${QEMU_VIRTIOFS_REPO}" qemu-virtiofs RUN git checkout "${QEMU_VIRTIOFS_TAG}" ADD scripts/configure-hypervisor.sh /root/configure-hypervisor.sh -ADD qemu/patches/ /root/kata_qemu_patches +ADD qemu /root/kata_qemu # Apply experimental specific patches # Patches to quick fix virtiofs fork -ENV VIRTIOFS_PATCHES_DIR=/root/kata_qemu_patches/${QEMU_VIRTIOFS_TAG}/ +ENV VIRTIOFS_PATCHES_DIR=/root/kata_qemu/patches/${QEMU_VIRTIOFS_TAG}/ RUN find "${VIRTIOFS_PATCHES_DIR}" -name '*.patch' -type f |sort -t- -k1,1n > patches_virtiofs RUN echo "Patches to apply for virtiofs fixes:" RUN cat patches_virtiofs RUN [ ! -s patches_virtiofs ] || git apply $(cat patches_virtiofs) - -RUN cat VERSION | awk 'BEGIN{FS=OFS="."}{print $1 "." $2 ".x"}' > stable_branch -RUN echo "/root/kata_qemu_patches/$(cat stable_branch)/" > patches_qemu_dir -RUN echo "patches dir $(cat patches_qemu_dir)" -RUN find "$(cat patches_qemu_dir)" -name '*.patch' -type f |sort -t- -k1,1n > patches_qemu -RUN echo "Patches to apply for qemu:" -RUN cat patches_qemu -RUN [ ! -s patches_qemu ] || git apply $(cat patches_qemu ) +RUN /root/kata_qemu/apply_patches.sh 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 7608bd9681..4296e5e053 100644 --- a/tools/packaging/static-build/qemu/Dockerfile +++ b/tools/packaging/static-build/qemu/Dockerfile @@ -48,15 +48,9 @@ RUN git clone https://github.com/qemu/capstone.git capstone RUN git clone https://github.com/qemu/keycodemapdb.git ui/keycodemapdb ADD scripts/configure-hypervisor.sh /root/configure-hypervisor.sh -ADD qemu/patches/ /root/kata_qemu_patches +ADD qemu /root/kata_qemu -RUN \ - cat VERSION; \ - stable_branch=$(cat VERSION | awk 'BEGIN{FS=OFS="."}{print $1 "." $2 ".x"}');\ - for patch in $(find /root/kata_qemu_patches/${stable_branch}/ -name '*.patch'); do\ - echo "apply $patch";\ - git apply "$patch"; \ - done +RUN /root/kata_qemu/apply_patches.sh RUN PREFIX="${PREFIX}" /root/configure-hypervisor.sh -s kata-qemu | xargs ./configure \ --with-pkgversion=kata-static