Skip to content

Commit

Permalink
Merge pull request #428 from perftool-incubator/dev-kmr
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rister authored Dec 3, 2024
2 parents d2d480d + 3733277 commit fd300d4
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/_help
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function help() {
echo "help | Show this help message"
echo "run | Run a benchmark"
echo "log | Manage with the crucible log"
echo "registries | Get info on or configure the container image registries"
echo "repo | Get info on or configure the crucible and subproject git repos"
echo "update | Update all or part of the crucible software"
echo "console | Run user supplied programs inside a crucible wrapper for logging purposes"
Expand Down
9 changes: 9 additions & 0 deletions bin/_main
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ elif [ "${1}" == "ls" -o "${1}" == "tags" -o "${1}" == "result-completion" ]; th
EXIT_VAL=$?
;;
esac
elif [ "${1}" == "registries" ]; then
shift
if [ -z "${1}" ]; then
${CRUCIBLE_HOME}/bin/registries info
EXIT_VAL=$?
else
${CRUCIBLE_HOME}/bin/registries "$@"
EXIT_VAL=$?
fi
elif [ "${1}" == "repo" ]; then
shift
if [ -z "${1}" ]; then
Expand Down
246 changes: 246 additions & 0 deletions bin/registries
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
#!/usr/bin/env bash
# -*- mode: sh; indent-tabs-mode: nil; sh-basic-offset: 4 -*-
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=bash

# registries management infrastructure

source /etc/sysconfig/crucible

if [ ! -e "${CRUCIBLE_HOME}" ]; then
echo "Could not find $CRUCIBLE_HOME, exiting."
exit 1
fi

source "${CRUCIBLE_HOME}/bin/base"
source "${CRUCIBLE_HOME}/bin/jqlib"

function help() {
echo "Usage:"
echo " registries <command> [command-specific-options]"
echo ""
echo "The following commands are supported"
echo ""
echo "add | Add a registry to the configruation. Either 'private-engine' or 'userenv' are currently supported."
echo "info | Give high level info about configured registries (default)"
echo ""
}

function add_private_engine() {
local url=""
local push_token=""
local pull_token=""
local tls_verify=""
local quay_expiration_length=""
local quay_refresh_token=""
local quay_refresh_api_url=""
local error=0

local required="url push-token pull-token tls-verify quay-expiration-length"

for key_value in $@; do
key=$(echo "${key_value}" | awk -F= '{ print $1 }')
value=$(echo "${key_value}" | awk -F= '{ print $2 }')
#echo "key=${key} value=${value}"

case "${key}" in
"url")
url="${value}"
required=${required//url}
;;
"push-token")
push_token="${value}"
required=${required//push-token}
;;
"pull-token")
pull_token="${value}"
required=${required//pull-token}
;;
"tls-verify")
tls_verify="${value}"
required=${required//tls-verify}
;;
"quay-expiration-length")
quay_expiration_length="${value}"
required=${required//quay-expiration-length}
;;
"quay-refresh-token")
quay_refresh_token="${value}"
;;
"quay-refresh-api-url")
quay_refresh_api_url="${value}"
;;
*)
echo "ERROR: Invalid key=value pair: ${key_value}"
error=1
;;
esac
done

local param
for param in ${required}; do
echo "ERROR: You must specify parameter ${param}"
error=1
done

if [ ${error} -ne 0 ]; then
exit 1
fi

local add_refresh=0
if [ -n "${quay_refresh_token}" -a -n "${quay_refresh_api_url}" ]; then
add_refresh=1
else
if [ -n "${quay_refresh_token}" -o -n "${quay_refresh_api_url}" ]; then
echo "ERROR: You must specify 'quay-refresh-token' and 'quay-refresh-api-url' together"
exit 1
fi
fi

local private_exists
private_exists=$(jq_query ${REGISTRIES_CFG} '.engines.private.url')
if [ "${private_exists}" != "null" ]; then
echo "ERROR: A private engines registry is already configured"
show_registries
exit 1
fi

jq_update ${REGISTRIES_CFG} "registries:add-private-engine" \
--arg url "${url}" \
--arg push_token "${push_token}" \
--arg pull_token "${pull_token}" \
--argjson tls_verify "${tls_verify}" \
--arg quay_expiration_length "${quay_expiration_length}" \
'.engines.private = {
"url": $url,
"tokens": {
"push": $push_token,
"pull": $pull_token
},
"tls-verify": $tls_verify,
"quay": {
"expiration-length": $quay_expiration_length
}
}'

if [ ${add_refresh} -eq 1 ]; then
jq_update ${REGISTRIES_CFG} "registries:add-private-engine-refresh" \
--arg quay_refresh_token "${quay_refresh_token}" \
--arg quay_refresh_api_url "${quay_refresh_api_url}" \
'.engines.private.quay."refresh-expiration" = {
"token-file": $quay_refresh_token,
"api-url": $quay_refresh_api_url
}'
fi

