blob: 3aa30c69feea79ad03c9f003e4091ec265916054 [file] [log] [blame]
Chris Smart02651712015-11-11 11:09:00 +11001#!/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 = barreleye|palmetto|qemu
7# distro = fedora|ubuntu
8# WORKSPACE =
9
Joel Stanley4b8b2392016-02-12 15:44:57 +103010# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103011set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110012
13# Default variables
14target=${target:-qemu}
15distro=${distro:-ubuntu}
16WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
17http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110018PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110019
20# Timestamp for job
21echo "Build started, $(date)"
22
23# Work out what build target we should be running and set bitbake command
24case ${target} in
25 barreleye)
26 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
27 ;;
28 palmetto)
29 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
30 ;;
Joel Stanley0e077202016-06-28 16:42:45 +093031 witherspoon)
32 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
33 ;;
34 firestone)
35 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
36 ;;
37 garrison)
38 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
39 ;;
40 evb-ast2500)
41 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
42 ;;
Chris Smart02651712015-11-11 11:09:00 +110043 qemu)
44 BITBAKE_CMD="source openbmc-env"
45 ;;
46 *)
47 exit 1
48 ;;
49esac
50
51# Configure docker build
52if [[ "${distro}" == fedora ]];then
53
54 if [[ -n "${http_proxy}" ]]; then
55 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
56 fi
57
58 Dockerfile=$(cat << EOF
59FROM fedora:latest
60
61${PROXY}
62
Chris Smartfc730ff2016-03-09 20:17:19 +110063RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110064 bzip2 \
65 chrpath \
66 cpio \
67 diffstat \
68 findutils \
69 gcc \
70 gcc-c++ \
71 git \
72 make \
73 patch \
74 perl-bignum \
75 perl-Data-Dumper \
76 perl-Thread-Queue \
77 python-devel \
78 SDL-devel \
79 socat \
80 subversion \
81 tar \
82 texinfo \
83 wget \
84 which
Chris Smart02651712015-11-11 11:09:00 +110085
Chris Smartd30c5902016-03-01 15:00:54 +110086RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
87RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +110088
89USER ${USER}
90ENV HOME ${HOME}
91RUN /bin/bash
92EOF
93)
94
95elif [[ "${distro}" == ubuntu ]]; then
96 if [[ -n "${http_proxy}" ]]; then
97 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
98 fi
99
100 Dockerfile=$(cat << EOF
101FROM ubuntu:latest
102
103${PROXY}
104
Chris Smart4593d4f2016-03-09 15:50:59 +1100105ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100106RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100107 build-essential \
108 chrpath \
109 debianutils \
110 diffstat \
111 gawk \
112 git \
113 libdata-dumper-simple-perl \
114 libsdl1.2-dev \
115 libthread-queue-any-perl \
116 python \
117 socat \
118 subversion \
119 texinfo \
120 wget
Chris Smart02651712015-11-11 11:09:00 +1100121
Chris Smartd30c5902016-03-01 15:00:54 +1100122RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
123RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
124
Chris Smart02651712015-11-11 11:09:00 +1100125USER ${USER}
126ENV HOME ${HOME}
127RUN /bin/bash
128EOF
129)
130fi
131
132# Build the docker container
133docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100134
135# Create the docker run script
136export PROXY_HOST=${http_proxy/#http*:\/\/}
137export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
138export PROXY_PORT=${http_proxy/#http*:\/\/*:}
139
Chris Smart01d2b962015-11-11 18:05:30 +1100140mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100141
Chris Smart01d2b962015-11-11 18:05:30 +1100142cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100143#!/bin/bash
144
Joel Stanley38c9d142016-02-16 12:31:55 +1030145set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100146
Chris Smart01d2b962015-11-11 18:05:30 +1100147cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100148
149# Go into the openbmc directory (the openbmc script will put us in a build subdir)
150cd openbmc
151
152# Set up proxies
153export ftp_proxy=${http_proxy}
154export http_proxy=${http_proxy}
155export https_proxy=${http_proxy}
156
Chris Smart01d2b962015-11-11 18:05:30 +1100157mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100158
159# Configure proxies for bitbake
160if [[ -n "${http_proxy}" ]]; then
161
Chris Smartd30c5902016-03-01 15:00:54 +1100162 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100163#!/bin/bash
164# \$1 = hostname, \$2 = port
165PROXY=${PROXY_HOST}
166PROXY_PORT=${PROXY_PORT}
167exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
168EOF_GIT
169
Chris Smart01d2b962015-11-11 18:05:30 +1100170 chmod a+x ${WORKSPACE}/bin/git-proxy
171 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100172 git config core.gitProxy git-proxy
173
174 mkdir -p ~/.subversion
175
176 cat > ~/.subversion/servers << EOF_SVN
177[global]
178http-proxy-host = ${PROXY_HOST}
179http-proxy-port = ${PROXY_PORT}
180EOF_SVN
181fi
182
183# Source our build env
184${BITBAKE_CMD}
185
186# Custom bitbake config settings
187cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100188BB_NUMBER_THREADS = "$(nproc)"
189PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100190INHERIT += "rm_work"
191BB_GENERATE_MIRROR_TARBALLS = "1"
192DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500193SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100194USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500195INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100196EOF_CONF
197
198# Kick off a build
199bitbake obmc-phosphor-image
200
201EOF_SCRIPT
202
203chmod a+x ${WORKSPACE}/build.sh
204
205# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100206docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
207 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100208
209# Create link to images for archiving
210ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
211
212# Timestamp for build
213echo "Build completed, $(date)"
214