Eric Debeau | bab2f61 | 2018-04-16 19:56:04 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ======================================================================== |
| 3 | # Copyright (c) 2018 Orange |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # ======================================================================== |
| 16 | |
Quoc Nghia Nguyen | f1b2933 | 2018-04-17 10:54:31 +0200 | [diff] [blame] | 17 | NEXUS_USERNAME=docker |
| 18 | NEXUS_PASSWD=docker |
| 19 | NEXUS_DOCKER_REPO=nexus3.onap.org:10001 |
| 20 | DOCKER_IMAGE_VERSION=latest |
Eric Debeau | bab2f61 | 2018-04-16 19:56:04 +0000 | [diff] [blame] | 21 | |
| 22 | echo "This is ${WORKSPACE}/test/csit/scripts/externalapi-nbi/start_nbi_containers.sh" |
| 23 | |
| 24 | # Create directory |
| 25 | mkdir -p $WORKSPACE/externalapi-nbi |
| 26 | cd $WORKSPACE/externalapi-nbi |
| 27 | |
Eric Debeau | 8484979 | 2018-05-12 07:29:49 +0000 | [diff] [blame] | 28 | # Create .env file to access env variables for docker-compose |
| 29 | echo "NEXUS_DOCKER_REPO=${NEXUS_DOCKER_REPO}" > .env |
| 30 | |
Eric Debeau | bab2f61 | 2018-04-16 19:56:04 +0000 | [diff] [blame] | 31 | # Fetch the latest docker-compose.yml |
Quoc Nghia Nguyen | f1b2933 | 2018-04-17 10:54:31 +0200 | [diff] [blame] | 32 | wget -O docker-compose.yml 'https://git.onap.org/externalapi/nbi/plain/docker-compose.yml?h=master' |
Eric Debeau | bab2f61 | 2018-04-16 19:56:04 +0000 | [diff] [blame] | 33 | |
| 34 | # Pull the nbi docker image from nexus |
| 35 | # MariaDB and mongoDB will be pulled automatically from docker.io during docker-compose |
| 36 | docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO |
| 37 | docker pull $NEXUS_DOCKER_REPO/onap/externalapi/nbi:$DOCKER_IMAGE_VERSION |
| 38 | |
| 39 | # Start nbi, MariaDB and MongoDB containers with docker compose and nbi/docker-compose.yml |
Quoc Nghia Nguyen | 2cb13e6 | 2018-05-02 18:39:20 +0200 | [diff] [blame] | 40 | docker-compose up -d mariadb mongo |
| 41 | |
| 42 | # inject a script to ensure that these services are ready for connections |
| 43 | docker-compose run --rm --entrypoint='/bin/sh' nbi -c '\ |
| 44 | attempt=1; \ |
| 45 | while ! nc -z mariadb 3306 || ! nc -z mongo 27017; do \ |
| 46 | if [ $attempt = 30 ]; then \ |
| 47 | echo "Timed out!"; \ |
| 48 | exit 1; \ |
| 49 | fi; \ |
| 50 | echo "waiting for db services (attempt #$attempt)..."; \ |
| 51 | sleep 1; \ |
| 52 | attempt=$(( attempt + 1)); \ |
| 53 | done; \ |
| 54 | echo "all db services are ready for connections!" \ |
| 55 | ' |
| 56 | |
Quoc Nghia Nguyen | f1b2933 | 2018-04-17 10:54:31 +0200 | [diff] [blame] | 57 | docker-compose up -d nbi |
Eric Debeau | a09ce2b | 2018-04-18 20:53:01 +0000 | [diff] [blame] | 58 | |
| 59 | NBI_CONTAINER_NAME=$(docker-compose ps 2> /dev/null | tail -n+3 | tr -s ' ' | cut -d' ' -f1 | grep _nbi_) |
Quoc Nghia Nguyen | 2cb13e6 | 2018-05-02 18:39:20 +0200 | [diff] [blame] | 60 | NBI_IP=$(docker inspect --format='{{ range .NetworkSettings.Networks }}{{ .IPAddress }}{{ end }}' ${NBI_CONTAINER_NAME}) |
Eric Debeau | a09ce2b | 2018-04-18 20:53:01 +0000 | [diff] [blame] | 61 | |
| 62 | echo "IP address for NBI main container ($NBI_CONTAINER_NAME) is set to ${NBI_IP}." |
| 63 | |
| 64 | # Wait for initialization |
| 65 | for i in {1..30}; do |
Quoc Nghia Nguyen | 2cb13e6 | 2018-05-02 18:39:20 +0200 | [diff] [blame] | 66 | curl -sS ${NBI_IP}:8080 > /dev/null 2>&1 && echo 'nbi initialized' && break |
Eric Debeau | a09ce2b | 2018-04-18 20:53:01 +0000 | [diff] [blame] | 67 | echo sleep $i |
| 68 | sleep $i |
| 69 | done |