uci-docker-build/try

62 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/bin/bash
file=try.yml
DIR=$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P )
#tags an images and pushes it to a <custom private> repository
# if not reposity is given will use docker.io and push to hub.docker.com
# $1 name, $2 user
declare -A arch=( ["x86_64"]="" ["aarch64"]="-arm64")
[[ $# -lt 1 ]] && echo "image name required to try" && exit
declare OPTION; declare OPTARG; declare OPTIND
while getopts 'pt:u:' OPTION; do
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
case "$OPTION" in
u)
RUSER=$OPTARG
;;
t)
TAG=$OPTARG
;;
p)
PROD=$OPTARG
;;
*) echo unknown run option -$OPTARG
echo "USAGE: try <options>"
echo "available options: -t <latest> custom tag "
;;
esac
done
shift $((OPTIND - 1))
# build up package tag
name=$1
user=${2:-$RUSER}
image=$([[ $user ]] && echo ${user}/)$name:${TAG:-latest}
if [[ $PROD ]]; then
echo removing any local copy of image $image
docker image rm $source
HOST=prod
else
HOST=local
image=${image/:/${arch[$(uname -p)]}:}
fi
echo starting container with image $image
export IMAGE=$image
export HOST
shopt -s extglob
export NAME=${image//+([^A-Za-z0-9])/-}
docker-compose -f $file down;
docker-compose -f $file up -d;
docker exec -it try-$NAME /bin/bash -l
docker-compose -f $file down;
# return to starting directory
# popd