echo "Successfully added userenv library with url '${url}'"

show_registries
}

function add_userenv() {
local url=""
local pull_token=""
local tls_verify=""
local error=0

local required="url pull-token tls-verify"

for key_value in $@; do
key=$(echo "${key_value}" | awk -F= '{ print $1 }')
value=$(echo "${key_value}" | awk -F= '{ print $2 }')
#echo "key=${key} value=${value}"

case "${key}" in
"url")
url="${value}"
required=${required//url}
;;
"pull-token")
pull_token="${value}"
required=${required//pull-token}
;;
"tls-verify")
tls_verify="${value}"
required=${required//tls-verify}
;;
*)
echo "ERROR: Invalid key=value pair: ${key_value}"
error=1
;;
esac
done

local param
for param in ${required}; do
echo "ERROR: You must specify parameter ${param}"
error=1
done

if [ ${error} -ne 0 ]; then
exit 1
fi

local url_exists
url_exists=$(jq_query ${REGISTRIES_CFG} --arg url "${url}" '.userenvs[] | select(.url == $url) | .url')
if [ "${url_exists}" == "${url}" ]; then
echo "ERROR: The requested URL '${url}' already exists"
exit 1
fi

jq_update ${REGISTRIES_CFG} "registries:add-userenv" \
--arg url "${url}" \
--arg pull_token "${pull_token}" \
--argjson tls_verify "${tls_verify}" \
'.userenvs += [
{
"url": $url,
"pull-token": $pull_token,
"tls-verify": $tls_verify
}
]'

echo "Successfully added userenv library with url '${url}'"

show_registries
}

function show_registries() {
jq . ${REGISTRIES_CFG}
}

if [ "$1" == "help" ]; then
help
exit
elif [ -z "$1" ]; then
command="info"
else
command=$1
shift
fi

case "${command}" in
info)
show_registries
;;
add)
add_type=${1}
shift

case "${add_type}" in
private-engine)
add_private_engine "$@"
;;
userenv)
add_userenv "$@"
;;
*)
echo "ERROR: Unknown registries add type '${add_type}'"
echo " Specify either 'private-engine' or 'userenv'"
exit 1
esac
;;
*)
echo "ERROR: Uknown registries command '${command}'"
exit 1
;;
esac
89 changes: 89 additions & 0 deletions bin/repo
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,98 @@ function config_show() {
done
}

function config_add_repo() {
local name=""
local type=""
local repository=""
local primary_branch=""
local checkout_mode=""
local checkout_target=""
local error=0

local required="name type repository primary-branch checkout-mode checkout-target"

for key_value in $@; do
key=$(echo "${key_value}" | awk -F= '{ print $1 }')
value=$(echo "${key_value}" | awk -F= '{ print $2 }')
#echo "key=${key} value=${value}"

case "${key}" in
"name")
name="${value}"
required=${required//name/}
;;
"type")
type="${value}"
required=${required//type/}
;;
"repository")
repository="${value}"
required=${required//repository/}
;;
"primary-branch")
primary_branch="${value}"
required=${required//primary-branch/}
;;
"checkout-mode")
checkout_mode="${value}"
required=${required//checkout-mode/}
;;
"checkout-target")
checkout_target="${value}"
required=${required//checkout-target/}
;;
*)
echo "ERROR: Invalid key=value pair: ${key_value}"
error=1
esac
done

local param
for param in ${required}; do
echo "ERROR: You must specify parameter ${param}"
error=1
done

if [ ${error} -ne 0 ]; then
exit 1
fi

jq_update ${CRUCIBLE_HOME}/config/repos.json "repos:add-unofficial-repo" \
--arg repo_name "${name}" \
--arg repo_type "${type}" \
--arg repo_repository "${repository}" \
--arg repo_primary_branch "${primary_branch}" \
--arg repo_checkout_mode "${checkout_mode}" \
--arg repo_checkout_target "${checkout_target}" \
'.unofficial += [
{
"name": $repo_name,
"type": $repo_type,
"repository": $repo_repository,
"primary-branch": $repo_primary_branch,
"checkout": {
"mode": $repo_checkout_mode,
"target": $repo_checkout_target
}
}
]'

echo "Successfully added repo with name '${name}'"

if pushd ${CRUCIBLE_HOME} > /dev/null; then
git diff config/repos.json
popd > /dev/null
fi
}

function config_help() {
echo "Config Usage:"
echo " repo config [<command> <command-specific-options>]"
echo
echo "The following command are supported"
echo
echo "add | Add an unofficial repository"
echo "show | Dump the configuration information in tabular form (default)"
echo
}
Expand Down Expand Up @@ -261,6 +347,9 @@ case "${command}" in
fi

case "${config_subcommand}" in
add)
config_add_repo "$@"
;;
show)
config_show
;;
Expand Down

0 comments on commit fd300d4

Please sign in to comment.