2021-06-24 11:20:43 +02:00
|
|
|
#! /usr/bin/env bash
|
2022-06-06 16:36:16 +02:00
|
|
|
set -e
|
2021-06-24 11:20:43 +02:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
DOCKER_FILE=${DIR}/../docker/rhel_kafka/Dockerfile
|
|
|
|
PLUGIN_DIR="plugins"
|
|
|
|
EXTRA_LIBS=""
|
|
|
|
|
2022-05-24 23:16:53 +02:00
|
|
|
OPTS=$(getopt -o d:i:a:k:z:l:f:r:o:t:g: --long dir:,image:,archive-urls:,kafka-url:,dbz-scripts:,libs:,dockerfile:,registry:,organisation:,tags:,auto-tag:,dest-login:,dest-pass:,img-output: -n 'parse-options' -- "$@")
|
2021-06-24 11:20:43 +02:00
|
|
|
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
|
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-d | --dir ) BUILD_DIR=$2;
|
|
|
|
PLUGIN_DIR=${BUILD_DIR}/plugins; shift; shift ;;
|
|
|
|
-i | --image ) IMAGE=$2; shift; shift ;;
|
|
|
|
-a | --archive-urls ) ARCHIVE_URLS=$2; shift; shift ;;
|
|
|
|
-k | --kafka-url ) KAFKA_URL=$2; shift; shift ;;
|
2022-05-24 23:16:53 +02:00
|
|
|
-z | --dbz-scripts ) DEBEZIUM_VERSION=$2; shift; shift ;;
|
2021-06-24 11:20:43 +02:00
|
|
|
-l | --libs ) EXTRA_LIBS=$2; shift; shift ;;
|
|
|
|
-f | --dockerfile ) DOCKER_FILE=$2; shift; shift ;;
|
|
|
|
-r | --registry ) REGISTRY=$2; shift; shift ;;
|
|
|
|
-o | --organisation ) ORGANISATION=$2; shift; shift ;;
|
2021-11-03 12:11:45 +01:00
|
|
|
-t | --tags ) TAGS=$2; shift; shift ;;
|
|
|
|
-g | --auto-tag ) AUTO_TAG=$2; shift; shift ;;
|
2021-09-14 13:16:15 +02:00
|
|
|
--dest-login ) DEST_LOGIN=$2; shift; shift ;;
|
|
|
|
--dest-pass ) DEST_PASS=$2; shift; shift ;;
|
2021-06-24 11:20:43 +02:00
|
|
|
--img-output ) IMAGE_OUTPUT_FILE=$2; shift; shift ;;
|
|
|
|
-h | --help ) PRINT_HELP=true; shift ;;
|
|
|
|
-- ) shift; break ;;
|
|
|
|
* ) break ;;
|
|
|
|
esac
|
|
|
|
done
|
2022-01-17 14:20:29 +01:00
|
|
|
if [ -z "${TAGS}" ] && [ "${AUTO_TAG}" = "false" ]; then
|
2021-11-03 12:11:45 +01:00
|
|
|
echo "Cannot push image without tag." >&2 ; exit 1 ;
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
|
2021-06-24 11:20:43 +02:00
|
|
|
echo "Creating plugin directory ${PLUGIN_DIR}"
|
|
|
|
mkdir -p "${PLUGIN_DIR}"
|
|
|
|
|
2021-09-14 13:16:15 +02:00
|
|
|
pushd "${PLUGIN_DIR}" || exit
|
2021-06-24 11:20:43 +02:00
|
|
|
for archive in ${ARCHIVE_URLS}; do
|
|
|
|
echo "[Processing] ${archive}"
|
|
|
|
curl -OJs "${archive}" && unzip \*.zip && rm *.zip
|
2021-08-05 12:52:50 +02:00
|
|
|
connectors_version=$(echo "$archive" | sed -rn 's|.*AMQ-CDC-(.*)/.*$|\1|p')
|
2022-10-25 14:33:33 +02:00
|
|
|
|
|
|
|
if [ -z "$connectors_version" ]; then
|
|
|
|
echo "[Processing] unable to parse connectors version, trying different approach"
|
|
|
|
connectors_version=$(echo "$archive" | rev | cut -d '/' -f 1 | rev | cut -d '-' -f 2)
|
|
|
|
fi
|
|
|
|
echo "[Processing] connectors version is ${connectors_version}"
|
2021-06-24 11:20:43 +02:00
|
|
|
done
|
|
|
|
|
2022-06-07 18:15:07 +02:00
|
|
|
connector_dirs=$(ls)
|
|
|
|
|
2021-06-24 11:20:43 +02:00
|
|
|
for input in ${EXTRA_LIBS}; do
|
2021-08-05 16:09:46 +02:00
|
|
|
echo "[Processing] ${input} "
|
2021-06-24 11:20:43 +02:00
|
|
|
lib=$(echo ${input} | awk -F "::" '{print $1}' | xargs)
|
|
|
|
dest=$(echo ${input} | awk -F "::" '{print $2}' | xargs)
|
|
|
|
|
|
|
|
curl -OJs "${lib}"
|
2022-06-07 18:15:07 +02:00
|
|
|
if [[ "${dest}" == '*' ]] ; then
|
|
|
|
if [[ "${lib}" =~ ^.*\.zip$ ]] ; then
|
|
|
|
echo $connector_dirs | xargs -n 1 unzip -o \*.zip -d
|
|
|
|
rm *.zip
|
|
|
|
else
|
|
|
|
echo $connector_dirs | xargs -n 1 cp *.jar
|
|
|
|
rm *.jar
|
|
|
|
fi
|
|
|
|
continue;
|
|
|
|
fi
|
|
|
|
if [[ "${lib}" =~ ^.*\.zip$ ]] ; then
|
|
|
|
unzip -od "${dest}" \*.zip && rm *.zip
|
|
|
|
else
|
|
|
|
mv *.jar "${dest}"
|
|
|
|
fi
|
2021-06-24 11:20:43 +02:00
|
|
|
done
|
2021-09-14 13:16:15 +02:00
|
|
|
popd || exit
|
2021-06-24 11:20:43 +02:00
|
|
|
|
|
|
|
echo "Copying Docker_entrypoint.sh and scripts to" "${BUILD_DIR}"
|
|
|
|
cp "${DIR}"/../docker/rhel_kafka/* "$BUILD_DIR"
|
|
|
|
|
2021-08-05 12:52:50 +02:00
|
|
|
echo "Copying Dockerfile to" "${BUILD_DIR}"
|
|
|
|
cp "$DOCKER_FILE" "$BUILD_DIR"
|
|
|
|
|
2021-11-03 12:11:45 +01:00
|
|
|
amq_version=$(echo "${KAFKA_URL}" | sed -rn 's|.*AMQ-STREAMS-(.*)/.*$|\1|p')
|
2022-06-21 15:22:34 +02:00
|
|
|
image_dbz=dbz-rhel-kafka
|
2021-11-03 12:11:45 +01:00
|
|
|
target=${REGISTRY}/${ORGANISATION}/${image_dbz}:amq-${amq_version}-dbz-${connectors_version}
|
2021-06-24 11:20:43 +02:00
|
|
|
|
2021-09-14 13:16:15 +02:00
|
|
|
pushd "${BUILD_DIR}" || exit
|
2021-08-05 12:52:50 +02:00
|
|
|
#change absolute path of PLUGIN_DIR to relative so docker doesnt crash
|
|
|
|
PLUGIN_DIR_BUILDARG="./${PLUGIN_DIR##*/}"
|
|
|
|
|
2021-06-24 11:20:43 +02:00
|
|
|
echo "[Build] Building ${image_dbz} from ${IMAGE}"
|
2022-05-24 23:16:53 +02:00
|
|
|
docker build . -t "$target" --build-arg IMAGE="${IMAGE}" --build-arg KAFKA_SOURCE_PATH="${KAFKA_URL}" --build-arg DEBEZIUM_CONNECTORS="${PLUGIN_DIR_BUILDARG}" --build-arg DEBEZIUM_VERSION="${DEBEZIUM_VERSION}"|| exit
|
2021-09-14 13:16:15 +02:00
|
|
|
popd || exit
|
|
|
|
|
2022-01-17 14:20:29 +01:00
|
|
|
if [ "${AUTO_TAG}" = "true" ] ; then
|
2021-11-03 12:11:45 +01:00
|
|
|
echo "[Build] Pushing image ${target}"
|
|
|
|
docker push ${target}
|
|
|
|
[[ -z "${IMAGE_OUTPUT_FILE}" ]] || echo $target >> ${IMAGE_OUTPUT_FILE}
|
|
|
|
fi
|
2021-09-14 13:16:15 +02:00
|
|
|
|
2021-11-03 12:11:45 +01:00
|
|
|
for tag in ${TAGS}; do
|
|
|
|
new_target="${REGISTRY}/${ORGANISATION}/${image_dbz}:${tag}"
|
|
|
|
echo "[Build] Pushing image ${new_target}"
|
|
|
|
docker tag "${target}" "${new_target}"
|
|
|
|
docker push "${new_target}"
|
|
|
|
[[ -z "${IMAGE_OUTPUT_FILE}" ]] || echo "$new_target" >> ${IMAGE_OUTPUT_FILE}
|
|
|
|
done
|