From 49feb9132ca8877efbc719beff76d951cabdfe26 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 26 Jul 2017 16:16:07 +0300 Subject: [PATCH 1/2] Docker updates to new release features --- .../src/main/resources/thingsboard.yml | 4 +- docker/.env | 10 ++-- docker/docker-compose.yml | 24 ++------- docker/{cassandra => k8s}/cassandra.yaml | 0 docker/{common => k8s}/common.yaml | 0 docker/{tb => k8s}/tb.yaml | 0 docker/{zookeeper => k8s}/zookeeper.yaml | 0 docker/tb-cassandra-schema/Dockerfile | 28 ---------- docker/tb-cassandra-schema/Makefile | 14 ----- docker/tb-cassandra-schema/install-schema.sh | 53 ------------------- .../tb-cassandra-schema.yaml | 39 -------------- docker/tb-postgres-schema/Dockerfile | 27 ---------- docker/tb-postgres-schema/Makefile | 14 ----- docker/tb-postgres-schema/install-schema.sh | 52 ------------------ docker/tb.env | 22 ++++++-- docker/tb/Dockerfile | 4 +- docker/tb/run-application.sh | 40 +++++++++----- 17 files changed, 58 insertions(+), 273 deletions(-) rename docker/{cassandra => k8s}/cassandra.yaml (100%) rename docker/{common => k8s}/common.yaml (100%) rename docker/{tb => k8s}/tb.yaml (100%) rename docker/{zookeeper => k8s}/zookeeper.yaml (100%) delete mode 100644 docker/tb-cassandra-schema/Dockerfile delete mode 100644 docker/tb-cassandra-schema/Makefile delete mode 100644 docker/tb-cassandra-schema/install-schema.sh delete mode 100644 docker/tb-cassandra-schema/tb-cassandra-schema.yaml delete mode 100644 docker/tb-postgres-schema/Dockerfile delete mode 100644 docker/tb-postgres-schema/Makefile delete mode 100644 docker/tb-postgres-schema/install-schema.sh diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 7e2a7735ff..e57018d14a 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -233,7 +233,7 @@ spring: jpa: hibernate: ddl-auto: "validate" - database-platform: "org.hibernate.dialect.HSQLDialect" + database-platform: "${SPRING_JPA_DATABASE_PLATFORM:org.hibernate.dialect.HSQLDialect}" datasource: driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.hsqldb.jdbc.JDBCDriver}" url: "${SPRING_DATASOURCE_URL:jdbc:hsqldb:file:${SQL_DATA_FOLDER:/tmp}/thingsboardDb;sql.enforce_size=false}" @@ -250,7 +250,7 @@ spring: # jpa: # hibernate: # ddl-auto: "validate" -# database-platform: "org.hibernate.dialect.PostgreSQLDialect" +# database-platform: "${SPRING_JPA_DATABASE_PLATFORM:org.hibernate.dialect.PostgreSQLDialect}" # datasource: # driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}" # url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}" diff --git a/docker/.env b/docker/.env index ff77f417be..e3306324d4 100644 --- a/docker/.env +++ b/docker/.env @@ -1,15 +1,13 @@ # cassandra environment variables CASSANDRA_DATA_DIR=/home/docker/cassandra_volume -CASSANDRA_URL=cassandra # postgres environment variables POSTGRES_DATA_DIR=/home/docker/postgres_volume POSTGRES_DB=thingsboard -POSTGRES_USER=postgres -POSTGRES_PASSWORD=postgres -POSTGRES_URL=postgres + +# hsqldb environment variables +HSQLDB_DATA_DIR=/home/docker/hsqldb_volume # environment variables for schema init and insert system and demo data -CREATE_SCHEMA=true -ADD_SYSTEM_DATA=false +ADD_SCHEMA_AND_SYSTEM_DATA=false ADD_DEMO_DATA=false \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 988a2db6d0..7cbea951e5 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -25,15 +25,12 @@ services: - "5683:5683/udp" env_file: - tb.env - entrypoint: /run-application.sh - tb-cassandra-schema: - image: "thingsboard/tb-cassandra-schema:1.2.4" environment: - - CREATE_SCHEMA=${CREATE_SCHEMA} - - ADD_SYSTEM_DATA=${ADD_SYSTEM_DATA} + - ADD_SCHEMA_AND_SYSTEM_DATA=${ADD_SCHEMA_AND_SYSTEM_DATA} - ADD_DEMO_DATA=${ADD_DEMO_DATA} - - CASSANDRA_URL=${CASSANDRA_URL} - entrypoint: /install-schema.sh + volumes: + - "${HSQLDB_DATA_DIR}:/usr/share/thingsboard/data/sql" + entrypoint: /run-application.sh cassandra: image: "cassandra:3.9" ports: @@ -52,18 +49,5 @@ services: - "5432" environment: - POSTGRES_DB=${POSTGRES_DB} - - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} volumes: - "${POSTGRES_DATA_DIR}:/var/lib/postgresql/data" - tb-postgres-schema: - image: "thingsboard/tb-postgres-schema:1.2.4" - environment: - - POSTGRES_URL=${POSTGRES_URL} - - POSTGRES_DB=${POSTGRES_DB} - - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - - CREATE_SCHEMA=${CREATE_SCHEMA} - - ADD_SYSTEM_DATA=${ADD_SYSTEM_DATA} - - ADD_DEMO_DATA=${ADD_DEMO_DATA} - entrypoint: /install-schema.sh \ No newline at end of file diff --git a/docker/cassandra/cassandra.yaml b/docker/k8s/cassandra.yaml similarity index 100% rename from docker/cassandra/cassandra.yaml rename to docker/k8s/cassandra.yaml diff --git a/docker/common/common.yaml b/docker/k8s/common.yaml similarity index 100% rename from docker/common/common.yaml rename to docker/k8s/common.yaml diff --git a/docker/tb/tb.yaml b/docker/k8s/tb.yaml similarity index 100% rename from docker/tb/tb.yaml rename to docker/k8s/tb.yaml diff --git a/docker/zookeeper/zookeeper.yaml b/docker/k8s/zookeeper.yaml similarity index 100% rename from docker/zookeeper/zookeeper.yaml rename to docker/k8s/zookeeper.yaml diff --git a/docker/tb-cassandra-schema/Dockerfile b/docker/tb-cassandra-schema/Dockerfile deleted file mode 100644 index e78042da75..0000000000 --- a/docker/tb-cassandra-schema/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -# -# Copyright © 2016-2017 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -FROM cassandra:3.9 - -ADD install-schema.sh /install-schema.sh - -RUN apt-get update \ - && apt-get install -y nmap \ - && chmod +x /install-schema.sh - -ADD schema.cql /schema.cql -ADD demo-data.cql /demo-data.cql -ADD system-data.cql /system-data.cql - diff --git a/docker/tb-cassandra-schema/Makefile b/docker/tb-cassandra-schema/Makefile deleted file mode 100644 index 72af77b756..0000000000 --- a/docker/tb-cassandra-schema/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -VERSION=1.2.4 -PROJECT=thingsboard -APP=tb-cassandra-schema - -build: - cp ../../dao/src/main/resources/cassandra/schema.cql . - cp ../../dao/src/main/resources/cassandra/demo-data.cql . - cp ../../dao/src/main/resources/cassandra/system-data.cql . - docker build --pull -t ${PROJECT}/${APP}:${VERSION} -t ${PROJECT}/${APP}:latest . - rm schema.cql demo-data.cql system-data.cql - -push: build - docker push ${PROJECT}/${APP}:${VERSION} - docker push ${PROJECT}/${APP}:latest diff --git a/docker/tb-cassandra-schema/install-schema.sh b/docker/tb-cassandra-schema/install-schema.sh deleted file mode 100644 index 0845a73a47..0000000000 --- a/docker/tb-cassandra-schema/install-schema.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -# -# Copyright © 2016-2017 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -until nmap $CASSANDRA_URL -p 9042 | grep "9042/tcp open" -do - echo "Wait for $CASSANDRA_URL..." - sleep 10 -done - -if [ "$CREATE_SCHEMA" == "true" ]; then - echo "Creating 'Thingsboard' keyspace..." - cqlsh $CASSANDRA_URL -f /schema.cql - if [ "$?" -eq 0 ]; then - echo "'Thingsboard' keyspace was successfully created!" - else - echo "There were issues while creating 'Thingsboard' keyspace!" - fi -fi - -if [ "$ADD_SYSTEM_DATA" == "true" ]; then - echo "Adding system data..." - cqlsh $CASSANDRA_URL -f /system-data.cql - if [ "$?" -eq 0 ]; then - echo "System data was successfully added!" - else - echo "There were issues while adding System data!" - fi -fi - -if [ "$ADD_DEMO_DATA" == "true" ]; then - echo "Adding demo data..." - cqlsh $CASSANDRA_URL -f /demo-data.cql - if [ "$?" -eq 0 ]; then - echo "Demo data was successfully added!" - else - echo "There were issues while adding Demo data!" - fi -fi diff --git a/docker/tb-cassandra-schema/tb-cassandra-schema.yaml b/docker/tb-cassandra-schema/tb-cassandra-schema.yaml deleted file mode 100644 index b86cb90dde..0000000000 --- a/docker/tb-cassandra-schema/tb-cassandra-schema.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# -# Copyright © 2016-2017 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -apiVersion: v1 -kind: Pod -metadata: - name: tb-cassandra-schema -spec: - containers: - - name: tb-cassandra-schema - imagePullPolicy: Always - image: thingsboard/tb-cassandra-schema:1.2.4 - env: - - name: CREATE_SCHEMA - value: "true" - - name: ADD_SYSTEM_DATA - value: "true" - - name : ADD_DEMO_DATA - value: "true" - - name : CASSANDRA_URL - value: "cassandra-headless" - command: - - sh - - -c - - /install-schema.sh - restartPolicy: Never \ No newline at end of file diff --git a/docker/tb-postgres-schema/Dockerfile b/docker/tb-postgres-schema/Dockerfile deleted file mode 100644 index b14356f0f8..0000000000 --- a/docker/tb-postgres-schema/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright © 2016-2017 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -FROM postgres:9.6 - -ADD install-schema.sh /install-schema.sh - -RUN apt-get update \ - && apt-get install -y nmap \ - && chmod +x /install-schema.sh - -ADD schema.sql /schema.sql -ADD system-data.sql /system-data.sql -ADD demo-data.sql /demo-data.sql \ No newline at end of file diff --git a/docker/tb-postgres-schema/Makefile b/docker/tb-postgres-schema/Makefile deleted file mode 100644 index dc7909b863..0000000000 --- a/docker/tb-postgres-schema/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -VERSION=1.2.4 -PROJECT=thingsboard -APP=tb-postgres-schema - -build: - cp ../../dao/src/main/resources/postgres/schema.sql . - cp ../../dao/src/main/resources/postgres/demo-data.sql . - cp ../../dao/src/main/resources/postgres/system-data.sql . - docker build --pull -t ${PROJECT}/${APP}:${VERSION} -t ${PROJECT}/${APP}:latest . - rm schema.sql demo-data.sql system-data.sql - -push: build - docker push ${PROJECT}/${APP}:${VERSION} - docker push ${PROJECT}/${APP}:latest diff --git a/docker/tb-postgres-schema/install-schema.sh b/docker/tb-postgres-schema/install-schema.sh deleted file mode 100644 index 40af3700f3..0000000000 --- a/docker/tb-postgres-schema/install-schema.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -# -# Copyright © 2016-2017 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -until nmap $POSTGRES_URL -p 5432 | grep "5432/tcp open" -do - echo "Waiting for $POSTGRES_URL..." - sleep 10 -done - -if [ "$CREATE_SCHEMA" == "true" ]; then - echo "Creating 'Thingsboard' database schema..." - PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_URL" -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -f /schema.sql - if [ "$?" -eq 0 ]; then - echo "'Thingsboard' database schema was successfully created!" - else - echo "There were issues while creating 'Thingsboard' database schema!" - fi -fi - -if [ "$ADD_SYSTEM_DATA" == "true" ]; then - echo "Adding system data..." - PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_URL" -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -f /system-data.sql - if [ "$?" -eq 0 ]; then - echo "System data was successfully added!" - else - echo "There were issues while adding System data!" - fi -fi - -if [ "$ADD_DEMO_DATA" == "true" ]; then - echo "Adding demo data..." - PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_URL" -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -f /demo-data.sql - if [ "$?" -eq 0 ]; then - echo "Demo data was successfully added!" - else - echo "There were issues while adding Demo data!" - fi -fi diff --git a/docker/tb.env b/docker/tb.env index 7947c23d43..c5d77c0ad1 100644 --- a/docker/tb.env +++ b/docker/tb.env @@ -1,9 +1,21 @@ #Thingsboard server configuration - -TB_CASSANDRA_SCHEMA_URL=tb-cassandra-schema -CASSANDRA_URL=cassandra:9042 -ZOOKEEPER_URL=zk:2181 MQTT_BIND_ADDRESS=0.0.0.0 MQTT_BIND_PORT=1883 COAP_BIND_ADDRESS=0.0.0.0 -COAP_BIND_PORT=5683 \ No newline at end of file +COAP_BIND_PORT=5683 + +# zk config +ZOOKEEPER_URL=zk:2181 + +# type of database to use: sql[DEFAULT] or cassandra +DATABASE_TYPE=sql + +# cassandra db config +CASSANDRA_URL=cassandra:9042 + +# postgres db config +# SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect +# SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver +# SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/thingsboard +# SPRING_DATASOURCE_USERNAME=postgres +# SPRING_DATASOURCE_PASSWORD=postgres diff --git a/docker/tb/Dockerfile b/docker/tb/Dockerfile index b2a3da6e06..993e7f3231 100644 --- a/docker/tb/Dockerfile +++ b/docker/tb/Dockerfile @@ -19,4 +19,6 @@ FROM openjdk:8-jre ADD run-application.sh /run-application.sh ADD thingsboard.deb /thingsboard.deb -RUN chmod +x /run-application.sh +RUN apt-get update \ + && apt-get install -y nmap \ + && chmod +x /run-application.sh diff --git a/docker/tb/run-application.sh b/docker/tb/run-application.sh index 4824133a28..274e255bdb 100755 --- a/docker/tb/run-application.sh +++ b/docker/tb/run-application.sh @@ -18,18 +18,34 @@ dpkg -i /thingsboard.deb -reachable=0 -while [ $reachable -eq 0 ]; -do - echo "$TB_CASSANDRA_SCHEMA_URL container is still in progress. waiting until it completed..." - sleep 3 - ping -q -c 1 $TB_CASSANDRA_SCHEMA_URL > /dev/null 2>&1 - if [ "$?" -ne 0 ]; - then - echo "$TB_CASSANDRA_SCHEMA_URL container completed!" - reachable=1 - fi -done +if [ "$DATABASE_TYPE" == "cassandra" ]; then + until nmap cassandra -p 9042 | grep "9042/tcp open" + do + echo "Wait for cassandra db to start..." + sleep 10 + done +fi + +if [ "$DATABASE_TYPE" == "sql" ]; then + if [ "$SPRING_DRIVER_CLASS_NAME" == "org.postgresql.Driver" ]; then + until nmap postgres -p 5432 | grep "5432/tcp open" + do + echo "Waiting for postgres db to start..." + sleep 10 + done + fi +fi + +if [ "$ADD_SCHEMA_AND_SYSTEM_DATA" == "true" ]; then + echo "Creating 'Thingsboard' schema and system data..." + if [ "$ADD_DEMO_DATA" == "true" ]; then + echo "Adding demo data..." + /usr/share/thingsboard/bin/install/install.sh --loadDemo + elif [ "$ADD_DEMO_DATA" == "false" ]; then + /usr/share/thingsboard/bin/install/install.sh + fi +fi + # Copying env variables into conf files printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thingsboard/conf/thingsboard.conf From be8f7062a46128fede2ba97ae88345a2c4d60502 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Thu, 27 Jul 2017 20:37:00 +0300 Subject: [PATCH 2/2] Docker updates to new release features --- .../src/main/resources/thingsboard.yml | 4 +- .../cassandra/AbstractCassandraCluster.java | 2 +- .../test/resources/cassandra-test.properties | 4 +- docker/cassandra-setup/Dockerfile | 24 ++++++++++++ docker/cassandra-setup/Makefile | 12 ++++++ docker/cassandra-setup/install.sh | 33 ++++++++++++++++ docker/cassandra/Makefile | 2 +- docker/k8s/cassandra-setup.yaml | 39 +++++++++++++++++++ docker/k8s/tb.yaml | 18 +++++++-- docker/tb.env | 5 ++- docker/tb/Makefile | 2 +- docker/tb/run-application.sh | 4 +- 12 files changed, 137 insertions(+), 12 deletions(-) create mode 100644 docker/cassandra-setup/Dockerfile create mode 100644 docker/cassandra-setup/Makefile create mode 100755 docker/cassandra-setup/install.sh create mode 100644 docker/k8s/cassandra-setup.yaml diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index e57018d14a..d080f84b19 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -115,7 +115,9 @@ cassandra: # Thingsboard keyspace name keyspace_name: "${CASSANDRA_KEYSPACE_NAME:thingsboard}" # Specify node list - url: "${CASSANDRA_URL:127.0.0.1:9042}" + host: "${CASSANDRA_HOST:127.0.0.1}" + # Specify node list + post: "${CASSANDRA_PORT:9042}" # Enable/disable secure connection ssl: "${CASSANDRA_USE_SSL:false}" # Enable/disable JMX diff --git a/dao/src/main/java/org/thingsboard/server/dao/cassandra/AbstractCassandraCluster.java b/dao/src/main/java/org/thingsboard/server/dao/cassandra/AbstractCassandraCluster.java index 2b9000d7dd..d693802bfd 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/cassandra/AbstractCassandraCluster.java +++ b/dao/src/main/java/org/thingsboard/server/dao/cassandra/AbstractCassandraCluster.java @@ -44,7 +44,7 @@ public abstract class AbstractCassandraCluster { @Value("${cassandra.cluster_name}") private String clusterName; - @Value("${cassandra.url}") + @Value("${cassandra.host}:${cassandra.port}") private String url; @Value("${cassandra.compression}") private String compression; diff --git a/dao/src/test/resources/cassandra-test.properties b/dao/src/test/resources/cassandra-test.properties index 82fcbe1949..b9e2734279 100644 --- a/dao/src/test/resources/cassandra-test.properties +++ b/dao/src/test/resources/cassandra-test.properties @@ -2,7 +2,9 @@ cassandra.cluster_name=Thingsboard Cluster cassandra.keyspace_name=thingsboard -cassandra.url=127.0.0.1:9142 +cassandra.host=127.0.0.1 + +cassandra.port=9142 cassandra.ssl=false diff --git a/docker/cassandra-setup/Dockerfile b/docker/cassandra-setup/Dockerfile new file mode 100644 index 0000000000..f91f0f16cb --- /dev/null +++ b/docker/cassandra-setup/Dockerfile @@ -0,0 +1,24 @@ +# +# Copyright © 2016-2017 The Thingsboard Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +FROM openjdk:8-jre + +ADD install.sh /install.sh +ADD thingsboard.deb /thingsboard.deb + +RUN apt-get update \ + && apt-get install -y nmap \ + && chmod +x /install.sh diff --git a/docker/cassandra-setup/Makefile b/docker/cassandra-setup/Makefile new file mode 100644 index 0000000000..635b92fce0 --- /dev/null +++ b/docker/cassandra-setup/Makefile @@ -0,0 +1,12 @@ +VERSION=1.2.4 +PROJECT=thingsboard +APP=cassandra-setup + +build: + cp ../../application/target/thingsboard.deb . + docker build --pull -t ${PROJECT}/${APP}:${VERSION} -t ${PROJECT}/${APP}:latest . + rm thingsboard.deb + +push: build + docker push ${PROJECT}/${APP}:${VERSION} + docker push ${PROJECT}/${APP}:latest diff --git a/docker/cassandra-setup/install.sh b/docker/cassandra-setup/install.sh new file mode 100755 index 0000000000..87aaeed95f --- /dev/null +++ b/docker/cassandra-setup/install.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Copyright © 2016-2017 The Thingsboard Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +dpkg -i /thingsboard.deb + +until nmap $CASSANDRA_HOST -p $CASSANDRA_PORT | grep "$CASSANDRA_PORT/tcp open" +do + echo "Wait for cassandra db to start..." + sleep 10 +done + +echo "Creating 'Thingsboard' schema and system data..." +if [ "$ADD_DEMO_DATA" == "true" ]; then + echo "plus demo data..." + /usr/share/thingsboard/bin/install/install.sh --loadDemo +elif [ "$ADD_DEMO_DATA" == "false" ]; then + /usr/share/thingsboard/bin/install/install.sh +fi diff --git a/docker/cassandra/Makefile b/docker/cassandra/Makefile index f277e9e543..ae82253eb7 100644 --- a/docker/cassandra/Makefile +++ b/docker/cassandra/Makefile @@ -7,4 +7,4 @@ build: push: build docker push ${PROJECT}/${APP}:${VERSION} - docker push ${PROJECT}/${APP}:latest + docker push ${PROJECT}/${APP}:latest diff --git a/docker/k8s/cassandra-setup.yaml b/docker/k8s/cassandra-setup.yaml new file mode 100644 index 0000000000..996ab1230e --- /dev/null +++ b/docker/k8s/cassandra-setup.yaml @@ -0,0 +1,39 @@ +# +# Copyright © 2016-2017 The Thingsboard Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +apiVersion: v1 +kind: Pod +metadata: + name: cassandra-setup +spec: + containers: + - name: cassandra-setup + imagePullPolicy: Always + image: thingsboard/cassandra-setup:1.2.4 + env: + - name: ADD_DEMO_DATA + value: "true" + - name : CASSANDRA_HOST + value: "cassandra-headless" + - name : CASSANDRA_PORT + value: "9042" + - name : DATABASE_TYPE + value: "cassandra" + command: + - sh + - -c + - /install.sh + restartPolicy: Never diff --git a/docker/k8s/tb.yaml b/docker/k8s/tb.yaml index 45f987f04f..be22309090 100644 --- a/docker/k8s/tb.yaml +++ b/docker/k8s/tb.yaml @@ -50,7 +50,9 @@ metadata: data: zookeeper.enabled: "true" zookeeper.url: "zk-headless" - cassandra.url: "cassandra-headless:9042" + cassandra.host: "cassandra-headless" + cassandra.port: "9042" + database.type: "cassandra" --- apiVersion: apps/v1beta1 kind: StatefulSet @@ -100,11 +102,21 @@ spec: configMapKeyRef: name: tb-config key: zookeeper.url - - name : CASSANDRA_URL + - name : CASSANDRA_HOST valueFrom: configMapKeyRef: name: tb-config - key: cassandra.url + key: cassandra.host + - name : CASSANDRA_PORT + valueFrom: + configMapKeyRef: + name: tb-config + key: cassandra.port + - name: DATABASE_TYPE + valueFrom: + configMapKeyRef: + name: tb-config + key: database.type - name : RPC_HOST valueFrom: fieldRef: diff --git a/docker/tb.env b/docker/tb.env index c5d77c0ad1..89a7dda8e4 100644 --- a/docker/tb.env +++ b/docker/tb.env @@ -8,10 +8,11 @@ COAP_BIND_PORT=5683 ZOOKEEPER_URL=zk:2181 # type of database to use: sql[DEFAULT] or cassandra -DATABASE_TYPE=sql +DATABASE_TYPE=cassandra # cassandra db config -CASSANDRA_URL=cassandra:9042 +CASSANDRA_HOST=cassandra +CASSANDRA_PORT=9042 # postgres db config # SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect diff --git a/docker/tb/Makefile b/docker/tb/Makefile index b12e5a6b5d..267a1664de 100644 --- a/docker/tb/Makefile +++ b/docker/tb/Makefile @@ -9,4 +9,4 @@ build: push: build docker push ${PROJECT}/${APP}:${VERSION} - docker push ${PROJECT}/${APP}:latest + docker push ${PROJECT}/${APP}:latest diff --git a/docker/tb/run-application.sh b/docker/tb/run-application.sh index 274e255bdb..783b35b0c3 100755 --- a/docker/tb/run-application.sh +++ b/docker/tb/run-application.sh @@ -19,7 +19,7 @@ dpkg -i /thingsboard.deb if [ "$DATABASE_TYPE" == "cassandra" ]; then - until nmap cassandra -p 9042 | grep "9042/tcp open" + until nmap $CASSANDRA_HOST -p $CASSANDRA_PORT | grep "$CASSANDRA_PORT/tcp open" do echo "Wait for cassandra db to start..." sleep 10 @@ -39,7 +39,7 @@ fi if [ "$ADD_SCHEMA_AND_SYSTEM_DATA" == "true" ]; then echo "Creating 'Thingsboard' schema and system data..." if [ "$ADD_DEMO_DATA" == "true" ]; then - echo "Adding demo data..." + echo "plus demo data..." /usr/share/thingsboard/bin/install/install.sh --loadDemo elif [ "$ADD_DEMO_DATA" == "false" ]; then /usr/share/thingsboard/bin/install/install.sh