diff --git a/build-tools/build-remote-cli.sh b/build-tools/build-remote-cli.sh index d7c25b7d..1cdce8e0 100755 --- a/build-tools/build-remote-cli.sh +++ b/build-tools/build-remote-cli.sh @@ -16,6 +16,8 @@ if [ -z "${MY_WORKSPACE}" -o -z "${MY_REPO}" ]; then fi IMAGE_TAG="master-centos-stable-latest" +PLATFORM_IMAGE_TAG="${IMAGE_TAG}" +APPLICATION_IMAGE_TAG="${IMAGE_TAG}" OUTPUT_FILE="stx-remote-cli" VERSION="1.0" @@ -23,22 +25,33 @@ CLIENTS_REPO="${MY_REPO}/stx/clients" REMOTE_CLI_FOLDER="remote_cli" BUILD_OUTPUT_PATH="${MY_WORKSPACE}/std/build-remote-cli" TAG_FILE="docker_image_version.sh" -CUSTOM_IMAGE_TAG=0 +COMMON_TAG=0 +SPECIFIC_TAG=0 +CUSTOM_PLATFORM_TAG=0 +CUSTOM_APPLICATION_TAG=0 function usage { echo "Usage:" - echo "$(basename $0) [--version ] [-o, --output ] [-t. --tag ] [-h]" + echo "$(basename $0) [--version ] [-o, --output ] [-t. --tag ]" + echo " [--application-tag ] [--platform-tag ] [-h]" echo "Options:" echo " -h show help options" echo " --version specify remote CLI version" echo " (default value is 1.0)" echo " -o, --output specify tarball output name" echo " (default value is stx-remote-cli)" - echo " -t, --tag specify docker image tag" + echo " -t, --tag specify docker image tag for both platform and application." + echo " cannot be used together with --platform-tag or --application-tag options" + echo " (default value is mater-centos-stable-latest)" + echo " --platform-tag specify platform docker image tag." + echo " cannot be used together with --tag option" + echo " (default value is mater-centos-stable-latest)" + echo " --application-tag specify application docker image tag." + echo " cannot be used together with --tag option" echo " (default value is mater-centos-stable-latest)" } -OPTS=$(getopt -o h,o:,t: -l version:,output:,tag: -- "$@") +OPTS=$(getopt -o h,o:,t: -l version:,output:,tag:,platform-tag:,application-tag: -- "$@") if [ $? -ne 0 ]; then usage exit 1 @@ -65,8 +78,23 @@ while true; do shift 2 ;; -t | --tag) - IMAGE_TAG=$2 - CUSTOM_IMAGE_TAG=1 + PLATFORM_IMAGE_TAG=$2 + APPLICATION_IMAGE_TAG=$2 + CUSTOM_PLATFORM_TAG=1 + CUSTOM_APPLICATION_TAG=1 + COMMON_TAG=1 + shift 2 + ;; + --platform-tag) + PLATFORM_IMAGE_TAG=$2 + CUSTOM_PLATFORM_TAG=1 + SPECIFIC_TAG=1 + shift 2 + ;; + --application-tag) + APPLICATION_IMAGE_TAG=$2 + CUSTOM_APPLICATION_TAG=1 + SPECIFIC_TAG=1 shift 2 ;; *) @@ -75,6 +103,11 @@ while true; do esac done +if [[ ${SPECIFIC_TAG} -eq 1 ]] && [[ ${COMMON_TAG} -eq 1 ]]; then + echo "Cannot use both \"--tag\" and \"--application-tag\"/\"--platform-tag\" options at the same time" >&2 + exit 1 +fi + if [ -d ${BUILD_OUTPUT_PATH} ]; then # Clean the previous build rm -rf ${BUILD_OUTPUT_PATH} @@ -93,16 +126,14 @@ fi cd ${BUILD_OUTPUT_PATH} cp -r "${CLIENTS_REPO}/${REMOTE_CLI_FOLDER}" . -if [ ${CUSTOM_IMAGE_TAG} -eq 1 ]; then - # Delete the default tag file - rm -rf "${REMOTE_CLI_FOLDER}/${TAG_FILE}" - if [ $? -ne 0 ]; then - echo "Failed to delete default tag file ${BUILD_OUTPUT_PATH}/${REMOTE_CLI_FOLDER}/${TAG_FILE}" >&2 - exit 1 - fi +if [ ${CUSTOM_PLATFORM_TAG} -eq 1 ]; then + # Replace the platform image tag + sed -i "s/PLATFORM_DOCKER_IMAGE_TAG=[^ ]*/PLATFORM_DOCKER_IMAGE_TAG=\"${PLATFORM_IMAGE_TAG}\"/" "${REMOTE_CLI_FOLDER}/${TAG_FILE}" +fi - # Write a new file with the custom tag - echo "export DOCKER_IMAGE_TAG=${IMAGE_TAG}" >> "${REMOTE_CLI_FOLDER}/${TAG_FILE}" +if [ ${CUSTOM_APPLICATION_TAG} -eq 1 ]; then + # Replace the application image tag + sed -i "s/APPLICATION_DOCKER_IMAGE_TAG=[^ ]*/APPLICATION_DOCKER_IMAGE_TAG=\"${APPLICATION_IMAGE_TAG}\"/" "${REMOTE_CLI_FOLDER}/${TAG_FILE}" fi # Create archive