Make sure bash is used to execute script
[aaf/sms.git] / sms-service / bin / deploy / sms.sh
1 #!/bin/bash
2 #
3 # -------------------------------------------------------------------------
4 #   Copyright 2018 Intel Corporation, Inc
5 #
6 #   Licensed under the Apache License, Version 2.0 (the "License");
7 #   you may not use this file except in compliance with the License.
8 #   You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #   Unless required by applicable law or agreed to in writing, software
13 #   distributed under the License is distributed on an "AS IS" BASIS,
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #   See the License for the specific language governing permissions and
16 #   limitations under the License.
17 #
18 # -------------------------------------------------------------------------
19
20 SS=0
21 if [ -e /opt/config/nexus_docker_repo.txt ]
22 then
23         NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
24 else
25         NEXUS_DOCKER_REPO=nexus3.onap.org:10001
26 fi
27 echo "Using ${NEXUS_DOCKER_REPO} for docker Repo"
28
29 SMS_IMG=${NEXUS_DOCKER_REPO}/onap/aaf/sms:latest
30 QUO_IMG=${NEXUS_DOCKER_REPO}/onap/aaf/smsquorumclient:latest
31 VAU_IMG=library/vault:0.10.0
32 CON_IMG=library/consul:1.0.6
33 WORK_DIR=${PWD}
34
35 if [ "$1" = "start" ]; then
36
37 # Create Volume for mapping war file and tomcat
38 docker volume create sms-service;
39 docker volume create sms-consul;
40 docker volume create sms-quorum;
41
42 # Create a network for all the containers to run in.
43 docker network create sms-net;
44
45 # Create Consul Container
46 docker create --rm --name sms-consul --network sms-net \
47 --hostname sms-consul -p "8500:8500" \
48 -v sms-consul:/consul/data \
49 ${CON_IMG} \
50 consul agent -server -client 0.0.0.0 -bootstrap-expect=1 -config-file /consul/config/config.json;
51
52 # Copy the configuration for Consul
53 docker cp consul.json sms-consul:/consul/config/config.json;
54
55 # Start the consul container
56 docker start sms-consul;
57
58 #Wait for Consul to start
59 sleep 10
60
61 # Create Vault Container
62 docker create --rm --name sms-vault --network sms-net \
63 --hostname sms-vault -p "8200:8200" \
64 -e SKIP_SETCAP=true \
65 ${VAU_IMG} \
66 vault server -config /vault/config/config.json;
67
68 docker cp vault.json sms-vault:/vault/config/config.json;
69 docker start sms-vault;
70
71 # Start SMS
72 docker create --rm --name sms-service --network sms-net \
73 --hostname sms-service -p "10443:10443" \
74 -v sms-service:/sms/auth \
75 ${SMS_IMG};
76
77 docker cp smsconfig.json sms-service:/sms/smsconfig.json
78 docker start sms-service
79
80 # Start 3 Quorum Clients
81 for i in {0..2}
82 do
83         docker create --rm --name sms-quorum-$i --network sms-net \
84         --hostname sms-quorum-$i \
85         -v sms-quorum:/quorumclient/auth \
86         ${QUO_IMG};
87
88         docker cp quorumconfig.json sms-quorum-$i:/quorumclient/config.json
89         docker start sms-quorum-$i
90 done
91
92 # Connect service to host bridge network so that its port can be seen.
93 docker network connect bridge sms-service;
94 SS=1;
95 fi
96
97 # Shutdown and clean up.
98 if [ "$1" = "stop" ]; then
99 docker stop sms-vault sms-consul sms-service;
100 for i in {0..2}; do
101 docker stop sms-quorum-$i
102 done
103 docker network rm sms-net;
104 sleep 5;
105 docker volume rm sms-service;
106 docker volume rm sms-consul;
107 docker volume rm sms-quorum;
108 SS=1
109 fi
110
111 if [ $SS = 0 ]; then
112         echo "Please type ${0} start or ${0} stop"
113 fi