2022-10-20 18:48:17 -07:00
|
|
|
#!/bin/bash
|
2023-01-17 15:20:30 -08:00
|
|
|
|
|
|
|
make_tag () {
|
|
|
|
|
|
|
|
local DIR
|
2022-10-20 18:48:17 -07:00
|
|
|
DIR=$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P )
|
|
|
|
|
2023-01-17 15:20:30 -08:00
|
|
|
# generate a full image name with tag
|
2022-10-20 18:48:17 -07:00
|
|
|
# $1 name, $2 user(or repo), $3 repo
|
|
|
|
|
|
|
|
[[ $# -lt 1 ]] && echo "image base name required" && exit
|
|
|
|
|
|
|
|
declare OPTION; declare OPTARG; declare OPTIND
|
|
|
|
while getopts 'daht:r:u:' OPTION; do
|
|
|
|
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
|
|
|
case "$OPTION" in
|
|
|
|
d)
|
|
|
|
delete=true
|
|
|
|
;;
|
|
|
|
r)
|
|
|
|
REPO=$OPTARG
|
|
|
|
;;
|
|
|
|
u)
|
|
|
|
RUSER=$OPTARG
|
|
|
|
;;
|
|
|
|
t)
|
|
|
|
TAG=$OPTARG
|
|
|
|
;;
|
|
|
|
a) # add -arm64 to image
|
|
|
|
arm=arm64
|
|
|
|
;;
|
|
|
|
*) echo unknown run option -$OPTARG
|
|
|
|
echo "USAGE: tag <options>"
|
|
|
|
echo "available options: -a add -arm64 to tag, -d delete tag "
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
|
|
|
|
# image tag
|
|
|
|
name=$1
|
|
|
|
user=${2:-$RUSER}
|
|
|
|
repo=${3:-$REPO}
|
|
|
|
|
|
|
|
tag=$([[ $repo ]] && echo ${repo}/)$([[ $user ]] && echo ${user}/)$name$([[ $arm ]] && echo -arm64):${TAG:-latest}
|
|
|
|
|
|
|
|
echo $tag
|
|
|
|
|
2023-01-17 15:20:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
# if script was executed then call the function
|
|
|
|
(return 0 2>/dev/null) || make_tag $@
|