Created
March 18, 2023 20:53
-
-
Save loperd/fea53d6fb1b05637eeb2569e404415e7 to your computer and use it in GitHub Desktop.
Generator of dockerconfig json for using in the helm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REGISTRY_URI="registry.gitlab.com" | |
USERNAME="" | |
PASSWORD="" | |
OUTPUT="raw" | |
ME_FILENAME="./$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")" | |
HELP_USAGE="${ME_FILENAME} -u {username} -p {password} [-o raw/json/base64/bs64] registry.example.co" | |
POSITIONAL=() | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
-u | --username) | |
USERNAME="$2" | |
shift | |
shift | |
;; | |
-p | --password) | |
PASSWORD="$2" | |
shift | |
shift | |
;; | |
-o | --output) | |
OUTPUT="$2" | |
if [[ "base64" -ne "$OUTPUT" || "bs64" -ne "$OUTPUT" || "json" -ne "$OUTPUT" || "raw" -ne "$OUTPUT" ]]; then | |
echo -e "\n[ERROR] Output should be one of the [bs64/base64, raw/json]\n" | |
exit | |
fi | |
shift | |
shift | |
;; | |
-h | --help) | |
echo -e "\nUse ${HELP_USAGE}\n" | |
exit | |
;; | |
*) | |
POSITIONAL+=("$1") | |
shift | |
;; | |
esac | |
done | |
set -- "${POSITIONAL[@]}" | |
if [[ -z "${USERNAME}" || -z "${PASSWORD}" ]]; then | |
echo -e "\nUse ${HELP_USAGE}\n" | |
exit | |
fi | |
TEMPLATE='{ | |
"auths": { | |
"{REGISTRY_URI}": { | |
"username":"{REGISTRY_USERNAME}", | |
"password":"{REGISTRY_PASSWORD}", | |
"auth":"{REGISTRY_AUTH}" | |
} | |
} | |
}' | |
AUTH=$(echo "${USERNAME}:${PASSWORD}" | base64 -w 0) | |
DOCKERCONFIG=${TEMPLATE/"{REGISTRY_USERNAME}"/"$USERNAME"} | |
DOCKERCONFIG=${DOCKERCONFIG/"{REGISTRY_PASSWORD}"/"$PASSWORD"} | |
DOCKERCONFIG=${DOCKERCONFIG/"{REGISTRY_AUTH}"/"$AUTH"} | |
DOCKERCONFIG=${DOCKERCONFIG/"{REGISTRY_URI}"/"$REGISTRY_URI"} | |
case $OUTPUT in | |
base64 | bs64) | |
echo -e $(echo "$DOCKERCONFIG" | base64 -w 0) | |
;; | |
raw | json) | |
echo -e "$DOCKERCONFIG" | |
;; | |
*) | |
echo "[FATAL] Invalid Output type." | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment