From 50b15e58fc550871b9a0588a16322823c9467c7b Mon Sep 17 00:00:00 2001 From: "pavel.voropaev" Date: Sat, 18 Dec 2021 21:54:53 +0000 Subject: [PATCH] Fix cassandra tests --- .dockerignore | 4 ++- build/Dockerfile-cassandra | 6 ++++ build/cassandra-entrypoint.sh | 65 +++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 build/cassandra-entrypoint.sh diff --git a/.dockerignore b/.dockerignore index f59ec20aab..3ed725abfe 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ -* \ No newline at end of file +* +!/quill-cassandra/src/test/cql/cassandra-schema.cql +!/build/cassandra-entrypoint.sh diff --git a/build/Dockerfile-cassandra b/build/Dockerfile-cassandra index eec7840e98..f934ab04a1 100644 --- a/build/Dockerfile-cassandra +++ b/build/Dockerfile-cassandra @@ -2,3 +2,9 @@ FROM cassandra:3.11.11 MAINTAINER deusaquilus@gmail.com RUN apt-get update; DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends default-jdk +ENV LANG C.UTF-8 +COPY ./build/cassandra-entrypoint.sh /entrypoint.sh +RUN chmod 755 /entrypoint.sh +COPY ./quill-cassandra/src/test/cql/*.cql /docker-entrypoint-initdb.d/ +ENTRYPOINT ["/entrypoint.sh"] +CMD ["cassandra", "-f"] \ No newline at end of file diff --git a/build/cassandra-entrypoint.sh b/build/cassandra-entrypoint.sh new file mode 100644 index 0000000000..d6ac88d314 --- /dev/null +++ b/build/cassandra-entrypoint.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +## +## This script will generate a patched docker-entrypoint.sh that: +## - executes any *.sh script found in /docker-entrypoint-initdb.d +## - boots cassandra up +## - executes any *.cql script found in docker-entrypoint-initdb.d +## +## It is compatible with any cassandra:* image +## + + +## Create script that executes files found in docker-entrypoint-initdb.d/ + +cat <<'EOF' >> /run-init-scripts.sh +#!/usr/bin/env bash + +LOCK=/var/lib/cassandra/_init.done +INIT_DIR=docker-entrypoint-initdb.d + +if [ -f "$LOCK" ]; then + echo "@@ Initialization already performed." + exit 0 +fi + +cd $INIT_DIR + +echo "@@ Executing bash scripts found in $INIT_DIR" + +# execute scripts found in INIT_DIR +for f in $(find . -type f -name "*.sh" -executable -print | sort); do + echo "$0: sourcing $f" + . "$f" + echo "$0: $f executed." +done + +# wait for cassandra to be ready and execute cql in background +( + while ! cqlsh -e 'describe cluster' > /dev/null 2>&1; do sleep 6; done + echo "$0: Cassandra cluster ready: executing cql scripts found in $INIT_DIR" + for f in $(find . -type f -name "*.cql" -print | sort); do + echo "$0: running $f" + cqlsh -f "$f" + echo "$0: $f executed" + done + # mark things as initialized (in case /var/lib/cassandra was mapped to a local folder) + touch $LOCK +) & + +EOF + +## Patch existing entrypoint to call our script in the background +# This has been inspired by https://www.thetopsites.net/article/51594713.shtml +EP=/patched-entrypoint.sh +sed '$ d' /docker-entrypoint.sh > $EP +cat <<'EOF' >> $EP +/run-init-scripts.sh & +exec "$@" +EOF + +# Make both scripts executable +chmod +x /run-init-scripts.sh +chmod +x $EP + +# Call the new entrypoint +$EP "$@" \ No newline at end of file