Script to build plain OVS RPM from master.
[ovsnfv.git] / ci / buildovs.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Red Hat Inc. and others.
4 # therbert@redhat.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Check to verify that I am being run by Jenkins CI.
12
13 if [ -z ${WORKSPACE+1} ]; then
14     # We are not being run by Jenkins.
15     export WORKSPACE=$HOME/opnfv/ovsnfv
16 else
17     export JENKINS=true
18 fi
19
20
21 if [ -z ${OVSTAG+1} ]; then
22     export TAG=master
23 else
24     export TAG=$OVSTAG
25 fi
26
27 export DATE=`date +%Y-%m-%d`
28
29 export BUILD_BASE=$WORKSPACE/build
30
31
32
33 if [ ! -d $BUILD_BASE ]
34 then
35     mkdir -p $BUILD_BASE
36     if [ ! -f $BUILD_BASE/config ]; then
37         touch $BUILd_BASE/config
38     fi
39 fi
40
41 export PATH=$PATH:$WORKSPACE/ci:$BUILD_BASE
42
43 source $BUILD_BASE/config
44
45 cd $BUILD_BASE
46 export TOPDIR=$BUILD_BASE
47
48 # build variables
49
50 export TMP_RELEASE_DIR=$TOPDIR/release
51 export CACHE_DIR=$TOPDIR/cache
52 export TMPDIR=$TOPDIR/scratch
53 export RPMDIR=$TOPDIR/rpmbuild
54
55 echo "--------------------------------------------------"
56 echo "Build OVS RPM from upstream git $TAG"
57 echo
58
59 mkdir -p $RPMDIR/BUILD
60 mkdir -p $RPMDIR/RPMS
61 mkdir -p $RPMDIR/SOURCES
62 mkdir -p $RPMDIR/SPECS
63 mkdir -p $RPMDIR/SRPMS
64
65 if [ ! -d $TMP_RELEASE_DIR ]
66 then
67     mkdir -p $TMP_RELEASE_DIR
68 fi
69
70 # Centos build server should support the following build prerequisites
71
72 # yum install gcc make python-devel openssl-devel kernel-devel graphviz \
73 # kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
74 # libtool
75
76 if [ -d $TMPDIR ]
77 then
78     rm -rf $TMPDIR
79 fi
80
81 mkdir $TMPDIR
82
83 cd $TMPDIR
84
85 echo "---------------------"
86 echo "Clone git repo $TAG"
87 echo
88 git clone https://github.com/openvswitch/ovs.git
89
90 cd ovs
91 echo "--------------------"
92 echo "Checkout OVS $TAG"
93 echo
94 if [[ ! "$TAG" =~ "master" ]]; then
95     git checkout $TAG
96 fi
97 ./boot.sh
98 ./configure
99 echo "--------------------"
100 echo "Make OVS $TAG"
101 echo
102 make
103 #
104 # Get version for master
105 #
106 echo "--------------------"
107 echo "Get OVS version for $TAG"
108 echo
109 if [[ "$TAG" =~ "master" ]]; then
110     v=$($TMPDIR/ovs/utilities/ovs-vsctl --version | head -1 | cut -d' ' -f4)
111     export VERSION=$v
112 else
113     export VERSION=${TAG:1}
114 fi
115
116 echo "--------------------"
117 echo "OVS version is $VERSION"
118 echo
119 echo "--------------------"
120 echo "Make OVS distribution $TAG"
121 echo
122
123 make dist
124
125 cd $TMPDIR/ovs
126
127 cp openvswitch-$VERSION.tar.gz $TOPDIR/rpmbuild/SOURCES
128 cp openvswitch-$VERSION.tar.gz $TMPDIR
129
130 cd $TMPDIR
131 tar -xzf openvswitch-$VERSION.tar.gz
132
133 cd $TMPDIR/openvswitch-$VERSION
134
135
136 echo "--------------------"
137 echo "Build OVS RPM"
138 echo
139
140 if [ ! -z ${NOCHECK+1} ]; then
141     # Build RPM without checks
142     #
143     rpmbuild -bb --define "_topdir `echo $RPMDIR`" --without check rhel/openvswitch.spec
144 else
145     rpmbuild -bb --define "_topdir `echo $RPMDIR`" rhel/openvswitch.spec
146 fi
147
148 # Once build is done copy product to artifactory.
149
150 echo "---------------------------------------"
151 echo "Copy RPM into $TMP_RELEASE_DIR"
152 echo
153 cp $RPMDIR/RPMS/x86_64/*.rpm $TMP_RELEASE_DIR
154
155 # cleanup
156
157 echo "---------------------------------------"
158 echo "Cleanup $TMP_RELEASE_DIR"
159 echo
160 cd $BUILDDIR
161
162 if [ -d $TMPDIR ]
163 then
164     echo rm -rf $TMPDIR
165     rm -rf $TMPDIR
166 fi
167
168 # copy artifacts.
169
170 if [ ! -z ${JENKINS+1} ]; then
171     upload_artifacts.sh
172 fi
173
174 exit 0