c3763c457ba3b0c61edf29883a538407f871f5ee
[music.git] / distribution / dockermusic / start.sh
1 #
2 # -------------------------------------------------------------------------
3 #   Copyright (c) 2017 AT&T Intellectual Property
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 # -------------------------------------------------------------------------
18 # In this example we are building a docker bridge network(music-net) for all
19 # the containers
20 # Then we connect the host bridge network(bridge) to the internal network(music-net) 
21
22 #
23 #
24 CASS_IMG=nexus3.onap.org:10001/onap/music/cassandra_music:latest
25 TOMCAT_IMG=nexus3.onap.org:10001/library/tomcat:8.0
26 ZK_IMG=nexus3.onap.org:10001/library/zookeeper:3.4
27 MUSIC_IMG=nexus3.onap.org:10001/onap/music/music:latest
28 WORK_DIR=${PWD}
29 CASS_USERNAME=cassandra1
30 CASS_PASSWORD=cassandra1
31
32 if [ "$1" = "start" ]; then
33
34 # Create Volume for mapping war file and tomcat
35 docker volume create music-vol;
36
37 # Create a network for all the containers to run in.
38 docker network create music-net;
39
40 # Start Cassandra
41 docker run -d --rm --name music-db --network music-net \
42 -p "7000:7000" -p "7001:7001" -p "7199:7199" -p "9042:9042" -p "9160:9160" \
43 -e CASSUSER=${CASS_USERNAME} \
44 -e CASSPASS=${CASS_PASSWORD} \
45 ${CASS_IMG};
46
47 # Start Music war
48 docker run -d --rm --name music-war \
49 -v music-vol:/app \
50 ${MUSIC_IMG};
51
52 # Start Zookeeper
53 docker run -d --rm --name music-zk --network music-net 
54 -p "2181:2181" -p "2888:2888" -p "3888:3888" \
55 ${ZK_IMG};
56
57 # Delay for Cassandra
58 sleep 20;
59
60 # Start Up tomcat - Needs to have properties,logs dir and war file volume mapped.
61 docker run -d --rm --name music-tomcat --network music-net -p "8080:8080" \
62 -v music-vol:/usr/local/tomcat/webapps \
63 -v ${WORK_DIR}/properties:/opt/app/music/etc:ro \
64 -v ${WORK_DIR}/logs:/opt/app/music/logs \
65 ${TOMCAT_IMG};
66
67 # Connect tomcat to host bridge network so that its port can be seen. 
68 docker network connect bridge music-tomcat;
69
70 fi
71
72
73 # Shutdown and clean up. 
74 if [ "$1" = "stop" ]; then
75 docker stop music-war;
76 docker stop music-db;
77 docker stop music-zk;
78 docker stop music-tomcat;
79 docker network rm music-net;
80 sleep 5;
81 docker volume rm music-vol;
82 fi