45d495f2a052e2b60413238be48b32eaaacadcc9
[osm/devops.git] / jenkins / host / start_build
1 #!/bin/bash
2 #   Copyright 2016 RIFT.IO Inc
3 #   Copyright 2016 Telefónica Investigación y Desarrollo S.A.U.
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 # start-build is run on a host to start a MDG build
18 #
19 # 24 June 2016 -- Jeremy Mordkoff -- Genesis
20 #              -- Gerardo Garcia
21
22
23 HERE=$(realpath $(dirname $0))
24 OSM_JENKINS=$(dirname $HERE)
25 . $OSM_JENKINS/common/all_funcs
26
27 [ $# -lt 1 ] && FATAL "arg is MDG name"
28
29 export OSM_MDG=$1
30 shift
31 OSM_load_config
32
33 if ! container_exists $OSM_BUILD_CONTAINER; then
34         CONTAINER_OPTS=""
35         [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
36         [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
37         create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
38         wait_container_up $OSM_BUILD_CONTAINER
39         RE="fedora|fc[0-9]"
40         if [[ $OSM_BASE_IMAGE =~ $RE ]]; then
41                 container_exec $OSM_BUILD_CONTAINER yum -y install git tar make sudo
42         else
43                 container_exec $OSM_BUILD_CONTAINER apt -y install git realpath make sudo 
44         fi
45         if [ ${OSM_USE_LOCAL_DEVOPS:-false} ]; then
46                 container_push_devops $OSM_BUILD_CONTAINER
47         else
48                 container_exec $OSM_BUILD_CONTAINER git clone ${OSM_GIT_URL}/devops
49         fi
50 else
51         if [ ${OSM_USE_LOCAL_DEVOPS:-false} ]; then
52                 container_push_devops $OSM_BUILD_CONTAINER
53         else
54                 container_exec $OSM_BUILD_CONTAINER git -C devops pull
55         fi
56 fi
57
58 container_exec $OSM_BUILD_CONTAINER ./devops/jenkins/$OSM_MDG/start_build $*
59 RC=$?
60 INFO "$OSM_MDG build complete. Return code was $RC"
61 exit $RC
62