summaryrefslogtreecommitdiffstats
path: root/distribution/dockermusic/music.sh
blob: b7a66f1e979edd6c65a5546913347b8303940da7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
# -------------------------------------------------------------------------
#   Copyright (c) 2017 AT&T Intellectual Property
#
#   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.
#
# -------------------------------------------------------------------------
# In this example we are building a docker bridge network(music-net) for all
# the containers
# Then we connect the host bridge network(bridge) to the internal network(music-net) 
# 
#
#
SS=0
if [ -e /opt/config/nexus_docker_repo.txt ]
then
	NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
else
	NEXUS_DOCKER_REPO=nexus3.onap.org:10001
fi
echo "Using ${NEXUS_DOCKER_REPO} for docker Repo"

CASS_IMG=${NEXUS_DOCKER_REPO}/onap/music/cassandra_music:latest
MUSIC_IMG=${NEXUS_DOCKER_REPO}/onap/music/music:latest
TOMCAT_IMG=library/tomcat:8.5
ZK_IMG=library/zookeeper:3.4
WORK_DIR=${PWD}
CASS_USERNAME=cassandra1
CASS_PASSWORD=cassandra1

if [ "$1" = "start" ]; then

# Create Volume for mapping war file and tomcat
docker volume create music-vol;

# Create a network for all the containers to run in.
docker network create music-net;

# Start Cassandra
docker run -d --rm --name music-db --network music-net \
-p "7000:7000" -p "7001:7001" -p "7199:7199" -p "9042:9042" -p "9160:9160" \
-e CASSUSER=${CASS_USERNAME} \
-e CASSPASS=${CASS_PASSWORD} \
${CASS_IMG};

# Start Music war
docker run -d --rm --name music-war \
-v music-vol:/app \
${MUSIC_IMG};

# Start Zookeeper
docker run -d --rm --name music-zk --network music-net \
-p "2181:2181" -p "2888:2888" -p "3888:3888" \
${ZK_IMG};

# Delay for Cassandra
sleep 20;

# Start Up tomcat - Needs to have properties,logs dir and war file volume mapped.
docker run -d --rm --name music-tomcat --network music-net -p "8080:8080" \
-v music-vol:/usr/local/tomcat/webapps \
-v ${WORK_DIR}/properties:/opt/app/music/etc:ro \
-v ${WORK_DIR}/logs:/opt/app/music/logs \
${TOMCAT_IMG};

# Connect tomcat to host bridge network so that its port can be seen. 
docker network connect bridge music-tomcat;
SS=1;
fi


# Shutdown and clean up. 
if [ "$1" = "stop" ]; then
docker stop music-war;
docker stop music-db;
docker stop music-zk;
docker stop music-tomcat;
docker network rm music-net;
sleep 5;
docker volume rm music-vol;
SS=1
fi

if [ $SS = 0 ]; then
	echo "Please type ${0} start or ${0} stop"
fi