From aee9d5689f2e771c0ea9cd6f636029663273fe21 Mon Sep 17 00:00:00 2001 From: Stefan Dinescu Date: Mon, 26 Aug 2019 15:13:47 +0300 Subject: [PATCH] Package remote cli wrapper scripts This script creates a tarball with the remote CLI wrapper scripts present in stx-clients. This also allows configuring the docker image tag for the remote cli containers so we can distribute a remote cli tarball compatible with the platform and application deployment. Change-Id: I156172a6ed208d6fcf9bb8f37182daea73b2856c Partial-bug: 1840133 Depends-On: I02ceee5d20aefe5fcc68f3059b41167bf1fa6a94 Signed-off-by: Stefan Dinescu --- build-tools/build-remote-cli.sh | 117 ++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 build-tools/build-remote-cli.sh diff --git a/build-tools/build-remote-cli.sh b/build-tools/build-remote-cli.sh new file mode 100755 index 00000000..719b86ba --- /dev/null +++ b/build-tools/build-remote-cli.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# +# Copyright (c) 2019 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +# This utility retrieves StarlingX remote CLI +# wrapper scripts from the REPO and packages +# them in a tarball +# + +# Required environment variables +if [ -z "${MY_WORKSPACE}" -o -z "${MY_REPO}" ]; then + echo "Environment not setup for build" >&2 + exit 1 +fi + +IMAGE_TAG="master-centos-stable-latest" +OUTPUT_FILE="stx-remote-cli" +VERSION="1.0" + +CLIENTS_REPO="${MY_REPO}/stx/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 + +function usage { + echo "Usage:" + echo "$(basename $0) [--version ] [-o, --output ] [-t. --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 " (default value is mater-centos-stable-latest)" +} + +OPTS=$(getopt -o h,o:,t: -l version:,output:,tag: -- "$@") +if [ $? -ne 0 ]; then + usage + exit 1 +fi + +eval set -- "${OPTS}" + +while true; do + case $1 in + --) + shift + break + ;; + -h) + usage + exit 1 + ;; + --version) + VERSION=$2 + shift 2 + ;; + -o | --output) + OUTPUT_FILE=$2 + shift 2 + ;; + -t | --tag) + IMAGE_TAG=$2 + CUSTOM_IMAGE_TAG=1 + shift 2 + ;; + *) + usage + exit 1 + esac +done + +if [ -d ${BUILD_OUTPUT_PATH} ]; then + # Clean the previous build + rm -rf ${BUILD_OUTPUT_PATH} + if [ $? -ne 0 ]; then + echo "Failed to cleanup workspace ${BUILD_OUTPUT_PATH}" >&2 + exit 1 + fi +fi + +mkdir -p ${BUILD_OUTPUT_PATH} +if [ $? -ne 0 ]; then + echo "Failed to create the workspace ${BUILD_OUTPUT_PATH}" >&2 + exit 1 +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 + + # Write a new file with the custom tag + echo "export DOCKER_IMAGE_TAG=${IMAGE_TAG}" >> "${REMOTE_CLI_FOLDER}/${TAG_FILE}" +fi + +# Create archive +tar czf ${OUTPUT_FILE}-${VERSION}.tgz ${REMOTE_CLI_FOLDER} +if [ $? -ne 0 ]; then + echo "Failed to create ${OUTPUT_FILE}-${VERSION}.tgz tarball" >&2 + exit 1 +fi + +echo "" +echo "Created remote CLI tarball: ${BUILD_OUTPUT_PATH}/${OUTPUT_FILE}-${VERSION}.tgz" +echo ""