summaryrefslogtreecommitdiffstats
path: root/ci/buildovs.sh
blob: 77cb96d02eb8338b5e32495546056affb56424df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
##############################################################################
# Copyright (c) 2015 Red Hat Inc. and others.
# therbert@redhat.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

# Check to verify that I am being run by Jenkins CI.

if [ -z ${WORKSPACE+1} ]; then
    # We are not being run by Jenkins.
    export WORKSPACE=$HOME/opnfv/ovsnfv
fi


if [ -z ${OVSTAG+1} ]; then
    export TAG=master
else
    export TAG=$OVSTAG
fi

export DATE=`date +%Y-%m-%d`

export BUILD_BASE=$WORKSPACE/build



if [ ! -d $BUILD_BASE ]
then
    mkdir -p $BUILD_BASE
fi

if [ ! -f $BUILD_BASE/config ]; then
    touch $BUILD_BASE/config
fi

export PATH=$PATH:$WORKSPACE/ci:$BUILD_BASE

source $BUILD_BASE/config

cd $BUILD_BASE
export TOPDIR=$BUILD_BASE

# build variables

export TMP_RELEASE_DIR=$TOPDIR/release
export CACHE_DIR=$TOPDIR/cache
export TMPDIR=$TOPDIR/scratch
export RPMDIR=$TOPDIR/rpmbuild

echo "--------------------------------------------------"
echo "Build OVS RPM from upstream git $TAG"
echo

mkdir -p $RPMDIR/RPMS
mkdir -p $RPMDIR/SOURCES
mkdir -p $RPMDIR/SPECS
mkdir -p $RPMDIR/SRPMS

if [ ! -d $TMP_RELEASE_DIR ]
then
    mkdir -p $TMP_RELEASE_DIR
fi

# Centos build server should support the following build prerequisites

# yum install gcc make python-devel openssl-devel kernel-devel graphviz \
# kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
# libtool

if [ -d $TMPDIR ]
then
    rm -rf $TMPDIR
fi

mkdir $TMPDIR

cd $TMPDIR

echo "---------------------"
echo "Clone git repo $TAG"
echo
git clone https://github.com/openvswitch/ovs.git

cd ovs
echo "--------------------"
echo "Checkout OVS $TAG"
echo
if [[ ! "$TAG" =~ "master" ]]; then
    git checkout $TAG
fi
./boot.sh
./configure
echo "--------------------"
echo "Make OVS $TAG"
echo
make
#
# Get version for master
#
echo "--------------------"
echo "Get OVS version for $TAG"
echo
if [[ "$TAG" =~ "master" ]]; then
    v=$($TMPDIR/ovs/utilities/ovs-vsctl --version | head -1 | cut -d' ' -f4)
    export VERSION=$v
else
    export VERSION=${TAG:1}
fi

echo "--------------------"
echo "OVS version is $VERSION"
echo
echo "--------------------"
echo "Make OVS distribution $TAG"
echo

make dist

cd $TMPDIR/ovs

cp openvswitch-$VERSION.tar.gz $TOPDIR/rpmbuild/SOURCES
cp openvswitch-$VERSION.tar.gz $TMPDIR

cd $TMPDIR
tar -xzf openvswitch-$VERSION.tar.gz

cd $TMPDIR/openvswitch-$VERSION


echo "--------------------"
echo "Build OVS RPM"
echo

if [ ! -z ${NOCHECK+1} ]; then
    # Build RPM without checks
    #
    rpmbuild -bb --define "_topdir `echo $RPMDIR`" --without check rhel/openvswitch.spec
else
    rpmbuild -bb --define "_topdir `echo $RPMDIR`" rhel/openvswitch.spec
fi

# Once build is done copy product to artifactory.

echo "---------------------------------------"
echo "Copy RPM into $TMP_RELEASE_DIR"
echo
cp $RPMDIR/RPMS/x86_64/*.rpm $TMP_RELEASE_DIR

# cleanup

echo "---------------------------------------"
echo "Cleanup $TMP_RELEASE_DIR"
echo
cd $BUILDDIR

if [ -d $TMPDIR ]
then
    echo rm -rf $TMPDIR
    rm -rf $TMPDIR
fi

# copy artifacts.

if [[ "$JOB_NAME" =~ "daily" ]]; then
    upload_artifacts.sh
fi

exit 0