#!/bin/bash set -o xtrace source /var/onap/commons source /var/onap/_composed_functions source /var/onap/_onap_functions mvn_conf_file=/root/.m2/settings.xml git_src_folder=/opt # export_env_vars() - Export environment variables function export_env_vars { export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' |sort -n | head -1) } # configure_dns() - DNS/GW IP address configuration function configure_dns { echo "nameserver 10.0.0.1" >> /etc/resolvconf/resolv.conf.d/head resolvconf -u } # _git_timed() - git can sometimes get itself infinitely stuck with transient network # errors or other issues with the remote end. This wraps git in a # timeout/retry loop and is intended to watch over non-local git # processes that might hang. function _git_timed { local count=0 local timeout=0 install_package git until timeout -s SIGINT ${timeout} git "$@"; do # 124 is timeout(1)'s special return code when it reached the # timeout; otherwise assume fatal failure if [[ $? -ne 124 ]]; then exit 1 fi count=$(($count + 1)) if [ $count -eq 3 ]; then exit 1 fi sleep 5 done } # clone_repo() - Clone Git repository into specific folder function clone_repo { local repo_url=https://git.onap.org/ local repo=$1 local dest_folder=${2:-$git_src_folder/$repo} if [ ! -d $dest_folder ]; then _git_timed clone -b $gerrit_branch --single-branch ${repo_url}${repo} $dest_folder else pushd $dest_folder _git_timed pull popd fi } # install_dev_tools() - Install basic dependencies function install_dev_tools { install_package apt-transport-https install_package ca-certificates install_package curl } # _install_bind() - Install bind utils function _install_bind { install_package bind9 install_package bind9utils } # install_java() - Install java binaries function install_java { install_package software-properties-common add-apt-repository -y ppa:openjdk-r/ppa install_package openjdk-8-jdk } # install_maven() - Install maven binaries function install_maven { if is_package_installed maven3; then return fi if ! is_package_installed openjdk-8-jdk; then install_java fi install_package software-properties-common add-apt-repository -y ppa:andrei-pozolotin/maven3 install_package maven3 # Force Maven3 to use jdk8 apt-get purge openjdk-7-jdk -y _configure_maven } # _configure_docker_proxy() - Configures proxy in Docker from ENV function _configure_docker_proxy { if [ $http_proxy ]; then echo "export http_proxy=$http_proxy" >> /etc/default/docker fi if [ $https_proxy ]; then echo "export https_proxy=$https_proxy" >> /etc/default/docker fi } # install_nodejs() - Download and install NodeJS function install_nodejs { if is_package_installed nodejs; then return fi curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - install_package nodejs # Update NPM to latest version npm install npm -g } # install_python() - Install Python 2.7 and other tools necessary for development. function install_python { install_package python2.7 install_package python-dev curl -sL https://bootstrap.pypa.io/get-pip.py | python pip install tox } # install_docker() - Download and install docker-engine function install_docker { if is_package_installed docker-ce; then return fi install_package software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" install_package docker-ce _configure_docker_proxy service docker restart sleep 10 } # pull_docker_image() - Pull Docker container image from the Public Docker Registry Hub function pull_docker_image { install_docker local image=$1 local tag=$2 docker pull ${image} if [ ${tag} ]; then docker tag ${image} $tag fi } # install_docker_compose() - Download and install docker-engine function install_docker_compose { local docker_compose_version=${1:-1.12.0} if [ ! -d /opt/docker ]; then mkdir /opt/docker curl -L https://github.com/docker/compose/releases/download/$docker_compose_version/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose chmod +x /opt/docker/docker-compose fi } # _install_ODL() - Download and Install OpenDayLight SDN controller function _install_ODL { if [ ! -d /opt/opendaylight/current ]; then mkdir -p /opt/opendaylight/ wget "https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/"$odl_version"/distribution-karaf-"$odl_version".tar.gz" -P /opt/ tar xvf "/opt/distribution-karaf-"$odl_version".tar.gz" -C /opt/ mv "/opt/distribution-karaf-"$odl_version /opt/opendaylight/current rm -rf "/opt/distribution-karaf-"$odl_version".tar.gz" fi } # start_ODL() - Start OpenDayLight SDN controller function start_ODL { _install_ODL if [ -d /opt/opendaylight ]; then export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre /opt/opendaylight/current/bin/start sleep 180 /opt/opendaylight/current/bin/client feature:install odl-dlux-all fi } # compile_src() - Function that compiles the java source code thru maven function compile_src { local src_folder=$1 pushd $src_folder if [ -f pom.xml ]; then install_maven mvn clean install -U -DskipTests=true -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dadditionalparam=-Xdoclint:none fi popd } # build_docker_image() - Build Docker container image from source code function build_docker_image { local src_folder=$1 local profile=$2 install_maven install_docker pushd $src_folder # Cleanup external repo sed -i 's|${docker.push.registry}/||g' pom.xml local mvn_docker="mvn clean package docker:build" if [ $profile ]; then mvn_docker+=" -P $profile" fi if [ $http_proxy ]; then if ! grep -ql "docker.buildArg.http_proxy" pom.xml ; then mvn_docker+=" -Ddocker.buildArg.http_proxy=$http_proxy" fi if ! grep -ql "docker.buildArg.HTTP_PROXY" pom.xml ; then mvn_docker+=" -Ddocker.buildArg.HTTP_PROXY=$http_proxy" fi fi if [ $https_proxy ]; then if ! grep -ql "docker.buildArg.https_proxy" pom.xml ; then mvn_docker+=" -Ddocker.buildArg.https_proxy=$https_proxy" fi if ! grep -ql "docker.buildArg.HTTPS_PROXY" pom.xml ; then mvn_docker+=" -Ddocker.buildArg.HTTPS_PROXY=$https_proxy" fi fi eval $mvn_docker popd }