-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
* | ||
* | ||
!/quill-cassandra/src/test/cql/cassandra-schema.cql | ||
!/build/cassandra-entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,9 @@ FROM cassandra:3.11.11 | |
MAINTAINER [email protected] | ||
|
||
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters