Skip to content

Instantly share code, notes, and snippets.

@awalterschulze
Created October 6, 2017 13:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awalterschulze/7732a15b555facdd9399b7f8ed9b88bf to your computer and use it in GitHub Desktop.
Save awalterschulze/7732a15b555facdd9399b7f8ed9b88bf to your computer and use it in GitHub Desktop.
Run a cassandra in a docker with preloaded data
version: "2"
services:
cassandra:
build: docker/cassandra
ports:
- "9042:9042"
- "7199:7199"
FROM cassandra:3.1.1
RUN mkdir -p /tmp/var/lib/cassandra /etc/cassandra \
&& chown -R cassandra:cassandra /tmp/var/lib/cassandra /etc/cassandra \
&& chmod 777 /tmp/var/lib/cassandra /etc/cassandra
RUN sed -i "s~/var/lib/cassandra~/tmp/var/lib/cassandra~g" /etc/cassandra/cassandra.yaml
COPY *.cql /tmp/
RUN cassandra \
&& while [ $(cqlsh -e "USE system" || echo 1) ]; do sleep 0.5; done \
&& echo 'waited for cassandra startup and now setting up myprojectname keyspace...' \
&& cqlsh localhost 9042 -f /tmp/keyspace.cql \
&& echo 'creating schemas...' \
&& cqlsh localhost 9042 -f /tmp/schema.cql \
&& echo 'insert some values...' \
&& cqlsh localhost 9042 -f /tmp/insert.cql \
&& echo 'flushing cassandra...' \
&& nodetool flush myprojectname \
&& echo 'done!'
HEALTHCHECK --interval=1s --timeout=1s --retries=1 CMD cqlsh -e "USE myprojectname"
RUN chmod -R 777 /tmp/var/lib/cassandra /etc/cassandra
INSERT INTO myprojectname.tenant(columnname) VALUES ('myvalue');
CREATE KEYSPACE IF NOT EXISTS myprojectname
with replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
docker-compose --project-name projectname up -d --build cassandra
./wait-for-docker.sh 'projectname_cassandra_1'
CREATE TABLE myprojectname.tablename (
columnname text,
PRIMARY KEY(columnname)
);
printf "Waiting for $1 to become available ..."
for i in $(seq 1 40); do
health=$(docker inspect --format "{{json .State.Health.Status }}" $1)
if [[ ${health} == "\"healthy\"" ]]; then
echo ''
echo "$1 is up"
exit 0
fi
sleep 1
printf '.'
done
echo ''
echo "$1 took too long to start up. Failing."
exit 1
@giggzy
Copy link

giggzy commented Dec 16, 2018

In the dockerfile:
RUN chmod -R 777 /tmp/var/lib/cassandra /etc/cassandra

what is this doing?

I'm intrigued by this approach but not getting to work yet in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment