Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft:NPT-768: Move script dependencies(tools like yq, tr) to docker image #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/Dockerfile.utils
Original file line number Diff line number Diff line change
@@ -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"]

16 changes: 16 additions & 0 deletions cli/get-latest-version.sh
Original file line number Diff line number Diff line change
@@ -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:]'
32 changes: 23 additions & 9 deletions cli/get-nexus-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@ 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
CLI_UTILS_DOCKER_NAME="cli-utils"

usage() { echo "Usage: $0 [-r <repository-name>] [-v <version>] [-d <install-directory>] " 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 --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
echo -e "Downloading Nexus ...\nVersion: ${VERSION}\nImage repository: ${REPOSITORY}\nDirectory: ${INSTALL_DIRECTORY}\n"
echo -e "Would you like to customize installation [y/n]:"
Expand Down