diff --git a/scripts/cleanImages.sh b/scripts/cleanImages.sh old mode 100644 new mode 100755 diff --git a/scripts/pushDockerDigestTag.sh b/scripts/pushDockerDigestTag.sh old mode 100644 new mode 100755 index a705eb9e0e..9fa2ee353e --- a/scripts/pushDockerDigestTag.sh +++ b/scripts/pushDockerDigestTag.sh @@ -2,30 +2,76 @@ scriptName=`basename "$0"` -if [ "$#" -ne 2 ]; then - echo "Usage: ${scriptName} " +usage="Usage: $scriptName [options] + + -h , --help show this help text + -i a source image to use + (e.g. quay.io/alfresco/ags-share-community) + -r a repository to push new tags to + (e.g. registry.hub.docker.com) + -t the existing tag for the images (mandatory) + -d the length of digest to output (default 12 chars)" + +digestLength=12 + +while getopts ':hi:r:t:d:' option; do + case "$option" in + h) echo -e "Tag one or more images to include the digest and push this to some repositories.\n\n${usage}" + exit + ;; + i) sourceImages+=("$OPTARG") + ;; + r) repositories+=("$OPTARG") + ;; + t) existingTag=$OPTARG + ;; + d) digestLength=$OPTARG + ;; + :) echo -e "Missing argument for -${OPTARG}\n\n${usage}" >&2 + exit 1 + ;; + \?) echo -e "Illegal option: -${OPTARG}\n\n${usage}" >&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ "#$existingTag" == "#" ]; then + echo -e "Please supply a tag with the -t option.\n\n${usage}" >&2 exit 1 fi -echo "${scriptName} called with:" -image=$1 -echo " image: $image" -existingTag=$2 -echo " existingTag: $existingTag" +for sourceImage in ${sourceImages[@]} +do + echo "Processing $sourceImage" -DIGEST_LENGTH=12 + # Note that this command should work even if the image is already present locally. + digest=`docker pull ${sourceImage}:${existingTag} | grep "Digest:" | awk -F':' '{print $3}' | cut -c 1-$digestLength` -# Note that this command should work even if the image is already present locally. -digest=`docker pull ${image}:${existingTag} | grep "Digest:" | awk -F':' '{print $3}' | cut -c 1-$DIGEST_LENGTH` + if [ ${#digest} != $digestLength ] + then + echo "Unexpected length for digest of ${sourceImage}: '${digest}'" >&2 + exit 1 + fi -if [ ${#digest} != $DIGEST_LENGTH ] -then - echo "Unexpected length for digest: '$digest'" - exit 1 -fi + newTag=${existingTag}_${digest} -newTag=${existingTag}_${digest} -docker tag ${image}:${existingTag} ${image}:${newTag} -docker push ${image}:${newTag} + # Remove the source repository name if it contains one. + slashes=`echo $sourceImage | sed "s|[^/]||g"` + if [ ${#slashes} == 2 ] + then + # The repository name is everything up to the first slash. + image=`echo $sourceImage | sed "s|[^/]*/||"` + else + # Assume the source image doesn't reference the repository name. + image=$sourceImage + fi -echo "Pushed ${image}:${existingTag} to ${image}:${newTag}" + for repository in ${repositories[@]} + do + docker tag ${sourceImage}:${existingTag} ${repository}:${image}:${newTag} + docker push ${repository}:${image}:${newTag} + echo "Pushed ${sourceImage}:${existingTag} to ${repository}:${image}:${newTag}" + done +done diff --git a/scripts/waitForAlfrescoToStart.sh b/scripts/waitForAlfrescoToStart.sh old mode 100644 new mode 100755