blob: 14b7a5c8790a234ad57a69ebfdedcedeea4c2c95 [file] [log] [blame]
Joel Stanley2ed389f2015-12-11 15:07:07 +10301#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4#
5# It expects a few variables which are part of Jenkins build job matrix:
6# target = palmetto|qemu|habanero|firestone|garrison
7# distro = ubuntu
8# WORKSPACE =
9
10# Trace bash processing
11set -x
12
13# Default variables
14target=${target:-palmetto}
15distro=${distro:-ubuntu}
16WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
17http_proxy=${http_proxy:-}
18
19# Timestamp for job
20echo "Build started, $(date)"
21
22# Configure docker build
23if [[ "${distro}" == fedora ]];then
24
25 Dockerfile=$(cat << EOF
26FROM fedora:latest
27
Chris Smartfc730ff2016-03-09 20:17:19 +110028RUN dnf --refresh repolist && dnf install -y \
29 bc \
Chris Smart4593d4f2016-03-09 15:50:59 +110030 bison \
Chris Smartfc730ff2016-03-09 20:17:19 +110031 bzip2 \
32 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +110033 cscope \
Chris Smartfc730ff2016-03-09 20:17:19 +110034 ctags \
Chris Smart4593d4f2016-03-09 15:50:59 +110035 expat-devel \
Chris Smartfc730ff2016-03-09 20:17:19 +110036 findutils \
37 flex \
38 gcc-c++ \
39 git \
40 libxml2-devel \
41 ncurses-devel \
Chris Smart4593d4f2016-03-09 15:50:59 +110042 patch \
Chris Smartfc730ff2016-03-09 20:17:19 +110043 perl \
44 perl-bignum \
45 "perl(Digest::SHA1)" \
Chris Smart905777e2016-03-11 15:01:48 +110046 "perl(Env)" \
Chris Smartfc730ff2016-03-09 20:17:19 +110047 "perl(Fatal)" \
48 "perl(Thread::Queue)" \
49 "perl(XML::SAX)" \
50 "perl(XML::Simple)" \
51 "perl(YAML)" \
52 "perl(XML::LibXML)" \
53 python \
54 tar \
55 unzip \
56 vim \
57 wget \
58 which \
Chris Smart4593d4f2016-03-09 15:50:59 +110059 zlib-devel \
Chris Smartfc730ff2016-03-09 20:17:19 +110060 zlib-static
Chris Smart4593d4f2016-03-09 15:50:59 +110061
62RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
63RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +103064
65USER ${USER}
66ENV HOME ${HOME}
67RUN /bin/bash
68EOF
69)
70
71elif [[ "${distro}" == ubuntu ]]; then
72
73 Dockerfile=$(cat << EOF
74FROM ubuntu:15.10
75
76ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110077RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110078 bc \
79 bison \
80 build-essential \
81 cscope \
82 cpio \
83 ctags \
84 flex \
85 g++ \
86 git \
87 libexpat-dev \
88 libz-dev \
89 libxml-sax-perl \
90 libxml-simple-perl \
91 libxml2-dev \
92 libxml2-utils \
93 language-pack-en \
94 python \
95 texinfo \
96 unzip \
97 vim-common \
98 wget\
99 xsltproc
100
101RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
102RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +1030103
104USER ${USER}
105ENV HOME ${HOME}
106RUN /bin/bash
107EOF
108)
109fi
110
111# Build the docker container
112docker build -t op-build/${distro} - <<< "${Dockerfile}"
113if [[ "$?" -ne 0 ]]; then
114 echo "Failed to build docker container."
115 exit 1
116fi
117
118mkdir -p ${WORKSPACE}
119
120cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
121#!/bin/bash
122
123set -x
124
Joel Stanley21e65232015-12-11 15:40:54 +1030125# This ensures that the alias set in op-build-env is
126# avalaible in this script
127shopt -s expand_aliases
128
Joel Stanley2ed389f2015-12-11 15:07:07 +1030129cd ${WORKSPACE}/op-build
130
131# Source our build env
132. op-build-env
133
134# Configure
Joel Stanleyf00719d2015-12-11 15:16:32 +1030135op-build ${target}_defconfig
Joel Stanley2ed389f2015-12-11 15:07:07 +1030136
137# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +1030138op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +1030139
140EOF_SCRIPT
141
142chmod a+x ${WORKSPACE}/build.sh
143
144# Run the docker container, execute the build script we just built
145docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
146 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
147
148# Create link to images for archiving
149ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
150
151# Timestamp for build
152echo "Build completed, $(date)"