Add build folder for ONAP Offline Build Jobs
[infra/cicd.git] / jjb / onap-offline / build_jobs / scripts / 2_build_preparation.sh
1 #!/bin/bash
2
3 set -x
4
5 ### Some other ways to get build_node_ip in case you don't want to make a file on Jenkins server ###
6 #build_node_ip=$(openstack server list -c Name -c Networks -f value | egrep ${stack_name} | awk '{print $NF}')
7 #build_node_ip=$(openstack server show ${stack_name} -f value -c addresses | cut -d' ' -f2 )
8
9 ### Setting variables used in this script ###
10 build_node_ip=$(openstack server list -c Name -c Networks -f value | egrep ${openstack_build_stack_name} | awk '{print $NF}' | sed 's/.*=//g')
11 ssh_cmd="ssh -o StrictHostKeychecking=no -i ${ssh_key} ${remote_user}@${build_node_ip}"
12 docker_repo="https://download.docker.com/linux/centos/docker-ce.repo"
13
14 ####################################
15 ### PREPARATIONS FOR CENTOS ONLY ###
16 ####################################
17
18 ### Required by special centos docker recommended by ONAP ###
19 RESULT=$(${ssh_cmd} "sudo yum-config-manager --add-repo ${docker_repo}")
20 if [[ $? -ne 0 ]]; then
21   echo "Failed to install add repo successfully: $RESULT"
22   exit -1
23 fi
24
25 ### Enable epel repo for npm and jq ###
26 RESULT=$(${ssh_cmd} "sudo yum install -y epel-release")
27 if [[ $? -ne 0 ]]; then
28   echo "Failed to install epel-release successfully: $RESULT"
29   exit -1
30 fi
31
32 ### Install following packages ###
33 RESULT=$(${ssh_cmd} "sudo yum install -y docker-ce-18.09.5 python-pip git createrepo expect nodejs npm jq")
34 if [[ $? -ne 0 ]]; then
35   echo "Failed to install packages successfully: $RESULT"
36   exit -1
37 fi
38
39 ### Offline Installer is using python3 now, thus need to install python3 and pip3 ###
40 RESULT=$(${ssh_cmd} "sudo yum install -y python36 python36-pip")
41 if [[ $? -ne 0 ]]; then
42   echo "Failed to install packages: $RESULT"
43   exit -1
44 fi
45
46 ### Install Twine, specific version 1.15.0 used, because new version 2.0.0 breaks the installation ###
47 RESULT=$(${ssh_cmd} "sudo pip install twine==1.15.0")
48 if [[ $? -ne 0 ]]; then
49   echo "Failed to pip install twine: $RESULT"
50   exit -1
51 fi
52
53 ### Starting Docker Service ###
54 RESULT=$(${ssh_cmd} "sudo service docker start")
55 if [[ $? -ne 0 ]]; then
56   echo "Failed to pip install twine: $RESULT"
57   exit -1
58 fi
59
60 ### Clone the OFfline Installer repo ###
61 RESULT=$(${ssh_cmd} " sudo git clone https://gerrit.onap.org/r/oom/offline-installer /tmp/onap-offline")
62 if [[ $? -ne 0 ]]; then
63   echo "Failed to clone onap/offline/install repo: $RESULT"
64   exit -1
65 fi
66 sleep 5
67
68 ### Install the required python packages ###
69 RESULT=$(${ssh_cmd} "sudo pip3 install -r /tmp/onap-offline/build/requirements.txt")
70 if [[ $? -ne 0 ]]; then
71   echo "Failed to install: $RESULT"
72   exit -1
73 fi
74 RESULT=$(${ssh_cmd} "sudo pip3 install -r /tmp/onap-offline/build/download/requirements.txt")
75 if [[ $? -ne 0 ]]; then
76   echo "Failed to install: $RESULT"
77   exit -1
78 fi