blob: 69007f29851fdc7ed413a2d72eff9f40e0083db2 [file] [log] [blame]
Gary Wu9abb61c2018-09-27 10:38:50 -07001#!/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
17NEXUS_USERNAME=docker
18NEXUS_PASSWD=docker
19export NEXUS_DOCKER_REPO=nexus3.onap.org:10001
20export DOCKER_IMAGE_VERSION=latest
21
Gary Wu13111e92018-09-27 11:31:33 -070022echo "This is ${WORKSPACE}/scripts/externalapi-nbi/start_nbi_containers.sh"
Gary Wu9abb61c2018-09-27 10:38:50 -070023
24# Create directory
25mkdir -p $WORKSPACE/externalapi-nbi
26cd $WORKSPACE/externalapi-nbi
27
28# Create .env file to access env variables for docker-compose
29echo "NEXUS_DOCKER_REPO=${NEXUS_DOCKER_REPO}" > .env
30echo "MSB_ENABLED=false" >> .env
31
32# Fetch the latest docker-compose.yml
33wget -O docker-compose.yml 'https://git.onap.org/externalapi/nbi/plain/docker-compose.yml?h=master'
34
35# Pull the nbi docker image from nexus
36# MariaDB and mongoDB will be pulled automatically from docker.io during docker-compose
37docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
38docker pull $NEXUS_DOCKER_REPO/onap/externalapi/nbi:$DOCKER_IMAGE_VERSION
39
40# Start nbi, MariaDB and MongoDB containers with docker compose and nbi/docker-compose.yml
41docker-compose up -d mariadb mongo
42
43# inject a script to ensure that these services are ready for connections
44docker-compose run --rm --entrypoint='/bin/sh' nbi -c '\
45 attempt=1; \
46 while ! nc -z mariadb 3306 || ! nc -z mongo 27017; do \
47 if [ $attempt = 30 ]; then \
48 echo "Timed out!"; \
49 exit 1; \
50 fi; \
51 echo "waiting for db services (attempt #$attempt)..."; \
52 sleep 1; \
53 attempt=$(( attempt + 1)); \
54 done; \
55 echo "all db services are ready for connections!" \
56'
57
58docker-compose up -d nbi
59
60NBI_CONTAINER_NAME=$(docker-compose ps 2> /dev/null | tail -n+3 | tr -s ' ' | cut -d' ' -f1 | grep _nbi_)
61NBI_IP=$(docker inspect --format='{{ range .NetworkSettings.Networks }}{{ .IPAddress }}{{ end }}' ${NBI_CONTAINER_NAME})
62
63echo "IP address for NBI main container ($NBI_CONTAINER_NAME) is set to ${NBI_IP}."
64
65# Wait for initialization
66for i in {1..30}; do
67 curl -sS ${NBI_IP}:8080 > /dev/null 2>&1 && echo 'nbi initialized' && break
68 echo sleep $i
69 sleep $i
70done