2021-06-24 11:20:43 +02:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
DOCKER_FILE=${DIR}/../docker/rhel_kafka/Dockerfile
|
|
|
|
PLUGIN_DIR="plugins"
|
|
|
|
EXTRA_LIBS=""
|
|
|
|
|
2021-08-05 12:52:50 +02:00
|
|
|
OPTS=$(getopt -o d:i:a:k:l:f:r:o:t: --long dir:,image:,archive-urls:,kafka-url:,libs:,dockerfile:,registry:,organisation:,tag:,dest-creds:,src-creds:,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 ;;
|
|
|
|
-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-08-05 12:52:50 +02:00
|
|
|
-t | --tag ) TAG=$2; shift; shift ;;
|
2021-06-24 11:20:43 +02:00
|
|
|
--dest-creds ) DEST_CREDS="--dest-creds $2"; shift; shift ;;
|
|
|
|
--src-creds ) SRC_CREDS="--src-creds $2"; shift; shift ;;
|
|
|
|
--img-output ) IMAGE_OUTPUT_FILE=$2; shift; shift ;;
|
|
|
|
-h | --help ) PRINT_HELP=true; shift ;;
|
|
|
|
-- ) shift; break ;;
|
|
|
|
* ) break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Creating plugin directory ${PLUGIN_DIR}"
|
|
|
|
mkdir -p "${PLUGIN_DIR}"
|
|
|
|
|
|
|
|
pushd "${PLUGIN_DIR}"
|
|
|
|
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')
|
2021-06-24 11:20:43 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
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}"
|
|
|
|
if [[ "${lib}" =~ ^.*\.zip$ ]] ; then
|
|
|
|
unzip -od ${dest} \*.zip && rm *.zip
|
|
|
|
else
|
|
|
|
mv *.jar "${dest}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
popd
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
if [ -z "$TAG" ] ; then
|
|
|
|
amq_version=$(echo "${KAFKA_URL}" | sed -rn 's|.*AMQ-STREAMS-(.*)/.*$|\1|p')
|
|
|
|
image_dbz=debezium-testing-rhel8:amq-${amq_version}-dbz-${connectors_version}
|
|
|
|
target=${REGISTRY}/${ORGANISATION}/${image_dbz}
|
|
|
|
else
|
|
|
|
target=$TAG
|
|
|
|
fi
|
2021-06-24 11:20:43 +02:00
|
|
|
|
|
|
|
pushd "${BUILD_DIR}"
|
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}"
|
2021-08-05 12:52:50 +02:00
|
|
|
docker build . -t "$target" --build-arg IMAGE="${IMAGE}" --build-arg KAFKA_SOURCE_PATH="${KAFKA_URL}" --build-arg DEBEZIUM_CONNECTORS="${PLUGIN_DIR_BUILDARG}"
|
|
|
|
popd
|
2021-06-24 11:20:43 +02:00
|
|
|
echo "[Build] Pushing image ${target}"
|
|
|
|
skopeo --override-os "linux" copy --src-tls-verify=false ${DEST_CREDS} "docker-daemon:${target}" "docker://$target"
|
|
|
|
[[ -z "${IMAGE_OUTPUT_FILE}" ]] || echo $target >> ${IMAGE_OUTPUT_FILE}
|