From ed7623af2c968484cbc27b2413cc0db6578f9276 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Fri, 13 Jul 2018 18:19:58 +0300 Subject: [PATCH] Added cassandra upgrade docker image and kubernetes yaml file --- docker/cassandra-upgrade/Dockerfile | 24 ++++++++++++++++ docker/cassandra-upgrade/Makefile | 12 ++++++++ docker/cassandra-upgrade/upgrade.sh | 28 +++++++++++++++++++ docker/k8s/cassandra-upgrade.yaml | 43 +++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 docker/cassandra-upgrade/Dockerfile create mode 100644 docker/cassandra-upgrade/Makefile create mode 100755 docker/cassandra-upgrade/upgrade.sh create mode 100644 docker/k8s/cassandra-upgrade.yaml diff --git a/docker/cassandra-upgrade/Dockerfile b/docker/cassandra-upgrade/Dockerfile new file mode 100644 index 0000000000..312db0d4e3 --- /dev/null +++ b/docker/cassandra-upgrade/Dockerfile @@ -0,0 +1,24 @@ +# +# Copyright © 2016-2018 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 upgrade.sh /upgrade.sh +ADD thingsboard.deb /thingsboard.deb + +RUN apt-get update \ + && apt-get install -y nmap \ + && chmod +x /upgrade.sh diff --git a/docker/cassandra-upgrade/Makefile b/docker/cassandra-upgrade/Makefile new file mode 100644 index 0000000000..f4c6825fc3 --- /dev/null +++ b/docker/cassandra-upgrade/Makefile @@ -0,0 +1,12 @@ +VERSION=2.0.3 +PROJECT=thingsboard +APP=cassandra-upgrade + +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-upgrade/upgrade.sh b/docker/cassandra-upgrade/upgrade.sh new file mode 100755 index 0000000000..dac49191b2 --- /dev/null +++ b/docker/cassandra-upgrade/upgrade.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Copyright © 2016-2018 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 "Upgrading 'Thingsboard' schema..." +/usr/share/thingsboard/bin/install/upgrade.sh --fromVersion=$UPGRADE_FROM_VERSION diff --git a/docker/k8s/cassandra-upgrade.yaml b/docker/k8s/cassandra-upgrade.yaml new file mode 100644 index 0000000000..881c5b8e51 --- /dev/null +++ b/docker/k8s/cassandra-upgrade.yaml @@ -0,0 +1,43 @@ +# +# Copyright © 2016-2018 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-upgrade +spec: + containers: + - name: cassandra-upgrade + imagePullPolicy: Always + image: thingsboard/cassandra-upgrade:2.0.3 + env: + - name: ADD_DEMO_DATA + value: "true" + - name : CASSANDRA_HOST + value: "cassandra-headless" + - name : CASSANDRA_PORT + value: "9042" + - name : DATABASE_TYPE + value: "cassandra" + - name : CASSANDRA_URL + value: "cassandra-headless:9042" + - name : UPGRADE_FROM_VERSION + value: "1.4.0" + command: + - sh + - -c + - /upgrade.sh + restartPolicy: Never