2020-02-20 14:45:48 +01:00
|
|
|
#! /usr/bin/env bash
|
2022-06-06 16:36:16 +02:00
|
|
|
set -e
|
2020-02-20 14:45:48 +01:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
COPY_IMAGES=true
|
|
|
|
REGISTRY="quay.io"
|
|
|
|
|
2021-09-14 13:16:15 +02:00
|
|
|
OPTS=`getopt -o d:i:r:o:f:s --long dir:,images:,registry:,organisation:,deployment-desc:,skip-copy,dest-login:,dest-pass:,img-output: -n 'parse-options' -- "$@"`
|
2020-02-20 14:45:48 +01:00
|
|
|
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
|
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-d | --dir ) INSTALL_SOURCE_DIR=$2; shift; shift ;;
|
|
|
|
-i | --images ) IMAGES=$2; shift; shift ;;
|
|
|
|
-r | --registry ) REGISTRY=$2; shift; shift ;;
|
|
|
|
-o | --organisation ) ORGANISATION=$2; shift; shift ;;
|
2020-11-10 13:56:49 +01:00
|
|
|
-f | --deployment-desc ) DEPLOYMENT_DESC=$2; shift; shift ;;
|
2020-02-20 14:45:48 +01:00
|
|
|
-s | --skip-copy ) COPY_IMAGES=false; shift ;;
|
2021-09-14 13:16:15 +02:00
|
|
|
--dest-login ) DEST_LOGIN=$2; shift; shift ;;
|
|
|
|
--dest-pass ) DEST_PASS=$2; shift; shift ;;
|
2020-02-20 14:45:48 +01:00
|
|
|
--img-output ) IMAGE_OUTPUT_FILE=$2; shift; shift ;;
|
|
|
|
-h | --help ) PRINT_HELP=true; shift ;;
|
|
|
|
-- ) shift; break ;;
|
|
|
|
* ) break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-09-13 15:18:58 +02:00
|
|
|
if [ ! -z "${DEST_LOGIN}" ] ; then
|
2021-09-14 13:16:15 +02:00
|
|
|
docker login -u "${DEST_LOGIN}" -p "${DEST_PASS}" "${REGISTRY}"
|
|
|
|
fi
|
|
|
|
|
2020-02-20 14:45:48 +01:00
|
|
|
function process_image() {
|
|
|
|
source=$1
|
|
|
|
registry=$2
|
|
|
|
organisation=$3
|
|
|
|
|
2021-08-24 18:45:27 +02:00
|
|
|
prefix=`echo $source | sed -rn 's|.*/[^/]+/([^-]*)-(.*):(.*)$|\1|p'`
|
|
|
|
name=`echo $source | sed -rn 's|.*/[^/]+/([^-]*)-(.*):(.*)$|\2|p'`
|
|
|
|
tag=`echo $source | sed -rn 's|.*/[^/]+/([^-]*)-(.*):(.*)$|\3|p'`
|
2020-02-20 14:45:48 +01:00
|
|
|
target=${registry}/${organisation}/${prefix}-${name}:${tag}
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$COPY_IMAGES" = true ] ; then
|
2021-09-14 13:16:15 +02:00
|
|
|
echo "[Image Copy] Pushing image $source as $target"
|
|
|
|
docker pull "$source"
|
|
|
|
docker tag "$source" "$target"
|
|
|
|
docker push "$target"
|
2020-02-20 14:45:48 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Replace images
|
|
|
|
echo "[Deployment Transformation] replacing image ${target}"
|
2020-11-10 13:56:49 +01:00
|
|
|
sed -i "s@registry.redhat.io/.*/${name}:.*\$@${target}@" "${INSTALL_SOURCE_DIR}/${DEPLOYMENT_DESC}"
|
2021-08-25 09:51:24 +02:00
|
|
|
[[ -z "${IMAGE_OUTPUT_FILE}" ]] || echo $target >> ${IMAGE_OUTPUT_FILE}
|
2020-02-20 14:45:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for image in $IMAGES; do
|
|
|
|
echo "[Processing] $image"
|
|
|
|
process_image $image $REGISTRY $ORGANISATION
|
|
|
|
done
|