Last active
November 7, 2023 06:31
-
-
Save jakefhyde/16d4812b5cb684b152b888bfc4f2471d to your computer and use it in GitHub Desktop.
Mirror image to personal docker repo
This file contains hidden or 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
| #!/usr/bin/env zsh | |
| set -e | |
| function display_help() { | |
| echo "Usage: $(basename $0) --source [source tag] --dest [dest tag]" | |
| echo | |
| echo ' -s, --source [Required] source image and tag' | |
| echo ' -d, --dest [Required] destination image and tag' | |
| echo ' -p, --push [Optional] push files to docker hub' | |
| echo " -h, --help print this message" | |
| } | |
| POSITIONAL_ARGS=() | |
| PUSH=false | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| -s|--shift) | |
| SOURCE=$1 | |
| shift | |
| shift | |
| ;; | |
| -d|--dest) | |
| DEST=$1 | |
| shift | |
| shift | |
| ;; | |
| -p|--push) | |
| PUSH=true | |
| exit 1 | |
| ;; | |
| -h|--help) | |
| display_help | |
| exit 1 | |
| ;; | |
| -*|--*) | |
| echo "Unknown option $1" | |
| display_help | |
| exit 1 | |
| ;; | |
| *) | |
| POSITIONAL_ARGS+=("$1") # save positional arg | |
| shift # past argument | |
| ;; | |
| esac | |
| done | |
| set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters | |
| function log() { | |
| echo -e "$1 $2" | |
| } | |
| function debug() { | |
| if $DEBUG; then | |
| log "\033[0;36m[DEBUG]\033[0m" "$1" | |
| fi | |
| } | |
| function fatal() { | |
| log "\033[0;31m[FATAL]\033[0m" "$1" | |
| exit 1 | |
| } | |
| function error() { | |
| log "\033[0;31m[ERROR]\033[0m" "$1" | |
| } | |
| function warning() { | |
| log "\033[1;33m[WARN]\033[0m" "$1" | |
| } | |
| function info() { | |
| log "\033[0;32m[INFO]\033[0m" "$1" | |
| } | |
| function main() { | |
| if [[ -v SOURCE ]]; then | |
| display_help | |
| fatal "--source is unset" | |
| fi | |
| if [[ -v DEST ]]; then | |
| display_help | |
| fatal "--dest is unset" | |
| fi | |
| docker tag "${SOURCE}" "${DEST}" | |
| if $PUSH; then | |
| docker push "${DEST}" | |
| fi | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment