代码拉取完成,页面将自动刷新
#!/usr/bin/env bash
set -ueo pipefail
usage() {
cat << EOF
Push Helm Chart to Nexus repository
This plugin provides ability to push a Helm Chart directory or package to a
remote Nexus Helm repository.
Usage:
helm nexus-push [repo] login [flags] Setup login information for repo
helm nexus-push [repo] logout [flags] Remove login information for repo
helm nexus-push [repo] [CHART] [flags] Pushes chart to repo
Flags:
-u, --username string Username for authenticated repo (assumes anonymous access if unspecified)
-p, --password string Password for authenticated repo (prompts if unspecified and -u specified)
EOF
}
declare USERNAME
declare PASSWORD
declare -a POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]
do
case "$1" in
-h|--help)
usage
exit 0
;;
-u|--username)
if [[ -z "${2:-}" ]]; then
echo "Must specify username!"
echo "---"
usage
exit 1
fi
shift
USERNAME=$1
;;
-p|--password)
if [[ -n "${2:-}" ]]; then
shift
PASSWORD=$1
else
PASSWORD=
fi
;;
*)
POSITIONAL_ARGS+=("$1")
;;
esac
shift
done
[[ ${#POSITIONAL_ARGS[@]} -ne 0 ]] && set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
if [[ $# -lt 2 ]]; then
echo "Missing arguments!"
echo "---"
usage
exit 1
fi
indent() { sed 's/^/ /'; }
declare HELM3_VERSION="$(helm version --client --short | grep "v3\.")"
declare REPO=$1
declare REPO_URL="$(helm repo list | grep "^$REPO" | awk '{print $2}')/"
if [[ -n $HELM3_VERSION ]]; then
declare REPO_AUTH_FILE="$HOME/.config/helm/auth.$REPO"
else
declare REPO_AUTH_FILE="$(helm home)/repository/auth.$REPO"
fi
if [[ -z "$REPO_URL" ]]; then
echo "Invalid repo specified! Must specify one of these repos..."
helm repo list
echo "---"
usage
exit 1
fi
declare CMD
declare AUTH
declare CHART
case "$2" in
login)
if [[ -z "$USERNAME" ]]; then
read -p "Username: " USERNAME
fi
if [[ -z "$PASSWORD" ]]; then
read -s -p "Password: " PASSWORD
echo
fi
echo "$USERNAME:$PASSWORD" > "$REPO_AUTH_FILE"
;;
logout)
rm -f "$REPO_AUTH_FILE"
;;
*)
CMD=push
CHART=$2
if [[ -f "$REPO_AUTH_FILE" ]]; then
REPO_CREDENTIALS=$(cat $REPO_AUTH_FILE)
USERNAME=$(echo ${REPO_CREDENTIALS} | cut -d':' -f1)
PASSWORD=$(echo ${REPO_CREDENTIALS} | cut -d':' -f2)
AUTH="$USERNAME:$PASSWORD"
echo "Found early saved autorization authorization. Will use user [${USERNAME}] with password [${PASSWORD}] for chart ${CHART}"
fi
if [[ -z "$USERNAME" ]] || [[ -z "$PASSWORD" ]]; then
if [[ -f "$REPO_AUTH_FILE" ]]; then
echo "Using cached login creds..."
AUTH="$(cat $REPO_AUTH_FILE)"
else
if [[ -z "$USERNAME" ]]; then
read -p "Username: " USERNAME
fi
if [[ -z "$PASSWORD" ]]; then
read -s -p "Password: " PASSWORD
echo
fi
AUTH="$USERNAME:$PASSWORD"
fi
fi
if [[ -d "$CHART" ]]; then
CHART_PACKAGE="$(helm package "$CHART" | cut -d":" -f2 | tr -d '[:space:]')"
else
CHART_PACKAGE="$CHART"
fi
echo "Pushing $CHART to repo $REPO_URL..."
curl -is -u "$AUTH" "$REPO_URL" --upload-file "$CHART_PACKAGE" | indent
echo "Done"
;;
esac
exit 0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。