buildOnVM.sh 9.52 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# *      http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */
22

23 24
function build_usage {
    echo "OAI CI VM script"
25 26 27 28 29 30 31 32 33
    echo "   Original Author: Raphael Defosseux"
    echo "   Requirements:"
    echo "     -- uvtool uvtool-libvirt apt-cacher"
    echo "     -- xenial image already synced"
    echo "   Default:"
    echo "     -- eNB with USRP"
    echo ""
    echo "Usage:"
    echo "------"
34
    echo "    oai-ci-vm-tool build [OPTIONS]"
35
    echo ""
36
    echo "Mandatory Options:"
37
    echo "--------"
Raphael Defosseux's avatar
Raphael Defosseux committed
38 39 40 41 42 43
    echo "    --job-name #### OR -jn ####"
    echo "    Specify the name of the Jenkins job."
    echo ""
    echo "    --build-id #### OR -id ####"
    echo "    Specify the build ID of the Jenkins job."
    echo ""
44
    echo "    --workspace #### OR -ws ####"
45
    echo "    Specify the workspace."
46
    echo ""
47 48 49
    echo "Options:"
    echo "--------"
    variant_usage
50 51 52 53
    echo "    Specify the variant to build."
    echo ""
    echo "    --keep-vm-alive OR -k"
    echo "    Keep the VM alive after the build."
54
    echo ""
55 56 57
    echo "    --daemon OR -D"
    echo "    Run as daemon"
    echo ""
58 59 60 61 62
    echo "    --help OR -h"
    echo "    Print this help message."
    echo ""
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76
function build_on_vm {
    if [ ! -f $JENKINS_WKSP/localZip.zip ]
    then
        echo "Missing localZip.zip file!"
        STATUS=1
        return
    fi
    if [ ! -f /etc/apt/apt.conf.d/01proxy ]
    then
        echo "Missing /etc/apt/apt.conf.d/01proxy file!"
        echo "Is apt-cacher installed and configured?"
        STATUS=1
        return
    fi
77 78

    echo "############################################################"
79
    echo "OAI CI VM script"
80
    echo "############################################################"
81

82 83 84 85 86
    echo "VM_NAME             = $VM_NAME"
    echo "VM_CMD_FILE         = $VM_CMDS"
    echo "JENKINS_WKSP        = $JENKINS_WKSP"
    echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
    echo "BUILD_OPTIONS       = $BUILD_OPTIONS"
87

88
    IS_VM_ALIVE=`uvt-kvm list | grep -c $VM_NAME`
89

90
    if [ $IS_VM_ALIVE -eq 0 ]
91
    then
92 93 94 95 96
        echo "VM_MEMORY           = $VM_MEMORY MBytes"
        echo "VM_CPU              = $VM_CPU"
        echo "############################################################"
        echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base"
        echo "############################################################"
97
        acquire_vm_create_lock
98
        uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu $VM_CPU --unsafe-caching --template ci-scripts/template-host.xml
99 100
        echo "Waiting for VM to be started"
        uvt-kvm wait $VM_NAME --insecure
101

102 103 104 105 106 107
        VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
        echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
        release_vm_create_lock
    else
        echo "Waiting for VM to be started"
        uvt-kvm wait $VM_NAME --insecure
108

109 110 111
        VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
        echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
    fi
112

113
    echo "############################################################"
114
    echo "Copying GIT repo into VM ($VM_NAME)" 
115
    echo "############################################################"
116 117 118 119 120 121
    if [[ "$VM_NAME" == *"-flexran-rtc"* ]]
    then
        scp -o StrictHostKeyChecking=no $JENKINS_WKSP/flexran/flexran.zip ubuntu@$VM_IP_ADDR:/home/ubuntu/localZip.zip
    else
        scp -o StrictHostKeyChecking=no $JENKINS_WKSP/localZip.zip ubuntu@$VM_IP_ADDR:/home/ubuntu
    fi
122
    scp -o StrictHostKeyChecking=no /etc/apt/apt.conf.d/01proxy ubuntu@$VM_IP_ADDR:/home/ubuntu
123

124 125 126 127 128 129
    echo "############################################################"
    echo "Running install and build script on VM ($VM_NAME)"
    echo "############################################################"
    echo "sudo cp 01proxy /etc/apt/apt.conf.d/" > $VM_CMDS
    echo "touch /home/ubuntu/.hushlogin" >> $VM_CMDS
    if [[ "$VM_NAME" == *"-cppcheck"* ]]
130
    then
131
        if [ $DAEMON -eq 0 ]
132
        then
133 134 135 136 137 138 139
            echo "echo \"sudo apt-get --yes --quiet install zip cppcheck \"" >> $VM_CMDS
            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
            echo "sudo apt-get --yes install zip cppcheck >> zip-install.txt 2>&1" >> $VM_CMDS
        else
            echo "echo \"sudo apt-get --yes --quiet install zip daemon cppcheck \"" >> $VM_CMDS
            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
            echo "sudo apt-get --yes install zip daemon cppcheck >> zip-install.txt 2>&1" >> $VM_CMDS
140
        fi
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    fi
    if [[ "$VM_NAME" == *"-flexran-rtc"* ]]
    then
        if [ $DAEMON -eq 0 ]
        then
            echo "echo \"sudo apt-get --yes --quiet install zip curl jq \"" >> $VM_CMDS
            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
            echo "sudo apt-get --yes install zip curl jq >> zip-install.txt 2>&1" >> $VM_CMDS
        else
            echo "echo \"sudo apt-get --yes --quiet install zip daemon curl jq \"" >> $VM_CMDS
            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
            echo "sudo apt-get --yes install zip daemon curl jq >> zip-install.txt 2>&1" >> $VM_CMDS
        fi
    fi
    if [[ "$VM_NAME" != *"-cppcheck"* ]] && [[ "$VM_NAME" != *"-flexran-rtc"* ]]
    then
157
        if [ $DAEMON -eq 0 ]
158
        then
159 160 161 162 163 164 165
            echo "echo \"sudo apt-get --yes --quiet install zip subversion libboost-dev \"" >> $VM_CMDS
            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
            echo "sudo apt-get --yes install zip subversion libboost-dev >> zip-install.txt 2>&1" >> $VM_CMDS
        else
            echo "echo \"sudo apt-get --yes --quiet install zip daemon subversion libboost-dev \"" >> $VM_CMDS
            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
            echo "sudo apt-get --yes install zip daemon subversion libboost-dev >> zip-install.txt 2>&1" >> $VM_CMDS
166
        fi
167 168 169 170 171 172 173 174 175 176 177 178
    fi
    echo "mkdir tmp" >> $VM_CMDS
    echo "cd tmp" >> $VM_CMDS
    echo "echo \"unzip -qq -DD ../localZip.zip\"" >> $VM_CMDS
    echo "unzip -qq -DD ../localZip.zip" >> $VM_CMDS
    if [[ "$VM_NAME" == *"-cppcheck"* ]]
    then
        echo "mkdir cmake_targets/log" >> $VM_CMDS
        echo "chmod 777 cmake_targets/log" >> $VM_CMDS
        echo "cp /home/ubuntu/zip-install.txt cmake_targets/log" >> $VM_CMDS
        echo "echo \"cppcheck $BUILD_OPTIONS . \"" >> $VM_CMDS
        if [ $DAEMON -eq 0 ]
179
        then
180
            echo "cppcheck $BUILD_OPTIONS . 2> cmake_targets/log/cppcheck.xml 1> cmake_targets/log/cppcheck_build.txt" >> $VM_CMDS
181
        else
182 183 184 185
            echo "echo \"cppcheck $BUILD_OPTIONS .\" > ./my-vm-build.sh" >> $VM_CMDS
            echo "chmod 775 ./my-vm-build.sh " >> $VM_CMDS
            echo "sudo -E daemon --inherit --unsafe --name=build_daemon --chdir=/home/ubuntu/tmp -O /home/ubuntu/tmp/cmake_targets/log/cppcheck_build.txt -E /home/ubuntu/tmp/cmake_targets/log/cppcheck.xml ./my-vm-build.sh" >> $VM_CMDS
        fi
186 187 188 189 190 191 192 193 194 195 196 197 198
    fi
    if [[ "$VM_NAME" == *"-flexran-rtc"* ]]
    then
        echo "mkdir -p cmake_targets/log" >> $VM_CMDS
        echo "chmod 777 cmake_targets/log" >> $VM_CMDS
        echo "cp /home/ubuntu/zip-install.txt cmake_targets/log" >> $VM_CMDS
        echo "echo \"./tools/install_dependencies \"" >> $VM_CMDS
        echo "./tools/install_dependencies > cmake_targets/log/install-build.txt 2>&1" >> $VM_CMDS
        echo "echo \"$BUILD_OPTIONS \"" >> $VM_CMDS
        echo "$BUILD_OPTIONS > cmake_targets/log/rt_controller.Rel14.txt 2>&1" >> $VM_CMDS
    fi
    if [[ "$VM_NAME" != *"-cppcheck"* ]] && [[ "$VM_NAME" != *"-flexran-rtc"* ]]
    then
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
        echo "echo \"source oaienv\"" >> $VM_CMDS
        echo "source oaienv" >> $VM_CMDS
        echo "cd cmake_targets/" >> $VM_CMDS
        echo "mkdir log" >> $VM_CMDS
        echo "chmod 777 log" >> $VM_CMDS
        echo "cp /home/ubuntu/zip-install.txt log" >> $VM_CMDS
        if [ $DAEMON -eq 0 ]
        then
            echo "echo \"./build_oai -I $BUILD_OPTIONS \"" >> $VM_CMDS
            echo "./build_oai -I $BUILD_OPTIONS > log/install-build.txt 2>&1" >> $VM_CMDS
        else
            echo "echo \"./build_oai -I $BUILD_OPTIONS\" > ./my-vm-build.sh" >> $VM_CMDS
            echo "chmod 775 ./my-vm-build.sh " >> $VM_CMDS
            echo "echo \"sudo -E daemon --inherit --unsafe --name=build_daemon --chdir=/home/ubuntu/tmp/cmake_targets -o /home/ubuntu/tmp/cmake_targets/log/install-build.txt ./my-vm-build.sh\"" >> $VM_CMDS
            echo "sudo -E daemon --inherit --unsafe --name=build_daemon --chdir=/home/ubuntu/tmp/cmake_targets -o /home/ubuntu/tmp/cmake_targets/log/install-build.txt ./my-vm-build.sh" >> $VM_CMDS
214
        fi
215
    fi
216 217 218
    ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS
    rm -f $VM_CMDS
}