parent
c343cbb148
commit
f2c9be5c29
|
@ -1,3 +1,4 @@
|
|||
/archive/
|
||||
/build.log
|
||||
_opt/
|
||||
.src
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
make_tag () {
|
||||
|
||||
local DIR
|
||||
DIR=$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P )
|
||||
local tag
|
||||
|
||||
# generate a full image name with tag
|
||||
# $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
|
||||
|
||||
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}
|
||||
case "$OPTION" in
|
||||
d)
|
||||
delete=true
|
||||
;;
|
||||
r)
|
||||
REPO=$OPTARG
|
||||
;;
|
||||
|
@ -38,12 +34,13 @@ done
|
|||
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
# image tag
|
||||
name=$1
|
||||
tag=$( echo $1 | cut -s -d ":" -f2)
|
||||
tag=${tag:-$TAG}
|
||||
name=${1%:*}
|
||||
user=${2:-$RUSER}
|
||||
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
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
image_info () {
|
||||
[[ $1 == "-k" ]] && key=$2 && shift 2
|
||||
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
|
||||
if [[ $key ]]; then
|
||||
# echo image: $tag, key:$key
|
||||
|
@ -20,6 +22,10 @@ image_arch () {
|
|||
image_info -k Architecture "$@"
|
||||
}
|
||||
|
||||
image_tags () {
|
||||
image_info -k RepoTags "$@"
|
||||
}
|
||||
|
||||
image_id () {
|
||||
image_info -k Id "$@" | sed 's/.*\://' | sed 's/"//'
|
||||
}
|
||||
|
|
|
@ -2,31 +2,28 @@
|
|||
|
||||
image_tag () {
|
||||
|
||||
local DIR
|
||||
DIR=$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P )
|
||||
local name; local remove; local id
|
||||
|
||||
# tags an image
|
||||
# -d -f <imagetag or id> <newimagetag>
|
||||
# -i <imagetag or id> <newimagetag>
|
||||
|
||||
[[ $# -lt 1 ]] && echo "image base name required" && exit
|
||||
|
||||
|
||||
[[ $1 == "-d" ]] && delete=true && shift 1
|
||||
[[ $1 == "-f" ]] && force=true && shift 1
|
||||
[[ $1 == "-r" ]] && remove=true && shift 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; }
|
||||
|
||||
|
||||
[[ $force ]] && docker rmi -f $id && return 0
|
||||
|
||||
if [[ $delete ]];then
|
||||
docker rmi $id
|
||||
else
|
||||
if [[ $2 ]];then
|
||||
# echo making tag for $2 $(make_tag $2)
|
||||
docker tag $id $(make_tag $2)
|
||||
else
|
||||
[[ $remove ]] && docker rmi $name || echo to remove an image tag use -r
|
||||
fi
|
||||
echo tags after operation for image $id
|
||||
image_info -k RepoTags $id
|
||||
image_tags $id
|
||||
}
|
||||
|
||||
image_delete () {
|
||||
docker rmi -f "$@"
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue