RM-6428 Handle multiple source images and multiple destinations.

Also update the scripts to be executable.
This commit is contained in:
Tom Page
2018-07-17 14:50:52 +01:00
parent 0df03c3b04
commit e00b4997e9
3 changed files with 65 additions and 19 deletions

0
scripts/cleanImages.sh Normal file → Executable file
View File

84
scripts/pushDockerDigestTag.sh Normal file → Executable file
View File

@@ -2,30 +2,76 @@
scriptName=`basename "$0"`
if [ "$#" -ne 2 ]; then
echo "Usage: ${scriptName} <imageName> <existingTag>"
usage="Usage: $scriptName [options]
-h , --help show this help text
-i <sourceImage> a source image to use
(e.g. quay.io/alfresco/ags-share-community)
-r <repository> a repository to push new tags to
(e.g. registry.hub.docker.com)
-t <tag> the existing tag for the images (mandatory)
-d <digestLength> 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} != $DIGEST_LENGTH ]
then
echo "Unexpected length for digest: '$digest'"
if [ ${#digest} != $digestLength ]
then
echo "Unexpected length for digest of ${sourceImage}: '${digest}'" >&2
exit 1
fi
fi
newTag=${existingTag}_${digest}
docker tag ${image}:${existingTag} ${image}:${newTag}
docker push ${image}:${newTag}
newTag=${existingTag}_${digest}
echo "Pushed ${image}:${existingTag} to ${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
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

0
scripts/waitForAlfrescoToStart.sh Normal file → Executable file
View File