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