diff --git a/xfce-test b/xfce-test index 165b90a..d9a00c5 100755 --- a/xfce-test +++ b/xfce-test @@ -6,6 +6,7 @@ RUN_AS= LOG=${LOG:-/dev/stdout} PARALLEL_BUILDS=${PARALLEL_BUILDS:-0} TRAVIS=${TRAVIS:-FALSE} +TAG=${TAG:-latest} is_my_git() { if git remote -v 2>/dev/null|grep "schuellerf/xfce-test" &>/dev/null; then @@ -84,6 +85,38 @@ get-free-display(){ done } +# checks that the passed tag ($1) is available on Dockerhub or locally ($2) +validate_tag(){ + TAG="$1" + + # check against whatever $2 is + case "$2" in + "Dockerhub") + tags="$(get_tags)" + location="on Dockerhub" + ;; + "local") + tags="$(get_local_tags)" + location="locally" + ;; + esac + + for t in ${tags}; do + if [ "${t}" = "${TAG}" ]; then + return 0 + fi + done + + # the specified tag doesn't exist on Dockerhub or locally, + # so we list the available ones and return non-zero exit code + printf "The tag '%s' was not found %s\n" "${TAG}" "${location}" + printf -- "---\n" + printf "The following tags are available %s:\n" "${location}" + printf "%s\n" "${tags}" + return 1 +} + + # use this X display number for the tests export DISPLAY_NUM=$(get-free-display) @@ -194,17 +227,6 @@ MODES_FOR_CASE=$(IFS=$'|'; echo "${WORK_MODES[*]}") shopt -s extglob MODES_FOR_CASE="+($MODES_FOR_CASE)" -if [ -z $TAG ]; then - if is_my_git; then - TAG=$(git rev-parse --abbrev-ref HEAD 2>/dev/null|tr '/' '_') - if [[ $TAG == "last_tag" ]]; then - TAG=latest - fi - else - TAG=latest - fi -fi - if [ $# -ge 1 ]; then case $1 in "install") @@ -227,7 +249,10 @@ if [ $# -ge 1 ]; then ;; "pull") if [ -n "$2" ]; then - TAG=$2 + TAG="$2" + if ! validate_tag "${TAG}" "Dockerhub"; then + exit 2 + fi fi mode=$1 ;; @@ -439,6 +464,14 @@ case $mode in ;; esac +# check whether the tag the user passed is actually valid +if ! validate_tag "${TAG}" "Dockerhub" && \ + ! ( printf "Attempting to find the tag '%s' locally...\n" "${TAG}" && \ + validate_tag "${TAG}" "local" ); then + printf "Unable to find the tag '%s' either on Dockerhub or locally, exiting...\n" "${TAG}" + exit 1 +fi + echo "You are working with the container: $TAG" # This starts the container for manual or semi automated tests