parent
c343cbb148
commit
f2c9be5c29
|
@ -1,3 +1,4 @@
|
||||||
/archive/
|
/archive/
|
||||||
/build.log
|
/build.log
|
||||||
_opt/
|
_opt/
|
||||||
|
.src
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
make_tag () {
|
make_tag () {
|
||||||
|
|
||||||
local DIR
|
local tag
|
||||||
DIR=$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P )
|
|
||||||
|
|
||||||
# generate a full image name with tag
|
# generate a full image name with tag
|
||||||
# $1 name, $2 user(or repo), $3 repo
|
# $1 name, $2 user(or repo), $3 repo
|
||||||
|
@ -11,12 +10,9 @@ DIR=$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P )
|
||||||
[[ $# -lt 1 ]] && echo "image base name required" && exit
|
[[ $# -lt 1 ]] && echo "image base name required" && exit
|
||||||
|
|
||||||
declare OPTION; declare OPTARG; declare OPTIND
|
declare OPTION; declare OPTARG; declare OPTIND
|
||||||
while getopts 'daht:r:u:' OPTION; do
|
while getopts 'at:r:u:' OPTION; do
|
||||||
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
||||||
case "$OPTION" in
|
case "$OPTION" in
|
||||||
d)
|
|
||||||
delete=true
|
|
||||||
;;
|
|
||||||
r)
|
r)
|
||||||
REPO=$OPTARG
|
REPO=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
@ -38,12 +34,13 @@ done
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
# image tag
|
tag=$( echo $1 | cut -s -d ":" -f2)
|
||||||
name=$1
|
tag=${tag:-$TAG}
|
||||||
|
name=${1%:*}
|
||||||
user=${2:-$RUSER}
|
user=${2:-$RUSER}
|
||||||
repo=${3:-$REPO}
|
repo=${3:-$REPO}
|
||||||
|
|
||||||
tag=$([[ $repo ]] && echo ${repo}/)$([[ $user ]] && echo ${user}/)$name$([[ $arm ]] && echo -arm64):${TAG:-latest}
|
tag=$([[ $repo ]] && echo ${repo}/)$([[ $user ]] && echo ${user}/)$name$([[ $arm ]] && echo -arm64):${tag:-latest}
|
||||||
|
|
||||||
echo $tag
|
echo $tag
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
image_info () {
|
image_info () {
|
||||||
[[ $1 == "-k" ]] && key=$2 && shift 2
|
[[ $1 == "-k" ]] && key=$2 && shift 2
|
||||||
tag=$(make_tag "$@")
|
tag=$(make_tag "$@")
|
||||||
|
# TODO try using --format to extract keys
|
||||||
|
# https://docs.docker.com/engine/reference/commandline/inspect/
|
||||||
info=$(docker image inspect $tag 2> /dev/null) || info=$(docker image inspect $1 2> /dev/null) || return 1
|
info=$(docker image inspect $tag 2> /dev/null) || info=$(docker image inspect $1 2> /dev/null) || return 1
|
||||||
if [[ $key ]]; then
|
if [[ $key ]]; then
|
||||||
# echo image: $tag, key:$key
|
# echo image: $tag, key:$key
|
||||||
|
@ -20,6 +22,10 @@ image_arch () {
|
||||||
image_info -k Architecture "$@"
|
image_info -k Architecture "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
image_tags () {
|
||||||
|
image_info -k RepoTags "$@"
|
||||||
|
}
|
||||||
|
|
||||||
image_id () {
|
image_id () {
|
||||||
image_info -k Id "$@" | sed 's/.*\://' | sed 's/"//'
|
image_info -k Id "$@" | sed 's/.*\://' | sed 's/"//'
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,31 +2,28 @@
|
||||||
|
|
||||||
image_tag () {
|
image_tag () {
|
||||||
|
|
||||||
local DIR
|
local name; local remove; local id
|
||||||
DIR=$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P )
|
|
||||||
|
|
||||||
# tags an image
|
# tags an image
|
||||||
# -d -f <imagetag or id> <newimagetag>
|
# -i <imagetag or id> <newimagetag>
|
||||||
|
|
||||||
[[ $# -lt 1 ]] && echo "image base name required" && exit
|
[[ $# -lt 1 ]] && echo "image base name required" && exit
|
||||||
|
[[ $1 == "-r" ]] && remove=true && shift 1
|
||||||
|
|
||||||
[[ $1 == "-d" ]] && delete=true && shift 1
|
|
||||||
[[ $1 == "-f" ]] && force=true && shift 1
|
|
||||||
[[ $1 == "-i" ]] && { shift 1; id=$1; } || id=$(image_id $1)
|
[[ $1 == "-i" ]] && { shift 1; id=$1; } || id=$(image_id $1)
|
||||||
|
name=$(make_tag "$1")
|
||||||
|
[[ ! $id ]] && { echo "no image with id:$id name:$name"; return 1; }
|
||||||
|
|
||||||
[[ ! $id ]] && { echo "no image with id $id $(make_tag "@")"; return 1; }
|
if [[ $2 ]];then
|
||||||
|
# echo making tag for $2 $(make_tag $2)
|
||||||
|
|
||||||
[[ $force ]] && docker rmi -f $id && return 0
|
|
||||||
|
|
||||||
if [[ $delete ]];then
|
|
||||||
docker rmi $id
|
|
||||||
else
|
|
||||||
docker tag $id $(make_tag $2)
|
docker tag $id $(make_tag $2)
|
||||||
|
else
|
||||||
|
[[ $remove ]] && docker rmi $name || echo to remove an image tag use -r
|
||||||
fi
|
fi
|
||||||
echo tags after operation for image $id
|
image_tags $id
|
||||||
image_info -k RepoTags $id
|
}
|
||||||
|
|
||||||
|
image_delete () {
|
||||||
|
docker rmi -f "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue