10119844d2a72bf2c0416e0be557c56462d60285
[aai/test-config.git] / deploy_vm1.sh
1 #!/bin/bash
2
3 if [ -f "/opt/docker/docker-compose" ];
4 then
5     DOCKER_COMPOSE_CMD="/opt/docker/docker-compose -f docker-compose-app.yml"
6 else
7     DOCKER_COMPOSE_CMD="docker-compose -f docker-compose-app.yml"
8 fi
9
10 export RESOURCES_LOGS="/opt/aai/logroot/AAI-RESOURCES";
11 export TRAVERSAL_LOGS="/opt/aai/logroot/AAI-TRAVERSAL";
12 export SEARCH_LOGS="/opt/aai/logroot/AAI-SEARCH";
13 export DATA_ROUTER_LOGS="/opt/aai/logroot/AAI-DATA-ROUTER";
14 export MODEL_LOADER_LOGS="/opt/aai/logroot/AAI-MODEL-LOADER";
15 export UI_LOGS="/opt/aai/logroot/AAI-UI";
16 export CHAMP_LOGS="/opt/aai/logroot/AAI-CHAMP-SERVICE";
17 export CRUD_LOGS="/opt/aai/logroot/AAI-CRUD-SERVICE";
18 export BABEL_LOGS="/opt/aai/logroot/AAI-BAS";
19
20 if [ ! -d "$RESOURCES_LOGS" ];
21 then
22     echo "Warning: Unable to find the volume directory $RESOURCES_LOGS so creating it as regular directory";
23     mkdir -p $RESOURCES_LOGS;
24 fi;
25
26 if [ ! -d "$TRAVERSAL_LOGS" ];
27 then
28     echo "Warning: Unable to find the volume directory $TRAVERSAL_LOGS so creating it as regular directory";
29     mkdir -p $TRAVERSAL_LOGS;
30 fi;
31
32 if [ ! -d "$SEARCH_LOGS" ];
33 then
34     echo "Warning: Unable to find the volume directory $SEARCH_LOGS so creating it as regular directory";
35     mkdir -p $SEARCH_LOGS;
36 fi;
37
38 if [ ! -d "$DATA_ROUTER_LOGS" ];
39 then
40     echo "Warning: Unable to find the volume directory $DATA_ROUTER_LOGS so creating it as regular directory";
41     mkdir -p $DATA_ROUTER_LOGS;
42 fi;
43
44 if [ ! -d "$MODEL_LOADER_LOGS" ];
45 then
46     echo "Warning: Unable to find the volume directory $MODEL_LOADER_LOGS so creating it as regular directory";
47     mkdir -p $MODEL_LOADER_LOGS;
48 fi;
49
50 if [ ! -d "$UI_LOGS" ];
51 then
52     echo "Warning: Unable to find the volume directory $UI_LOGS so creating it as regular directory";
53     mkdir -p $UI_LOGS;
54 fi;
55
56 if [ ! -d "$CHAMP_LOGS" ];
57 then
58     echo "Warning: Unable to find the volume directory $CHAMP_LOGS so creating it as regular directory";
59     mkdir -p $CHAMP_LOGS;
60 fi;
61
62 if [ ! -d "$CRUD_LOGS" ];
63 then
64     echo "Warning: Unable to find the volume directory $CRUD_LOGS so creating it as regular directory";
65     mkdir -p $CRUD_LOGS;
66 fi;
67
68 if [ ! -d "$BABEL_LOGS" ];
69 then
70     echo "Warning: Unable to find the volume directory $BABEL_LOGS so creating it as regular directory";
71     mkdir -p $BABEL_LOGS;
72 fi;
73
74 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1);
75 export DOCKER_REGISTRY="${DOCKER_REGISTRY:-localhost:5000}";
76 export AAI_HAPROXY_IMAGE="${AAI_HAPROXY_IMAGE:-aaionap/haproxy}";
77 export AAI_HAPROXY_VERSION="${AAI_HAPROXY_VERSION:-1.2.3}";
78
79 NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)
80 NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)
81 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
82 DMAAP_TOPIC=$(cat /opt/config/dmaap_topic.txt)
83 DOCKER_IMAGE_VERSION=$(cat /opt/config/docker_version.txt)
84 DOCKER_REGISTRY=${NEXUS_DOCKER_REPO}
85
86 docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
87
88 function wait_for_container() {
89
90     CONTAINER_NAME="$1";
91     START_TEXT="$2";
92
93     TIMEOUT=600
94
95     # wait for the real startup
96     AMOUNT_STARTUP=$(docker logs ${CONTAINER_NAME} 2>&1 | grep "$START_TEXT" | wc -l)
97     while [[ ${AMOUNT_STARTUP} -ne 1 ]];
98     do
99         echo "Waiting for '$CONTAINER_NAME' deployment to finish ..."
100         AMOUNT_STARTUP=$(docker logs ${CONTAINER_NAME} 2>&1 | grep "$START_TEXT" | wc -l)
101         if [ "$TIMEOUT" = "0" ];
102         then
103             echo "ERROR: $CONTAINER_NAME deployment failed."
104             exit 1
105         fi
106         let TIMEOUT-=5
107         sleep 5
108     done
109 }
110
111 function check_if_user_exists(){
112
113         local user_id=$1;
114
115         if [ -z "$user_id" ]; then
116                 echo "Needs to provide at least one argument for check_if_user_exists func";
117                 exit 1;
118         fi;
119
120         id -u ${user_id} > /dev/null 2>&1 && {
121                 echo "1";
122         } || {
123                 echo "0";
124         }
125 }
126
127 docker pull ${DOCKER_REGISTRY}/onap/aai-resources:${DOCKER_IMAGE_VERSION};
128 docker tag $DOCKER_REGISTRY/onap/aai-resources:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/aai-resources:latest;
129
130 docker pull ${DOCKER_REGISTRY}/onap/aai-traversal:${DOCKER_IMAGE_VERSION};
131 docker tag $DOCKER_REGISTRY/onap/aai-traversal:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/aai-traversal:latest;
132
133 docker pull ${DOCKER_REGISTRY}/onap/search-data-service:${DOCKER_IMAGE_VERSION};
134 docker tag $DOCKER_REGISTRY/onap/search-data-service:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/search-data-service:latest;
135
136 docker pull ${DOCKER_REGISTRY}/onap/data-router:${DOCKER_IMAGE_VERSION};
137 docker tag $DOCKER_REGISTRY/onap/data-router:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/data-router:latest;
138
139 docker pull ${DOCKER_REGISTRY}/onap/model-loader:${DOCKER_IMAGE_VERSION};
140 docker tag $DOCKER_REGISTRY/onap/model-loader:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/model-loader:latest;
141
142 docker pull ${DOCKER_REGISTRY}/onap/sparky-be:${DOCKER_IMAGE_VERSION};
143 docker tag $DOCKER_REGISTRY/onap/sparky-be:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/sparky-be:latest;
144
145 docker pull ${DOCKER_REGISTRY}/onap/champ:${DOCKER_IMAGE_VERSION};
146 docker tag $DOCKER_REGISTRY/onap/champ:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/champ:latest;
147
148 docker pull ${DOCKER_REGISTRY}/onap/gizmo:${DOCKER_IMAGE_VERSION};
149 docker tag $DOCKER_REGISTRY/onap/gizmo:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/gizmo:latest;
150
151 docker pull ${DOCKER_REGISTRY}/onap/babel:${DOCKER_IMAGE_VERSION};
152 docker tag $DOCKER_REGISTRY/onap/babel:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/onap/babel:latest;
153
154 # cleanup
155 $DOCKER_COMPOSE_CMD stop
156 $DOCKER_COMPOSE_CMD rm -f -v
157
158
159 USER_EXISTS=$(check_if_user_exists aaiadmin);
160
161 if [ "${USER_EXISTS}" -eq 0 ]; then
162         export USER_ID=9000;
163         export GROUP_ID=9000;
164 else
165         export USER_ID=$(id -u aaiadmin);
166         export GROUP_ID=$(id -g aaiadmin);
167 fi;
168
169 chown -R $USER_ID:$USER_ID $RESOURCE_LOGS $TRAVERSAL_LOGS;
170 chown -R 341790:492381 $BABEL_LOGS;
171
172 $DOCKER_COMPOSE_CMD run --rm aai-resources.api.simpledemo.onap.org createDBSchema.sh
173
174 RESOURCES_CONTAINER_NAME=$($DOCKER_COMPOSE_CMD up -d aai-resources.api.simpledemo.onap.org 2>&1 | grep 'Creating' | grep -v 'volume' | grep -v 'network' | awk '{ print $2; }' | head -1);
175 wait_for_container $RESOURCES_CONTAINER_NAME 'Resources Microservice Started';
176
177 # Deploy haproxy and traversal at the same time for traversal to make updateQuery against resources using haproxy
178 $DOCKER_COMPOSE_CMD up -d aai-traversal.api.simpledemo.onap.org aai.api.simpledemo.onap.org
179
180 sleep 3;
181
182 $DOCKER_COMPOSE_CMD run --rm aai-traversal.api.simpledemo.onap.org install/updateQueryData.sh
183
184 $DOCKER_COMPOSE_CMD up -d sparky-be
185
186 $DOCKER_COMPOSE_CMD up -d model-loader datarouter aai.searchservice.simpledemo.openecomp.org
187
188 $DOCKER_COMPOSE_CMD up -d champ-service
189
190 $DOCKER_COMPOSE_CMD up -d crud-service
191
192 $DOCKER_COMPOSE_CMD up -d babel
193
194 echo "A&AI Microservices are successfully started";
195
196 crontab < /opt/test-config/aaicrontab