waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START======================================================= |
| 4 | # Copyright (C) 2019 Nordix Foundation. |
| 5 | # ================================================================================ |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ============LICENSE_END========================================================= |
| 20 | |
| 21 | # @author Waqas Ikram (waqas.ikram@est.tech) |
| 22 | |
| 23 | MAVEN_VERSION_DIR="apache-maven-3.3.9" |
| 24 | MAVEN_TAR_FILE="$MAVEN_VERSION_DIR-bin.tar.gz" |
| 25 | MAVEN_TAR_LOCATION="http://apache.claz.org/maven/maven-3/3.3.9/binaries/$MAVEN_TAR_FILE" |
| 26 | |
| 27 | SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 28 | SCRIPT_NAME=$(basename $0) |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 29 | CONFIG_DIR=$SCRIPT_HOME/config |
| 30 | ENV_FILE=$CONFIG_DIR/env |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 31 | TEMP_DIR_PATH=$SCRIPT_HOME/temp |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 32 | TEST_LAB_DIR_PATH=$TEMP_DIR_PATH/test_lab |
| 33 | DOCKER_COMPOSE_FILE_PATH=$SCRIPT_HOME/docker-compose.yml |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 34 | |
| 35 | MAVEN_DIR=$TEMP_DIR_PATH/maven |
| 36 | INSTALLED_MAVEN_DIR=$MAVEN_DIR/$MAVEN_VERSION_DIR |
| 37 | MVN=$INSTALLED_MAVEN_DIR/bin/mvn |
| 38 | MVN_VERSION="$MVN -v" |
| 39 | MVN_SETTINGS_XML="$SCRIPT_HOME/settings.xml" |
| 40 | MVN_CLEAN_INSTALL="$MVN clean install" |
| 41 | SIMULATOR_MAVEN_PROJECT_POM="$SCRIPT_HOME/so-simulators/pom.xml" |
waqas.ikram | 5fee448 | 2019-07-22 13:56:13 +0000 | [diff] [blame] | 42 | WAIT_FOR_WORKAROUND_SCRIPT=$CONFIG_DIR/"wait-for-workaround-job.sh" |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 43 | |
| 44 | echo "Running $SCRIPT_HOME/$SCRIPT_NAME ..." |
| 45 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 46 | export $(egrep -v '^#' $ENV_FILE | xargs) |
| 47 | |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 48 | if [[ ! "$TEMP_DIR_PATH" || ! -d "$TEMP_DIR_PATH" ]]; then |
| 49 | echo "Creating temporary directory $TEMP_DIR_PATH" |
| 50 | mkdir $TEMP_DIR_PATH |
| 51 | |
| 52 | if [ $? -ne 0 ]; then |
| 53 | echo "Could not create $TEMP_DIR_PATH" |
| 54 | exit 1 |
| 55 | fi |
| 56 | |
| 57 | fi |
| 58 | echo "Will use ${TEMP_DIR_PATH} directory" |
| 59 | |
| 60 | if [[ ! "$MAVEN_DIR" || ! -d "$MAVEN_DIR" ]]; then |
| 61 | echo "Creating temporary maven directory $MAVEN_DIR" |
| 62 | mkdir $MAVEN_DIR |
| 63 | |
| 64 | if [ $? -ne 0 ]; then |
| 65 | echo "Could not create $MAVEN_DIR" |
| 66 | exit 1 |
| 67 | fi |
| 68 | fi |
| 69 | echo "Will use ${MAVEN_DIR} directory for maven install" |
| 70 | |
| 71 | if [[ ! "$INSTALLED_MAVEN_DIR" || ! -d "$INSTALLED_MAVEN_DIR" ]]; then |
| 72 | echo "Installing maven ..." |
| 73 | cd $MAVEN_DIR |
| 74 | |
| 75 | CURL=`which curl` |
| 76 | if [[ ! "$CURL" ]]; then |
| 77 | echo "curl command is not installed" |
| 78 | echo "Unable to execute test plan" |
| 79 | exit 1 |
| 80 | fi |
| 81 | curl -O $MAVEN_TAR_LOCATION |
| 82 | |
| 83 | TAR=`which tar` |
| 84 | if [[ ! "$TAR" ]]; then |
| 85 | echo "tar command is not installed" |
| 86 | echo "Unable to execute test plan" |
| 87 | exit 1 |
| 88 | fi |
| 89 | |
| 90 | tar -xzvf apache-maven-3.3.9-bin.tar.gz |
| 91 | |
| 92 | echo "Finished installing maven ..." |
| 93 | fi |
| 94 | |
| 95 | echo "Maven installed under directory $INSTALLED_MAVEN_DIR" |
| 96 | |
| 97 | $MVN_VERSION |
| 98 | |
| 99 | if [ $? -ne 0 ]; then |
| 100 | echo "Unable to run mvn -v command" |
| 101 | exit 1 |
| 102 | fi |
| 103 | |
| 104 | cd $SCRIPT_HOME |
| 105 | |
| 106 | echo "Will build simulator project using $MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML" |
| 107 | $MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML |
| 108 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 109 | if [ $? -ne 0 ]; then |
| 110 | echo "Maven build failed" |
| 111 | exit 1 |
| 112 | fi |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 113 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 114 | echo "Will clone docker-config project ... " |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 115 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 116 | |
| 117 | if [[ -d "$TEST_LAB_DIR_PATH" ]]; then |
| 118 | echo "$TEST_LAB_DIR_PATH already exists" |
| 119 | echo "Removing $TEST_LAB_DIR_PATH directory ..." |
| 120 | rm -rf $TEST_LAB_DIR_PATH |
| 121 | fi |
| 122 | |
| 123 | git clone http://gerrit.onap.org/r/so/docker-config.git $TEST_LAB_DIR_PATH |
| 124 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 125 | export TEST_LAB_DIR=$TEST_LAB_DIR_PATH |
| 126 | export CONFIG_DIR_PATH=$CONFIG_DIR |
| 127 | |
| 128 | docker-compose -f $DOCKER_COMPOSE_FILE_PATH up -d |
| 129 | |
| 130 | echo "Sleeping for 3m" |
| 131 | sleep 3m |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 132 | |
waqas.ikram | 5fee448 | 2019-07-22 13:56:13 +0000 | [diff] [blame] | 133 | echo "Will execute $WAIT_FOR_WORKAROUND_SCRIPT script" |
| 134 | $WAIT_FOR_WORKAROUND_SCRIPT |
| 135 | |
| 136 | if [ $? -ne 0 ]; then |
| 137 | echo "ERROR: $WAIT_FOR_WORKAROUND_SCRIPT failed" |
| 138 | echo "Will stop running docker containers . . ." |
| 139 | docker-compose -f $DOCKER_COMPOSE_FILE_PATH down |
| 140 | exit 1 |
| 141 | fi |
| 142 | |
| 143 | |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 144 | REPO_IP='127.0.0.1' |
| 145 | ROBOT_VARIABLES="-v REPO_IP:${REPO_IP}" |
| 146 | |
| 147 | echo "Finished executing $SCRIPT_HOME/$SCRIPT_NAME" |