From cdafb36e510adb4b39bf6529a83efa62a6b20dc2 Mon Sep 17 00:00:00 2001 From: sankarm Date: Fri, 23 Dec 2022 16:38:23 +0530 Subject: [PATCH 1/2] getting latest nexus version part moved to docker image, since it has yq, tr dependencies --- cli/Dockerfile.utils | 6 ++++++ cli/get-latest-version.sh | 16 ++++++++++++++++ cli/get-nexus-cli.sh | 29 ++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 cli/Dockerfile.utils create mode 100755 cli/get-latest-version.sh diff --git a/cli/Dockerfile.utils b/cli/Dockerfile.utils new file mode 100644 index 000000000..46de8bf48 --- /dev/null +++ b/cli/Dockerfile.utils @@ -0,0 +1,6 @@ +FROM gcr.io/nsx-sm/photon:4.0 + +RUN tdnf install --refresh -y jq coreutils +ADD get-latest-version.sh / +ENTRYPOINT ["/usr/bin/bash", "/get-latest-version.sh"] + diff --git a/cli/get-latest-version.sh b/cli/get-latest-version.sh new file mode 100755 index 000000000..bb83048e8 --- /dev/null +++ b/cli/get-latest-version.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -e + +VERSION="" +SEMVER_REGEX_MASTER="v[0-9]+\.[0-9]+\.[0-9]+$" + +json_resp=$(curl -s https://gcr.io/v2/nsx-sm/nexus/nexus-cli/tags/list | jq -r '.manifest[] | .tag | select(.[]=="latest") | .[]') +declare -a tags_array=($(echo "${json_resp}" | tr "\n" " ")) +for version in "${tags_array[@]}"; do + if [[ "${version}" =~ ${SEMVER_REGEX_MASTER} ]]; then + VERSION="${version}" + break + fi +done + +echo "$VERSION" | tr -d '[:space:]' diff --git a/cli/get-nexus-cli.sh b/cli/get-nexus-cli.sh index 788dc0df6..39f05a992 100755 --- a/cli/get-nexus-cli.sh +++ b/cli/get-nexus-cli.sh @@ -5,19 +5,30 @@ set -e REPOSITORY="gcr.io/nsx-sm/nexus/nexus-cli" INSTALL_DIRECTORY="/usr/local/bin" VERSION="" - SEMVER_REGEX_MASTER="v[0-9]+\.[0-9]+\.[0-9]+$" -json_resp=$(curl -s https://gcr.io/v2/nsx-sm/nexus/nexus-cli/tags/list | jq -r '.manifest[] | .tag | select(.[]=="latest") | .[]') -declare -a tags_array=($(echo "${json_resp}" | tr "\n" " ")) -for version in "${tags_array[@]}"; do - if [[ "${version}" =~ ${SEMVER_REGEX_MASTER} ]]; then - VERSION="${version}" - break - fi -done usage() { echo "Usage: $0 [-r ] [-v ] [-d ] " 1>&2; exit 1; } +must_exist() { + export PATH=$PATH:$HOME/.local/bin + if ! command -v "$1" >/dev/null 2>&1; then + echo -e "$1" is not installed! "\n$2" >&2 + return 1 + fi +} + +msg="docker is needed by this script, please install the docker to use this script to download the nexus" +must_exist "docker" "${msg}" + +version_tag=$(docker run -it gcr.io/nsx-sm/nexus/cli-utils) +if [[ "${version_tag}" =~ ${SEMVER_REGEX_MASTER} ]]; then + VERSION="${version_tag}" +else + echo "Unable to find latest nexus version" + exit 1 +fi + + if [[ $# == 0 ]]; then echo -e "Downloading Nexus ...\nVersion: ${VERSION}\nImage repository: ${REPOSITORY}\nDirectory: ${INSTALL_DIRECTORY}\n" echo -e "Would you like to customize installation [y/n]:" From 617bc09a011f4245ed2f48f976fbd000a1a060bc Mon Sep 17 00:00:00 2001 From: sankarm Date: Fri, 23 Dec 2022 18:22:54 +0530 Subject: [PATCH 2/2] run the docker image with name and do cleanup once get the version --- cli/get-nexus-cli.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/get-nexus-cli.sh b/cli/get-nexus-cli.sh index 39f05a992..9241ca7b6 100755 --- a/cli/get-nexus-cli.sh +++ b/cli/get-nexus-cli.sh @@ -6,6 +6,7 @@ REPOSITORY="gcr.io/nsx-sm/nexus/nexus-cli" INSTALL_DIRECTORY="/usr/local/bin" VERSION="" SEMVER_REGEX_MASTER="v[0-9]+\.[0-9]+\.[0-9]+$" +CLI_UTILS_DOCKER_NAME="cli-utils" usage() { echo "Usage: $0 [-r ] [-v ] [-d ] " 1>&2; exit 1; } @@ -20,13 +21,15 @@ must_exist() { msg="docker is needed by this script, please install the docker to use this script to download the nexus" must_exist "docker" "${msg}" -version_tag=$(docker run -it gcr.io/nsx-sm/nexus/cli-utils) +version_tag=$(docker run --name ${CLI_UTILS_DOCKER_NAME} -it gcr.io/nsx-sm/nexus/cli-utils) if [[ "${version_tag}" =~ ${SEMVER_REGEX_MASTER} ]]; then VERSION="${version_tag}" else echo "Unable to find latest nexus version" exit 1 fi +docker rm ${CLI_UTILS_DOCKER_NAME} &> /dev/null +docker rmi "gcr.io/nsx-sm/nexus/cli-utils:latest" &> /dev/null if [[ $# == 0 ]]; then