@@ -15,13 +15,21 @@ usage() {
1515# If the query fails for any reason, prints an error and *exits* nonzero.
1616#
1717# This function cribbed from:
18- # https://github.com/openshift/boilerplate/blob/d2d6640ef28a7ce54ac639db32c825aa4bb492a0 /boilerplate/_lib/common.sh#L77-L125
18+ # https://github.com/openshift/boilerplate/blob/0ba6566d544d0df9993a92b2286c131eb61f3e88 /boilerplate/_lib/common.sh#L77-L135
1919# ...then adapted to use docker rather than skopeo.
2020image_exists_in_repo () {
2121 local image_uri=$1
2222 local output
23+ local rc
24+ local skopeo_stderr
2325
24- if output=$( docker image pull " ${image_uri} " 2>&1 ) ; then
26+ skopeo_stderr=$( mktemp)
27+ output=$( docker image pull " ${image_uri} " 2> " $skopeo_stderr " )
28+ rc=$?
29+ # So we can delete the temp file right away...
30+ stderr=$( cat " $skopeo_stderr " )
31+ rm -f " $skopeo_stderr "
32+ if [[ $rc -eq 0 ]]; then
2533 # The image exists. Sanity check the output.
2634 local report
2735 if report=$( docker image inspect " ${image_uri} " 2>&1 ) ; then
@@ -31,6 +39,8 @@ image_exists_in_repo() {
3139 echo " Unexpected error: docker inspect succeeded, but output contained no digest."
3240 echo " Here's the inspect output:"
3341 echo " $report "
42+ echo " ...and stderr:"
43+ echo " $stderr "
3444 exit 1
3545 fi
3646 # Happy path: image exists
@@ -41,12 +51,12 @@ image_exists_in_repo() {
4151 echo " Here's the output:"
4252 echo " $report "
4353 exit 1
44- elif [[ " $output " == * " manifest for" * " not found" * ]]; then
54+ elif [[ " $stderr " == * " manifest for" * " not found" * ]]; then
4555 # We were able to talk to the repository, but the tag doesn't exist.
4656 # This is the normal "green field" case.
4757 echo " Image ${image_uri} does not exist in the repository."
4858 return 1
49- elif [[ " $output " == * " was deleted or has expired" * ]]; then
59+ elif [[ " $stderr " == * " was deleted or has expired" * ]]; then
5060 # This should be rare, but accounts for cases where we had to
5161 # manually delete an image.
5262 echo " Image ${image_uri} was deleted from the repository."
@@ -62,7 +72,8 @@ image_exists_in_repo() {
6272 # In all these cases, we want to bail, because we don't know whether
6373 # the image exists (and we'd likely fail to push it anyway).
6474 echo " Error querying the repository for ${image_uri} :"
65- echo " $output "
75+ echo " stdout: $output "
76+ echo " stderr: $stderr "
6677 exit 1
6778 fi
6879}
0 commit comments