diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-09-14 15:46:49 +0200 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-09-14 15:46:49 +0200 |
commit | 79657f94a9ecf272736e3e52c5ca5e5bca60bf00 (patch) | |
tree | ab4f5ab50b4ed5114c905c8fe25cd8ccc74625b6 /scripts/xds-docker-create-container.sh | |
parent | bc3ffe4a0087b655bdfaf70dfa7bac6d840eb7ab (diff) |
Dynamically retrieve docker image name/version
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'scripts/xds-docker-create-container.sh')
-rwxr-xr-x | scripts/xds-docker-create-container.sh | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/scripts/xds-docker-create-container.sh b/scripts/xds-docker-create-container.sh index 9eafeef..2db3e5f 100755 --- a/scripts/xds-docker-create-container.sh +++ b/scripts/xds-docker-create-container.sh @@ -30,16 +30,6 @@ VERSION=4.0 DOCKER_USER=devel DEFIMAGE=$REGISTRY/$REPO/$NAME-$FLAVOUR:$VERSION -docker images |grep $DEFIMAGE 2>&1 > /dev/null -if [ "$?" = "1" ]; then - VERSION=`docker images $REGISTRY/$REPO/$NAME-$FLAVOUR:* --format "{{.Tag}}"` - if [ "$VERSION" = "" ]; then - echo "ERROR: cannot automatically retrieve image tag for $REGISTRY/$REPO/$NAME-$FLAVOUR" - exit 1 - fi - DEFIMAGE=$REGISTRY/$REPO/$NAME-$FLAVOUR:$VERSION -fi - function usage() { echo "Usage: $(basename $0) <instance ID> [image name]" >&2 @@ -50,7 +40,7 @@ function usage() { } ID="" -IMAGE=$DEFIMAGE +IMAGE="" FORCE_RESTART=false UPDATE_UID=true while [ $# -ne 0 ]; do @@ -77,6 +67,28 @@ done [ "$ID" = "" ] && ID=0 +# Dynamically retrieve image name +if [ "$IMAGE" = "" ]; then + + VER_NUM=`docker images $REGISTRY/$REPO/$NAME-$FLAVOUR:* --format {{.Tag}} | wc -l` + if [ $VER_NUM -gt 1 ]; then + echo "ERROR: more than one xds image found, please set explicitly the image to use !" + exit 1 + elif [ $VER_NUM -lt 1 ]; then + echo "ERROR: cannot automatically retrieve image tag for $REGISTRY/$REPO/$NAME-$FLAVOUR" + exit 1 + fi + + VERSION=`docker images $REGISTRY/$REPO/$NAME-$FLAVOUR:* --format {{.Tag}}` + if [ "$VERSION" = "" ]; then + echo "ERROR: cannot automatically retrieve image tag for $REGISTRY/$REPO/$NAME-$FLAVOUR" + usage + exit 1 + fi + + IMAGE=$REGISTRY/$REPO/$NAME-$FLAVOUR:$VERSION +fi + USER=$(id -un) echo "Using instance ID #$ID (user $(id -un))" |