Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 3 | source /var/onap/commons |
Victor Morales | 5464664 | 2017-12-08 11:57:42 -0800 | [diff] [blame] | 4 | source /var/onap/config/env-vars |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 5 | source /var/onap/_composed_functions |
| 6 | source /var/onap/_onap_functions |
| 7 | |
Victor Morales | 9651265 | 2017-08-16 13:44:28 -0500 | [diff] [blame] | 8 | export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' |sort -n | head -1) |
Victor Morales | 4ab71c1 | 2017-11-08 07:28:28 -0800 | [diff] [blame] | 9 | export NIC=$(ip route get 8.8.8.8 | awk '{ print $5; exit }') |
| 10 | export IP_ADDRESS=$(ifconfig $NIC | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2) |
Victor Morales | 9651265 | 2017-08-16 13:44:28 -0500 | [diff] [blame] | 11 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 12 | mvn_conf_file=/root/.m2/settings.xml |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 13 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 14 | # configure_dns() - DNS/GW IP address configuration |
| 15 | function configure_dns { |
| 16 | echo "nameserver 10.0.0.1" >> /etc/resolvconf/resolv.conf.d/head |
| 17 | resolvconf -u |
| 18 | } |
| 19 | |
Victor Morales | 4ab71c1 | 2017-11-08 07:28:28 -0800 | [diff] [blame] | 20 | # get_next_ip() - Function that provides the next ip |
| 21 | function get_next_ip { |
| 22 | local ip=${1:-$IP_ADDRESS} |
| 23 | ip_hex=$(printf '%.2X%.2X%.2X%.2X\n' `echo $ip | sed -e 's/\./ /g'`) |
| 24 | next_ip_hex=$(printf %.8X `echo $(( 0x$ip_hex + 1 ))`) |
| 25 | echo $(printf '%d.%d.%d.%d\n' `echo $next_ip_hex | sed -r 's/(..)/0x\1 /g'`) |
| 26 | } |
| 27 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 28 | # _git_timed() - git can sometimes get itself infinitely stuck with transient network |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 29 | # errors or other issues with the remote end. This wraps git in a |
| 30 | # timeout/retry loop and is intended to watch over non-local git |
| 31 | # processes that might hang. |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 32 | function _git_timed { |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 33 | local count=0 |
| 34 | local timeout=0 |
| 35 | |
| 36 | install_package git |
| 37 | until timeout -s SIGINT ${timeout} git "$@"; do |
| 38 | # 124 is timeout(1)'s special return code when it reached the |
| 39 | # timeout; otherwise assume fatal failure |
| 40 | if [[ $? -ne 124 ]]; then |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | count=$(($count + 1)) |
| 45 | if [ $count -eq 3 ]; then |
| 46 | exit 1 |
| 47 | fi |
| 48 | sleep 5 |
| 49 | done |
| 50 | } |
| 51 | |
| 52 | # clone_repo() - Clone Git repository into specific folder |
| 53 | function clone_repo { |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 54 | local repo_url=${3:-"https://git.onap.org/"} |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 55 | local repo=$1 |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 56 | local dest_folder=${2:-$git_src_folder/$repo} |
| 57 | if [ ! -d $dest_folder ]; then |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 58 | if [[ "$debug" == "False" ]]; then |
| 59 | _git_timed clone --quiet ${repo_url}${repo} $dest_folder |
| 60 | else |
| 61 | _git_timed clone ${repo_url}${repo} $dest_folder |
| 62 | fi |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 63 | fi |
| 64 | } |
| 65 | |
Victor Morales | f1f1ba5 | 2017-11-20 16:38:28 -0800 | [diff] [blame] | 66 | # clone_repos() - Function that clones source repositories for a given project |
| 67 | function clone_repos { |
| 68 | local project=$1 |
Victor Morales | 5d21f64 | 2017-12-07 11:54:59 -0800 | [diff] [blame] | 69 | local repo_name=${2:-$project} |
Victor Morales | f1f1ba5 | 2017-11-20 16:38:28 -0800 | [diff] [blame] | 70 | |
Victor Morales | 5464664 | 2017-12-08 11:57:42 -0800 | [diff] [blame] | 71 | for repo in ${repos[$project]}; do |
| 72 | clone_repo $repo ${src_folders[$project]}${repo#*$repo_name} |
Victor Morales | f1f1ba5 | 2017-11-20 16:38:28 -0800 | [diff] [blame] | 73 | done |
| 74 | } |
| 75 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 76 | # _install_bind() - Install bind utils |
| 77 | function _install_bind { |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 78 | install_packages bind9 bind9utils |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 79 | } |
| 80 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 81 | # install_java() - Install java binaries |
| 82 | function install_java { |
Victor Morales | ece790c | 2017-08-08 11:11:36 -0500 | [diff] [blame] | 83 | if is_package_installed openjdk-8-jdk; then |
| 84 | return |
| 85 | fi |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 86 | source /etc/os-release || source /usr/lib/os-release |
| 87 | case ${ID,,} in |
| 88 | *suse) |
| 89 | ;; |
| 90 | ubuntu|debian) |
| 91 | install_package software-properties-common |
| 92 | add-apt-repository -y ppa:openjdk-r/ppa |
| 93 | ;; |
| 94 | rhel|centos|fedora) |
| 95 | ;; |
| 96 | esac |
Victor Morales | 332d7d8 | 2017-11-06 11:51:37 -0800 | [diff] [blame] | 97 | update_repos |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 98 | |
| 99 | # Remove Java 7 |
| 100 | uninstall_packages default-jre openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless |
| 101 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 102 | install_package openjdk-8-jdk |
Victor Morales | 455bece | 2017-07-31 18:40:39 -0500 | [diff] [blame] | 103 | # ca-certificates-java is not a dependency in the Oracle JDK/JRE so this must be explicitly installed. |
| 104 | /var/lib/dpkg/info/ca-certificates-java.postinst configure |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | # install_maven() - Install maven binaries |
| 108 | function install_maven { |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 109 | if is_package_installed maven3; then |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 110 | return |
| 111 | fi |
Victor Morales | ece790c | 2017-08-08 11:11:36 -0500 | [diff] [blame] | 112 | install_java |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 113 | source /etc/os-release || source /usr/lib/os-release |
| 114 | case ${ID,,} in |
| 115 | *suse) |
| 116 | ;; |
| 117 | ubuntu|debian) |
| 118 | install_package software-properties-common |
| 119 | add-apt-repository -y ppa:andrei-pozolotin/maven3 |
| 120 | ;; |
| 121 | rhel|centos|fedora) |
| 122 | ;; |
| 123 | esac |
Victor Morales | 332d7d8 | 2017-11-06 11:51:37 -0800 | [diff] [blame] | 124 | update_repos |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 125 | install_package maven3 |
| 126 | |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 127 | # Remove Java 7 |
| 128 | uninstall_package openjdk-7-jdk |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 129 | |
| 130 | _configure_maven |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Idan Amit | e17b5ec | 2017-08-16 14:17:59 +0300 | [diff] [blame] | 133 | # _configure_docker_settings() - Configures Docker settings |
| 134 | function _configure_docker_settings { |
Victor Morales | cf26999 | 2017-10-18 09:29:55 -0700 | [diff] [blame] | 135 | local docker_conf_backup=/tmp/docker.backup |
| 136 | local docker_conf=/etc/default/docker |
| 137 | local chameleonsocks_filename=chameleonsocks.sh |
Victor Morales | fa9eb9c | 2017-12-18 09:56:13 -0800 | [diff] [blame] | 138 | local max_concurrent_downloads=${1:-3} |
Victor Morales | cf26999 | 2017-10-18 09:29:55 -0700 | [diff] [blame] | 139 | |
Victor Morales | 80f144b | 2018-01-10 07:20:54 -0800 | [diff] [blame] | 140 | cp ${docker_conf} ${docker_conf_backup} |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 141 | if [ $http_proxy ]; then |
Victor Morales | cf26999 | 2017-10-18 09:29:55 -0700 | [diff] [blame] | 142 | echo "export http_proxy=$http_proxy" >> $docker_conf |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 143 | fi |
| 144 | if [ $https_proxy ]; then |
Victor Morales | cf26999 | 2017-10-18 09:29:55 -0700 | [diff] [blame] | 145 | echo "export https_proxy=$https_proxy" >> $docker_conf |
Victor Morales | 5ce0421 | 2017-09-24 09:03:32 -0700 | [diff] [blame] | 146 | #If you have a socks proxy, then use that to connect to the nexus repo |
Kiran | f2824c2 | 2017-09-22 18:05:29 -0700 | [diff] [blame] | 147 | #via a redsocks container |
| 148 | if [ $socks_proxy ]; then |
Victor Morales | cf26999 | 2017-10-18 09:29:55 -0700 | [diff] [blame] | 149 | wget https://raw.githubusercontent.com/crops/chameleonsocks/master/$chameleonsocks_filename |
| 150 | chmod 755 $chameleonsocks_filename |
Victor Morales | 5ce0421 | 2017-09-24 09:03:32 -0700 | [diff] [blame] | 151 | socks=$(echo $socks_proxy | sed -e "s/^.*\///" | sed -e "s/:.*$//") |
| 152 | port=$(echo $socks_proxy | sed -e "s/^.*://") |
Victor Morales | cf26999 | 2017-10-18 09:29:55 -0700 | [diff] [blame] | 153 | PROXY=$socks PORT=$port ./$chameleonsocks_filename --install |
| 154 | rm $chameleonsocks_filename |
Victor Morales | 80f144b | 2018-01-10 07:20:54 -0800 | [diff] [blame] | 155 | cp ${docker_conf_backup} ${docker_conf} |
Kiran | f2824c2 | 2017-09-22 18:05:29 -0700 | [diff] [blame] | 156 | fi |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 157 | fi |
Victor Morales | 80f144b | 2018-01-10 07:20:54 -0800 | [diff] [blame] | 158 | rm ${docker_conf_backup} |
Idan Amit | e17b5ec | 2017-08-16 14:17:59 +0300 | [diff] [blame] | 159 | |
Victor Morales | fa9eb9c | 2017-12-18 09:56:13 -0800 | [diff] [blame] | 160 | echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --max-concurrent-downloads $max_concurrent_downloads \"" >> $docker_conf |
| 161 | usermod -aG docker $USER |
| 162 | |
| 163 | source /etc/os-release || source /usr/lib/os-release |
| 164 | case ${ID,,} in |
| 165 | *suse) |
| 166 | ;; |
| 167 | ubuntu|debian) |
| 168 | service docker restart |
| 169 | sleep 10 |
| 170 | ;; |
| 171 | rhel|centos|fedora) |
| 172 | ;; |
| 173 | esac |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 176 | # install_nodejs() - Download and install NodeJS |
| 177 | function install_nodejs { |
| 178 | if is_package_installed nodejs; then |
| 179 | return |
| 180 | fi |
| 181 | curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - |
| 182 | install_package nodejs |
| 183 | |
| 184 | # Update NPM to latest version |
| 185 | npm install npm -g |
| 186 | } |
| 187 | |
| 188 | # install_python() - Install Python 2.7 and other tools necessary for development. |
| 189 | function install_python { |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 190 | install_packages python2.7 python-dev |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 191 | } |
| 192 | |
Victor Morales | 970ec19 | 2017-07-31 09:10:11 -0500 | [diff] [blame] | 193 | # _install_pip() - Install Python Package Manager |
| 194 | function _install_pip { |
| 195 | install_python |
Victor Morales | 4ab71c1 | 2017-11-08 07:28:28 -0800 | [diff] [blame] | 196 | if ! which pip; then |
Victor Morales | 158c18c | 2017-08-06 11:23:15 -0500 | [diff] [blame] | 197 | curl -sL https://bootstrap.pypa.io/get-pip.py | python |
| 198 | fi |
Victor Morales | 970ec19 | 2017-07-31 09:10:11 -0500 | [diff] [blame] | 199 | } |
| 200 | |
Victor Morales | 88d193e | 2017-11-16 10:50:28 -0800 | [diff] [blame] | 201 | # install_python_package() - Install python modules |
Victor Morales | 970ec19 | 2017-07-31 09:10:11 -0500 | [diff] [blame] | 202 | function install_python_package { |
Victor Morales | 4ab71c1 | 2017-11-08 07:28:28 -0800 | [diff] [blame] | 203 | local python_packages=$@ |
Victor Morales | 970ec19 | 2017-07-31 09:10:11 -0500 | [diff] [blame] | 204 | |
| 205 | _install_pip |
Victor Morales | 4ab71c1 | 2017-11-08 07:28:28 -0800 | [diff] [blame] | 206 | pip install $python_packages |
Victor Morales | 970ec19 | 2017-07-31 09:10:11 -0500 | [diff] [blame] | 207 | } |
| 208 | |
Victor Morales | 88d193e | 2017-11-16 10:50:28 -0800 | [diff] [blame] | 209 | # install_python_requirements() - Install a list of python modules defined in requirement.txt file |
| 210 | function install_python_requirements { |
| 211 | local python_project_path=$1 |
| 212 | |
| 213 | _install_pip |
| 214 | pushd $python_project_path |
| 215 | pip install -r requirements.txt |
| 216 | popd |
| 217 | } |
| 218 | |
Victor Morales | 970ec19 | 2017-07-31 09:10:11 -0500 | [diff] [blame] | 219 | # install_docker() - Download and install docker-engine |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 220 | function install_docker { |
Victor Morales | fa9eb9c | 2017-12-18 09:56:13 -0800 | [diff] [blame] | 221 | if $(docker version &>/dev/null); then |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 222 | return |
| 223 | fi |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 224 | source /etc/os-release || source /usr/lib/os-release |
| 225 | case ${ID,,} in |
| 226 | *suse) |
| 227 | ;; |
| 228 | ubuntu|debian) |
Victor Morales | 071b81c | 2017-11-07 14:13:07 -0800 | [diff] [blame] | 229 | install_packages software-properties-common linux-image-extra-$(uname -r) linux-image-extra-virtual apt-transport-https ca-certificates curl |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 230 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - |
| 231 | add-apt-repository \ |
| 232 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ |
| 233 | $(lsb_release -cs) stable" |
| 234 | ;; |
| 235 | rhel|centos|fedora) |
| 236 | ;; |
| 237 | esac |
Victor Morales | 332d7d8 | 2017-11-06 11:51:37 -0800 | [diff] [blame] | 238 | update_repos |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 239 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 240 | install_package docker-ce |
Idan Amit | e17b5ec | 2017-08-16 14:17:59 +0300 | [diff] [blame] | 241 | _configure_docker_settings |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | # pull_docker_image() - Pull Docker container image from the Public Docker Registry Hub |
| 245 | function pull_docker_image { |
| 246 | install_docker |
| 247 | local image=$1 |
| 248 | local tag=$2 |
| 249 | docker pull ${image} |
| 250 | if [ ${tag} ]; then |
| 251 | docker tag ${image} $tag |
| 252 | fi |
| 253 | } |
| 254 | |
Victor Morales | 472a306 | 2018-02-02 08:26:50 -0800 | [diff] [blame] | 255 | # wait_docker_pull() - Function that waits for all docker pull processes |
| 256 | function wait_docker_pull { |
| 257 | local counter=60 |
| 258 | local delay=${1:-60} |
| 259 | |
| 260 | sleep $delay |
| 261 | while [ $(ps -ef | grep "docker pull" | wc -l) -gt 1 ]; do |
| 262 | sleep $delay |
| 263 | counter=$((counter - 1)) |
| 264 | if [ "$counter" -eq 0 ]; then |
| 265 | break |
| 266 | fi |
| 267 | done |
| 268 | } |
| 269 | |
Victor Morales | 9d205bc | 2017-12-01 17:52:07 -0800 | [diff] [blame] | 270 | # run_docker_image() - Starts a Docker instance |
| 271 | function run_docker_image { |
| 272 | install_docker |
| 273 | docker run $@ |
| 274 | } |
| 275 | |
Victor Morales | 96fe388 | 2018-03-02 14:08:39 -0800 | [diff] [blame^] | 276 | # run_docker_compose() - Ensures that docker compose is installed and run it in background |
| 277 | function run_docker_compose { |
| 278 | local folder=$1 |
| 279 | |
| 280 | install_docker_compose |
| 281 | pushd $folder |
| 282 | /opt/docker/docker-compose up -d |
| 283 | popd |
| 284 | } |
| 285 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 286 | # install_docker_compose() - Download and install docker-engine |
| 287 | function install_docker_compose { |
| 288 | local docker_compose_version=${1:-1.12.0} |
| 289 | if [ ! -d /opt/docker ]; then |
| 290 | mkdir /opt/docker |
| 291 | curl -L https://github.com/docker/compose/releases/download/$docker_compose_version/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose |
| 292 | chmod +x /opt/docker/docker-compose |
| 293 | fi |
| 294 | } |
| 295 | |
| 296 | # _install_ODL() - Download and Install OpenDayLight SDN controller |
| 297 | function _install_ODL { |
| 298 | if [ ! -d /opt/opendaylight/current ]; then |
| 299 | mkdir -p /opt/opendaylight/ |
| 300 | wget "https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/"$odl_version"/distribution-karaf-"$odl_version".tar.gz" -P /opt/ |
Victor Morales | fa9eb9c | 2017-12-18 09:56:13 -0800 | [diff] [blame] | 301 | tar xvf "/opt/distribution-karaf-"$odl_version".tar.gz" -C /tmp/ |
| 302 | mv "/tmp/distribution-karaf-"$odl_version /opt/opendaylight/current |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 303 | rm -rf "/opt/distribution-karaf-"$odl_version".tar.gz" |
| 304 | fi |
| 305 | } |
| 306 | |
| 307 | # start_ODL() - Start OpenDayLight SDN controller |
| 308 | function start_ODL { |
| 309 | _install_ODL |
| 310 | if [ -d /opt/opendaylight ]; then |
| 311 | export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre |
| 312 | /opt/opendaylight/current/bin/start |
| 313 | sleep 180 |
| 314 | /opt/opendaylight/current/bin/client feature:install odl-dlux-all |
| 315 | fi |
| 316 | } |
| 317 | |
| 318 | # compile_src() - Function that compiles the java source code thru maven |
| 319 | function compile_src { |
| 320 | local src_folder=$1 |
| 321 | pushd $src_folder |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 322 | local mvn_build='mvn clean install -DskipTests=true -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dadditionalparam=-Xdoclint:none' |
| 323 | if [[ "$debug" == "False" ]]; then |
| 324 | mvn_build+=" -q" |
| 325 | fi |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 326 | if [ -f pom.xml ]; then |
| 327 | install_maven |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 328 | echo "Compiling $src_folder folder..." |
| 329 | eval $mvn_build |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 330 | fi |
| 331 | popd |
| 332 | } |
| 333 | |
Victor Morales | f1f1ba5 | 2017-11-20 16:38:28 -0800 | [diff] [blame] | 334 | # compile_repos() - Function that compiles source repositories for a given project |
| 335 | function compile_repos { |
| 336 | local project=$1 |
Victor Morales | f1f1ba5 | 2017-11-20 16:38:28 -0800 | [diff] [blame] | 337 | |
Victor Morales | 5464664 | 2017-12-08 11:57:42 -0800 | [diff] [blame] | 338 | for repo in ${repos[$project]}; do |
| 339 | compile_src ${src_folders[$project]}${repo#*$project} |
Victor Morales | f1f1ba5 | 2017-11-20 16:38:28 -0800 | [diff] [blame] | 340 | done |
| 341 | } |
| 342 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 343 | # build_docker_image() - Build Docker container image from source code |
| 344 | function build_docker_image { |
| 345 | local src_folder=$1 |
| 346 | local profile=$2 |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 347 | install_docker |
| 348 | pushd $src_folder |
| 349 | |
Victor Morales | 9d205bc | 2017-12-01 17:52:07 -0800 | [diff] [blame] | 350 | if [ -f pom.xml ]; then |
| 351 | install_maven |
| 352 | # Cleanup external repo |
| 353 | sed -i 's|${docker.push.registry}/||g' pom.xml |
Victor Morales | be84471 | 2018-01-22 10:07:28 -0800 | [diff] [blame] | 354 | local docker_build="mvn clean package docker:build -DskipTests=true -Dmaven.test.skip=true -Dmaven.javadoc.skip=true" |
Victor Morales | 9d205bc | 2017-12-01 17:52:07 -0800 | [diff] [blame] | 355 | if [ $profile ]; then |
| 356 | docker_build+=" -P $profile" |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 357 | fi |
Victor Morales | 472a306 | 2018-02-02 08:26:50 -0800 | [diff] [blame] | 358 | if [[ "$debug" == "False" ]]; then |
| 359 | docker_build+=" -q" |
| 360 | fi |
Victor Morales | 9d205bc | 2017-12-01 17:52:07 -0800 | [diff] [blame] | 361 | if [ $http_proxy ]; then |
| 362 | if ! grep -ql "docker.buildArg.http_proxy" pom.xml ; then |
| 363 | docker_build+=" -Ddocker.buildArg.http_proxy=$http_proxy" |
| 364 | fi |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 365 | if ! grep -ql "docker.buildArg.HTTP_PROXY" pom.xml ; then |
Victor Morales | 9d205bc | 2017-12-01 17:52:07 -0800 | [diff] [blame] | 366 | docker_build+=" -Ddocker.buildArg.HTTP_PROXY=$http_proxy" |
| 367 | fi |
| 368 | fi |
| 369 | if [ $https_proxy ]; then |
| 370 | if ! grep -ql "docker.buildArg.https_proxy" pom.xml ; then |
| 371 | docker_build+=" -Ddocker.buildArg.https_proxy=$https_proxy" |
| 372 | fi |
| 373 | if ! grep -ql "docker.buildArg.HTTPS_PROXY" pom.xml ; then |
| 374 | docker_build+=" -Ddocker.buildArg.HTTPS_PROXY=$https_proxy" |
| 375 | fi |
| 376 | fi |
| 377 | elif [ -f Dockerfile ]; then |
| 378 | # NOTE: Workaround for dmmapbc images |
| 379 | sed -i '/LocalKey/d' Dockerfile |
| 380 | sed -i "s/nexus3.onap.org\:10003\///g" Dockerfile |
| 381 | local docker_build="docker build -t $profile -f ./Dockerfile ." |
| 382 | if [ $http_proxy ]; then |
| 383 | docker_build+=" --build-arg http_proxy=$http_proxy" |
| 384 | docker_build+=" --build-arg HTTP_PROXY=$http_proxy" |
| 385 | fi |
| 386 | if [ $https_proxy ]; then |
| 387 | docker_build+=" --build-arg https_proxy=$https_proxy" |
| 388 | docker_build+=" --build-arg HTTPS_PROXY=$https_proxy" |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 389 | fi |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 390 | fi |
Victor Morales | 9d205bc | 2017-12-01 17:52:07 -0800 | [diff] [blame] | 391 | echo $docker_build |
| 392 | eval $docker_build |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 393 | popd |
| 394 | } |
Victor Morales | fa9eb9c | 2017-12-18 09:56:13 -0800 | [diff] [blame] | 395 | |
| 396 | # mount_external_partition() - Create partition and mount the external volume |
| 397 | function mount_external_partition { |
| 398 | local dev_name="/dev/$1" |
| 399 | local mount_dir=$2 |
| 400 | |
| 401 | sfdisk $dev_name << EOF |
| 402 | ; |
| 403 | EOF |
| 404 | mkfs -t ext4 ${dev_name}1 |
| 405 | mkdir -p $mount_dir |
| 406 | mount ${dev_name}1 $mount_dir |
| 407 | echo "${dev_name}1 $mount_dir ext4 errors=remount-ro,noatime,barrier=0 0 1" >> /etc/fstab |
| 408 | } |
Nate Potter | fdf88f3 | 2018-01-17 09:29:35 -0800 | [diff] [blame] | 409 | |
Victor Morales | 96fe388 | 2018-03-02 14:08:39 -0800 | [diff] [blame^] | 410 | # add_no_proxy_value() - Add no_proxy values into environment file, used for internal IPs generated at deploy time |
Nate Potter | fdf88f3 | 2018-01-17 09:29:35 -0800 | [diff] [blame] | 411 | function add_no_proxy_value { |
| 412 | if [[ `grep "no_proxy" /etc/environment` ]]; then |
| 413 | sed -i.bak "s/^no_proxy.*$/&,$1/" /etc/environment |
| 414 | else |
| 415 | echo "no_proxy=$1" >> /etc/environment |
| 416 | fi |
| 417 | if [[ `grep "NO_PROXY" /etc/environment` ]]; then |
| 418 | sed -i.bak "s/^NO_PROXY.*$/&,$1/" /etc/environment |
| 419 | else |
| 420 | echo "NO_PROXY=$1" >> /etc/environment |
| 421 | fi |
| 422 | } |
Victor Morales | 96fe388 | 2018-03-02 14:08:39 -0800 | [diff] [blame^] | 423 | |