Increase timeout to 600s
[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
17 if [ ! -d "$RESOURCES_LOGS" ];
18 then
19     echo "Warning: Unable to find the volume directory $RESOURCES_LOGS so creating it as regular directory";
20     mkdir -p $RESOURCES_LOGS;
21 fi;
22
23 if [ ! -d "$TRAVERSAL_LOGS" ];
24 then
25     echo "Warning: Unable to find the volume directory $TRAVERSAL_LOGS so creating it as regular directory";
26     mkdir -p $TRAVERSAL_LOGS;
27 fi;
28
29 if [ ! -d "$SEARCH_LOGS" ];
30 then
31     echo "Warning: Unable to find the volume directory $SEARCH_LOGS so creating it as regular directory";
32     mkdir -p $SEARCH_LOGS;
33 fi;
34
35 if [ ! -d "$DATA_ROUTER_LOGS" ];
36 then
37     echo "Warning: Unable to find the volume directory $DATA_ROUTER_LOGS so creating it as regular directory";
38     mkdir -p $DATA_ROUTER_LOGS;
39 fi;
40
41 if [ ! -d "$MODEL_LOADER_LOGS" ];
42 then
43     echo "Warning: Unable to find the volume directory $MODEL_LOADER_LOGS so creating it as regular directory";
44     mkdir -p $MODEL_LOADER_LOGS;
45 fi;
46
47 if [ ! -d "$UI_LOGS" ];
48 then
49     echo "Warning: Unable to find the volume directory $UI_LOGS so creating it as regular directory";
50     mkdir -p $UI_LOGS;
51 fi;
52
53 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1);
54 export DOCKER_REGISTRY="${DOCKER_REGISTRY:-localhost:5000}";
55 export AAI_HAPROXY_IMAGE="${AAI_HAPROXY_IMAGE:-aaionap/haproxy}";
56
57 NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)
58 NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)
59 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
60 DMAAP_TOPIC=$(cat /opt/config/dmaap_topic.txt)
61 DOCKER_IMAGE_VERSION=$(cat /opt/config/docker_version.txt)
62 DOCKER_REGISTRY=${NEXUS_DOCKER_REPO}
63
64 docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
65
66 function wait_for_container() {
67
68     CONTAINER_NAME="$1";
69     START_TEXT="$2";
70
71     TIMEOUT=600
72
73     # wait for the real startup
74     AMOUNT_STARTUP=$(docker logs ${CONTAINER_NAME} 2>&1 | grep "$START_TEXT" | wc -l)
75     while [[ ${AMOUNT_STARTUP} -ne 1 ]];
76     do
77         echo "Waiting for '$CONTAINER_NAME' deployment to finish ..."
78         AMOUNT_STARTUP=$(docker logs ${CONTAINER_NAME} 2>&1 | grep "$START_TEXT" | wc -l)
79         if [ "$TIMEOUT" = "0" ];
80         then
81             echo "ERROR: $CONTAINER_NAME deployment failed."
82             exit 1
83         fi
84         let TIMEOUT-=5
85         sleep 5
86     done
87 }
88
89 function check_if_user_exists(){
90
91         local user_id=$1;
92
93         if [ -z "$user_id" ]; then
94                 echo "Needs to provide at least one argument for check_if_user_exists func";
95                 exit 1;
96         fi;
97
98         id -u ${user_id} > /dev/null 2>&1 && {
99                 echo "1";
100         } || {
101                 echo "0";
102         }
103 }
104
105 docker pull ${DOCKER_REGISTRY}/openecomp/aai-resources:${DOCKER_IMAGE_VERSION};
106 docker tag $DOCKER_REGISTRY/openecomp/aai-resources:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/openecomp/aai-resources:latest;
107
108 docker pull ${DOCKER_REGISTRY}/openecomp/aai-traversal:${DOCKER_IMAGE_VERSION};
109 docker tag $DOCKER_REGISTRY/openecomp/aai-traversal:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/openecomp/aai-traversal:latest;
110
111 docker pull ${DOCKER_REGISTRY}/openecomp/search-data-service:${DOCKER_IMAGE_VERSION};
112 docker tag $DOCKER_REGISTRY/openecomp/search-data-service:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/openecomp/search-data-service:latest;
113
114 docker pull ${DOCKER_REGISTRY}/openecomp/data-router:${DOCKER_IMAGE_VERSION};
115 docker tag $DOCKER_REGISTRY/openecomp/data-router:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/openecomp/data-router:latest;
116
117 docker pull ${DOCKER_REGISTRY}/openecomp/model-loader:${DOCKER_IMAGE_VERSION};
118 docker tag $DOCKER_REGISTRY/openecomp/model-loader:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/openecomp/model-loader:latest;
119
120 docker pull ${DOCKER_REGISTRY}/openecomp/sparky-be:${DOCKER_IMAGE_VERSION};
121 docker tag $DOCKER_REGISTRY/openecomp/sparky-be:$DOCKER_IMAGE_VERSION $DOCKER_REGISTRY/openecomp/sparky-be:latest;
122
123 # cleanup
124 $DOCKER_COMPOSE_CMD stop
125 $DOCKER_COMPOSE_CMD rm -f -v
126
127
128 USER_EXISTS=$(check_if_user_exists aaiadmin);
129
130 if [ "${USER_EXISTS}" -eq 0 ]; then
131         export USER_ID=9000;
132 else
133         export USER_ID=$(id -u aaiadmin);
134 fi;
135
136 chown -R $USER_ID:$USER_ID $RESOURCE_LOGS $TRAVERSAL_LOGS;
137
138 RESOURCES_CONTAINER_NAME=$($DOCKER_COMPOSE_CMD up -d aai-resources.api.simpledemo.openecomp.org 2>&1 | grep 'Creating' | grep -v 'volume' | grep -v 'network' | awk '{ print $2; }' | head -1);
139 wait_for_container $RESOURCES_CONTAINER_NAME '0.0.0.0:8447';
140
141 GRAPH_CONTAINER_NAME=$($DOCKER_COMPOSE_CMD up -d aai-traversal.api.simpledemo.openecomp.org 2>&1 | grep 'Creating' | awk '{ print $2; }' | head -1);
142 wait_for_container $GRAPH_CONTAINER_NAME '0.0.0.0:8446';
143
144 # Deploy haproxy and traversal and resources
145 $DOCKER_COMPOSE_CMD up -d aai.api.simpledemo.openecomp.org
146
147 $DOCKER_COMPOSE_CMD up -d sparky-be
148
149 $DOCKER_COMPOSE_CMD up -d model-loader datarouter aai.searchservice.simpledemo.openecomp.org
150
151 echo "A&AI Microservices are successfully started";