1 Star 0 Fork 0

wl4g-k8s/helm-nexus3-push-plugin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
push.sh 3.72 KB
一键复制 编辑 原始数据 按行查看 历史
James Wong 提交于 2022-08-25 16:53 . Init Commit
#!/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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/wl4g-k8s/helm-nexus3-push-plugin.git
git@gitee.com:wl4g-k8s/helm-nexus3-push-plugin.git
wl4g-k8s
helm-nexus3-push-plugin
helm-nexus3-push-plugin
main

搜索帮助