From b864e153ddac995cb111b583a9d9e0c58a567387 Mon Sep 17 00:00:00 2001 From: Don Penney Date: Tue, 21 Jan 2020 17:04:10 -0500 Subject: [PATCH] Support source patches for building images The build-stx-images.sh allows for building images using a git repo as the source, which is cloned into the workspace as part of the build procedure. In some cases, there may be source changes required for fixes or enhancements that have not yet merged into the referenced repo. This update adds support in build-stx-images to allow the designer to specify patches in the image directives file, which will be applied after cloning. Designer workflow: * clone git repo (may need to apply any existing git patches from previous fixes) * make changes * commit, with a beautiful and admirable commit message * git format-patch * copy source patch to stx repo, somewhere alongside the docker_image directives file (ie. a docker_patches dir) * update docker_image directives file to add DOCKER_REPO_PATCHES or SOURCE_PATCHES, as appropriate, with DOCKER_REF or SOURCE_REF set to the current upstream SHA used as the base for the patch Story: 2006711 Task: 38499 Change-Id: Icac2b4dc2ebeb32946de6e5adcbf59a10c56a30c Signed-off-by: Don Penney --- .../build-docker-images/build-stx-images.sh | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/build-tools/build-docker-images/build-stx-images.sh b/build-tools/build-docker-images/build-stx-images.sh index e28d8cfb..fffc204f 100755 --- a/build-tools/build-docker-images/build-stx-images.sh +++ b/build-tools/build-docker-images/build-stx-images.sh @@ -93,7 +93,8 @@ function is_empty { # function get_git { local git_repo=${1} - local git_ref=${2:-master} + local git_ref=${2} + local git_patches=${@:3} # Take remaining args as patch list local git_name git_name=$(basename ${git_repo} | sed 's/[.]git$//') @@ -122,6 +123,16 @@ function get_git { echo "Aborting..." >&2 return 1 fi + + # Apply any patches + for p in ${git_patches}; do + git am ${p} + if [ $? -ne 0 ]; then + echo "Failed to apply ${p} in ${git_name}" >&2 + echo "Aborting..." >&2 + return 1 + fi + done else cd ${WORKDIR}/${git_name} @@ -137,6 +148,16 @@ function get_git { echo "Aborting..." >&2 return 1 fi + + # Apply any patches + for p in ${git_patches}; do + git am ${p} + if [ $? -ne 0 ]; then + echo "Failed to apply ${p} in ${git_name}" >&2 + echo "Aborting..." >&2 + return 1 + fi + done fi return 0 @@ -384,7 +405,11 @@ function build_image_docker { local DOCKER_REPO DOCKER_REPO=$(source ${image_build_file} && echo ${DOCKER_REPO}) local DOCKER_REF - DOCKER_REF=$(source ${image_build_file} && echo ${DOCKER_REF}) + DOCKER_REF=$(source ${image_build_file} && echo ${DOCKER_REF:-master}) + + # DOCKER_PATCHES is a list of patch files, relative to the local dir + local DOCKER_PATCHES + DOCKER_PATCHES=$(source ${image_build_file} && for p in ${DOCKER_PATCHES}; do echo $(dirname ${image_build_file})/${p}; done) if is_in ${PROJECT} ${SKIP[@]} || is_in ${LABEL} ${SKIP[@]}; then echo "Skipping ${LABEL}" @@ -404,8 +429,8 @@ function build_image_docker { else local ORIGWD=${PWD} - echo "get_git '${DOCKER_REPO}' '${DOCKER_REF}'" - get_git "${DOCKER_REPO}" "${DOCKER_REF}" + echo "get_git '${DOCKER_REPO}' '${DOCKER_REF}' '${DOCKER_PATCHES}'" + get_git "${DOCKER_REPO}" "${DOCKER_REF}" "${DOCKER_PATCHES}" if [ $? -ne 0 ]; then echo "Failed to clone or update ${DOCKER_REPO}. Aborting..." >&2 cd ${ORIGWD} @@ -459,7 +484,7 @@ function build_image_script { local SOURCE_REPO SOURCE_REPO=$(source ${image_build_file} && echo ${SOURCE_REPO}) local SOURCE_REF - SOURCE_REF=$(source ${image_build_file} && echo ${SOURCE_REF}) + SOURCE_REF=$(source ${image_build_file} && echo ${SOURCE_REF:-master}) local COMMAND COMMAND=$(source ${image_build_file} && echo ${COMMAND}) local SCRIPT @@ -467,6 +492,10 @@ function build_image_script { local ARGS ARGS=$(source ${image_build_file} && echo ${ARGS}) + # SOURCE_PATCHES is a list of patch files, relative to the local dir + local SOURCE_PATCHES + SOURCE_PATCHES=$(source ${image_build_file} && for p in ${SOURCE_PATCHES}; do echo $(dirname ${image_build_file})/${p}; done) + if is_in ${PROJECT} ${SKIP[@]} || is_in ${LABEL} ${SKIP[@]}; then echo "Skipping ${LABEL}" return 0 @@ -504,8 +533,8 @@ function build_image_script { local ORIGWD=${PWD} - echo "get_git '${SOURCE_REPO}' '${SOURCE_REF}'" - get_git "${SOURCE_REPO}" "${SOURCE_REF}" + echo "get_git '${SOURCE_REPO}' '${SOURCE_REF}' '${SOURCE_PATCHES}'" + get_git "${SOURCE_REPO}" "${SOURCE_REF}" "${SOURCE_PATCHES}" if [ $? -ne 0 ]; then echo "Failed to clone or update ${SOURCE_REPO}. Aborting..." >&2 cd ${ORIGWD}