From 7dc6b23b517d4d14cad38f29d47af64e66e105b9 Mon Sep 17 00:00:00 2001 From: Stefan Dinescu Date: Wed, 18 Mar 2020 16:23:59 +0200 Subject: [PATCH] Support custom docker registries for remote cli The build script for remote cli was receiving as parameters only the desired tag for the clients docker images; the docker images were always pulled from docker.io/starlinx. Nowthe build script take the full link of the docker image as parameter, so we can use any docker registry as source for the client images. Change-Id: Ibc4584a9401c1ff30f8e657ca27d31b35c4e94d5 Depends-On: https://review.opendev.org/#/c/713665/ Story: 2006711 Task: 39095 Signed-off-by: Stefan Dinescu --- build-tools/build-remote-cli.sh | 67 +++++++++++---------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/build-tools/build-remote-cli.sh b/build-tools/build-remote-cli.sh index 1cdce8e0..1f6bbc0b 100755 --- a/build-tools/build-remote-cli.sh +++ b/build-tools/build-remote-cli.sh @@ -15,43 +15,35 @@ if [ -z "${MY_WORKSPACE}" -o -z "${MY_REPO}" ]; then exit 1 fi -IMAGE_TAG="master-centos-stable-latest" -PLATFORM_IMAGE_TAG="${IMAGE_TAG}" -APPLICATION_IMAGE_TAG="${IMAGE_TAG}" +PLATFORM_IMAGE="docker.io/starlingx/stx-platformclients:master-centos-stable-latest" +APPLICATION_IMAGE="docker.io/starlingx/stx-openstackclients:master-centos-stable-latest" OUTPUT_FILE="stx-remote-cli" VERSION="1.0" 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" -COMMON_TAG=0 -SPECIFIC_TAG=0 -CUSTOM_PLATFORM_TAG=0 -CUSTOM_APPLICATION_TAG=0 +IMAGE_FILE="docker_image_version.sh" +CUSTOM_PLATFORM_IMAGE=0 +CUSTOM_APPLICATION_IMAGE=0 function usage { echo "Usage:" echo "$(basename $0) [--version ] [-o, --output ] [-t. --tag ]" - echo " [--application-tag ] [--platform-tag ] [-h]" + echo " [--application-image ] [--platform-image ] [-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 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)" + echo " --platform-image specify platform docker image tag." + echo " (default value is docker.io/starlingx/stx-platformclients:master-centos-stable-latest)" + echo " --application-image specify application docker image." + echo " (default value is docker.io/starlingx/stx-openstackclients:master-centos-stable-latest)" } -OPTS=$(getopt -o h,o:,t: -l version:,output:,tag:,platform-tag:,application-tag: -- "$@") +OPTS=$(getopt -o h,o:,t: -l version:,output:,tag:,platform-image:,application-image: -- "$@") if [ $? -ne 0 ]; then usage exit 1 @@ -77,24 +69,14 @@ while true; do OUTPUT_FILE=$2 shift 2 ;; - -t | --tag) - PLATFORM_IMAGE_TAG=$2 - APPLICATION_IMAGE_TAG=$2 - CUSTOM_PLATFORM_TAG=1 - CUSTOM_APPLICATION_TAG=1 - COMMON_TAG=1 + --platform-image) + PLATFORM_IMAGE=$2 + CUSTOM_PLATFORM_IMAGE=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 + --application-image) + APPLICATION_IMAGE=$2 + CUSTOM_APPLICATION_IMAGE=1 shift 2 ;; *) @@ -103,11 +85,6 @@ 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} @@ -126,14 +103,16 @@ fi cd ${BUILD_OUTPUT_PATH} cp -r "${CLIENTS_REPO}/${REMOTE_CLI_FOLDER}" . -if [ ${CUSTOM_PLATFORM_TAG} -eq 1 ]; then +if [ ${CUSTOM_PLATFORM_IMAGE} -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}" + # Since the full path to a docker image contains slashes, we must escape them in order to pass them to sed. + # The "${PLATFORM_IMAGE//\//\\/} takes the path and escapes all the slashes. + sed -i "s/PLATFORM_DOCKER_IMAGE=[^ ]*/PLATFORM_DOCKER_IMAGE=\"${PLATFORM_IMAGE//\//\\/}\"/" "${REMOTE_CLI_FOLDER}/${IMAGE_FILE}" fi -if [ ${CUSTOM_APPLICATION_TAG} -eq 1 ]; then +if [ ${CUSTOM_APPLICATION_IMAGE} -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}" + sed -i "s/APPLICATION_DOCKER_IMAGE=[^ ]*/APPLICATION_DOCKER_IMAGE=\"${APPLICATION_IMAGE//\//\\/}\"/" "${REMOTE_CLI_FOLDER}/${IMAGE_FILE}" fi # Create archive