Created
October 6, 2017 13:09
-
-
Save awalterschulze/7732a15b555facdd9399b7f8ed9b88bf to your computer and use it in GitHub Desktop.
Run a cassandra in a docker with preloaded data
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
version: "2" | |
services: | |
cassandra: | |
build: docker/cassandra | |
ports: | |
- "9042:9042" | |
- "7199:7199" |
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
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 |
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
INSERT INTO myprojectname.tenant(columnname) VALUES ('myvalue'); |
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
CREATE KEYSPACE IF NOT EXISTS myprojectname | |
with replication = {'class': 'SimpleStrategy', 'replication_factor': 3}; |
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
docker-compose --project-name projectname up -d --build cassandra | |
./wait-for-docker.sh 'projectname_cassandra_1' |
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
CREATE TABLE myprojectname.tablename ( | |
columnname text, | |
PRIMARY KEY(columnname) | |
); |
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.