From be8b920fe8272a839e57a6ab0e90057283db5aad Mon Sep 17 00:00:00 2001 From: JCGoran Date: Thu, 11 Mar 2021 19:01:46 +0100 Subject: [PATCH 1/5] Modify parsing of tags (fixes #41) Instead of Git tags, it now parses Dockerhub tags instead. Additionally, now it always uses 'latest' as the default tag. --- xfce-test | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/xfce-test b/xfce-test index 165b90a..76f7d34 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='latest' is_my_git() { if git remote -v 2>/dev/null|grep "schuellerf/xfce-test" &>/dev/null; then @@ -84,6 +85,30 @@ get-free-display(){ done } +# checks that the passed tag is available on Dockerhub +validate_tag(){ + if [ $# -ne 1 ]; then + printf "ERROR: you need to supply one argument!\n" + exit 1 + fi + TAG="$1" + if [ -z "${TAG}" ]; then + TAG='latest' + return 0 + else + # check the tag is valid + tags="$(get_tags)" + for t in ${tags}; do + if [ "${t}" = "${TAG}" ]; then + return 0 + fi + done + # the specified tag doesn't exist on Dockerhub + return 1 + fi +} + + # use this X display number for the tests export DISPLAY_NUM=$(get-free-display) @@ -194,17 +219,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 +241,11 @@ if [ $# -ge 1 ]; then ;; "pull") if [ -n "$2" ]; then - TAG=$2 + TAG="$2" + if ! validate_tag "${TAG}"; then + printf "The tag '%s' was not found on Dockerhub\n" "${TAG}" + exit 2 + fi fi mode=$1 ;; From ed5e6472c8ee2ae0a9ef5d377600dcafe8af6992 Mon Sep 17 00:00:00 2001 From: JCGoran Date: Mon, 15 Mar 2021 13:12:02 +0100 Subject: [PATCH 2/5] Fix for default tag See: https://github.com/schuellerf/xfce-test/pull/43#discussion_r593921459 --- xfce-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xfce-test b/xfce-test index 76f7d34..e2635c9 100755 --- a/xfce-test +++ b/xfce-test @@ -6,7 +6,7 @@ RUN_AS= LOG=${LOG:-/dev/stdout} PARALLEL_BUILDS=${PARALLEL_BUILDS:-0} TRAVIS=${TRAVIS:-FALSE} -TAG='latest' +TAG=${TAG:-latest} is_my_git() { if git remote -v 2>/dev/null|grep "schuellerf/xfce-test" &>/dev/null; then From a6ba79bb641b0ca9cf50c4170e09348a151fb531 Mon Sep 17 00:00:00 2001 From: JCGoran Date: Mon, 15 Mar 2021 13:13:11 +0100 Subject: [PATCH 3/5] Fix for error message on tags See: https://github.com/schuellerf/xfce-test/pull/43#discussion_r593921802 --- xfce-test | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/xfce-test b/xfce-test index e2635c9..30d04f3 100755 --- a/xfce-test +++ b/xfce-test @@ -87,25 +87,21 @@ get-free-display(){ # checks that the passed tag is available on Dockerhub validate_tag(){ - if [ $# -ne 1 ]; then - printf "ERROR: you need to supply one argument!\n" - exit 1 - fi TAG="$1" - if [ -z "${TAG}" ]; then - TAG='latest' - return 0 - else - # check the tag is valid - tags="$(get_tags)" - for t in ${tags}; do - if [ "${t}" = "${TAG}" ]; then - return 0 - fi - done - # the specified tag doesn't exist on Dockerhub - return 1 - fi + # check the tag is valid + tags="$(get_tags)" + for t in ${tags}; do + if [ "${t}" = "${TAG}" ]; then + return 0 + fi + done + + # the specified tag doesn't exist on Dockerhub, + # so we list the available ones and return non-zero exit code + printf "The tag '%s' was not found on Dockerhub\n" "${TAG}" + printf "The following tags are available on Dockerhub:\n" + printf "%s\n" "${tags}" + return 1 } @@ -243,7 +239,6 @@ if [ $# -ge 1 ]; then if [ -n "$2" ]; then TAG="$2" if ! validate_tag "${TAG}"; then - printf "The tag '%s' was not found on Dockerhub\n" "${TAG}" exit 2 fi fi From 53ce0033009b01f48f438ffee1dd261e986688e5 Mon Sep 17 00:00:00 2001 From: JCGoran Date: Mon, 15 Mar 2021 23:16:26 +0100 Subject: [PATCH 4/5] Improved fix for validating the tags --- xfce-test | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/xfce-test b/xfce-test index 30d04f3..1078e1d 100755 --- a/xfce-test +++ b/xfce-test @@ -85,21 +85,33 @@ get-free-display(){ done } -# checks that the passed tag is available on Dockerhub +# checks that the passed tag ($1) is available on Dockerhub or locally ($2) validate_tag(){ TAG="$1" - # check the tag is valid - tags="$(get_tags)" + + # 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, + # 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 on Dockerhub\n" "${TAG}" - printf "The following tags are available on Dockerhub:\n" + printf "The tag '%s' was not found %s\n" "${TAG}" "${location}" >&2 + printf -- "---\n" + printf "The following tags are available %s:\n" "${location}" printf "%s\n" "${tags}" return 1 } @@ -238,7 +250,7 @@ if [ $# -ge 1 ]; then "pull") if [ -n "$2" ]; then TAG="$2" - if ! validate_tag "${TAG}"; then + if ! validate_tag "${TAG}" "Dockerhub"; then exit 2 fi fi @@ -452,6 +464,13 @@ case $mode in ;; esac +# check whether the tag the user passed is actually valid +if ! validate_tag "${TAG}" "Dockerhub" >/dev/null && \ + ! ( printf "Attempting to find the tag '%s' locally...\n" "${TAG}" && \ + validate_tag "${TAG}" "local" >/dev/null ); then + exit 1 +fi + echo "You are working with the container: $TAG" # This starts the container for manual or semi automated tests From 93083114be42355f9f0e0f2847ed1ed69c6df61d Mon Sep 17 00:00:00 2001 From: JCGoran Date: Mon, 15 Mar 2021 23:27:27 +0100 Subject: [PATCH 5/5] Increase verbosity in case of an invalid tag --- xfce-test | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xfce-test b/xfce-test index 1078e1d..d9a00c5 100755 --- a/xfce-test +++ b/xfce-test @@ -109,7 +109,7 @@ validate_tag(){ # 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}" >&2 + 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}" @@ -465,9 +465,10 @@ case $mode in esac # check whether the tag the user passed is actually valid -if ! validate_tag "${TAG}" "Dockerhub" >/dev/null && \ +if ! validate_tag "${TAG}" "Dockerhub" && \ ! ( printf "Attempting to find the tag '%s' locally...\n" "${TAG}" && \ - validate_tag "${TAG}" "local" >/dev/null ); then + validate_tag "${TAG}" "local" ); then + printf "Unable to find the tag '%s' either on Dockerhub or locally, exiting...\n" "${TAG}" exit 1 fi