thingsboard-aplcache

Merge branch 'develop/cluster-refactoring' of github.com:thingsboard/thingsboard

5/14/2018 10:48:09 AM

Details

diff --git a/base-docker-compose.yml b/base-docker-compose.yml
index e1f6a5e..7047a2b 100644
--- a/base-docker-compose.yml
+++ b/base-docker-compose.yml
@@ -8,6 +8,9 @@ services:
       - "2181:2181"
 
   cassandra-tb:
+    build:
+      context: .
+      dockerfile: Dockerfile.cassandra
     image: cassandra
     networks:
       - core
@@ -15,7 +18,9 @@ services:
       - "7199:7199"
       - "9160:9160"
       - "9042:9042"
-
+    volumes:
+      - /cassandra:/var/lib/cassandra
+      - ./db-schema:/docker-entrypoint-initdb.d/
   redis:
     image: redis:4.0
     networks:
diff --git a/Dockerfile.cassandra b/Dockerfile.cassandra
new file mode 100644
index 0000000..b68b78a
--- /dev/null
+++ b/Dockerfile.cassandra
@@ -0,0 +1,13 @@
+FROM cassandra
+
+WORKDIR /opt/cassandra
+
+COPY dao/src/main/resources/cassandra/schema.cql /opt/cassandra
+
+COPY entrypoint-with-db-init.sh /opt/cassandra/entrypoint-with-db-init.sh
+
+RUN chmod +x /opt/cassandra/entrypoint-with-db-init.sh
+
+ENTRYPOINT ["/opt/cassandra/entrypoint-with-db-init.sh"]
+
+CMD ["cassandra", "-f"]
diff --git a/entrypoint-with-db-init.sh b/entrypoint-with-db-init.sh
new file mode 100644
index 0000000..3fb3bce
--- /dev/null
+++ b/entrypoint-with-db-init.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+if [[ $1 = 'cassandra' ]]; then
+
+  until cqlsh -f/opt/cassandra/schema.cql; do
+    echo "cqlsh: Cassandra is unavailable - retrying"
+    sleep 2
+  done &
+
+fi
+
+exec /docker-entrypoint.sh "$@"