blob: 41b158e18ec7ea0390c9bb56d7d0c5494093a503 [file] [log] [blame]
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05001###############################################################################
Chris Smart02651712015-11-11 11:09:00 +11002#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05003# This build script is for running the OpenBMC builds as containers with the
4# option of launching the containers with Docker or Kubernetes.
Alanny Lopez3fbaa512017-04-24 15:46:52 -05005#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05006###############################################################################
7#
8# Variables used for Jenkins build job matrix:
9# target = barreleye|palmetto|witherspoon|firestone|garrison|evb-ast2500
10# zaius|romulus|qemu
11# distro = fedora|ubuntu
12# imgtag = Varies by distro. latest|16.04|14.04|trusty|xenial; 23|24|25
13# ocache = Path of the OpenBMC repo cache that is used to speed up git
14# clones, default directory location "${WORKSPACE}/openbmc"
15# obmcdir = Path of the OpenBMC directory, where the build occurs inside
16# the container cannot be placed on external storage default
17# directory location "/tmp/openbmc"
18# sscdir = Path of the BitBake shared-state cache directoy, will default
19# to directory "/home/${USER}", used to speed up builds.
20# WORKSPACE = Path of the workspace directory where some intermediate files
21# and the images will be saved to.
22#
23# Optional Variables:
24# launch = job|pod
25# Can be left blank to launch via Docker if not using
26# Kubernetes to launch the container.
27# Job lets you keep a copy of job and container logs on the
28# api, can be useful if not using Jenkins as you can run the
29# job again via the api without needing this script.
30# Pod launches a container which runs to completion without
31# saving anything to the api when it completes.
32# imgname = Defaults to a relatively long but descriptive name, can be
33# changed or passed to give a specific name to created image.
34# http_proxy = The HTTP address for the proxy server you wish to connect to.
35# BITBAKE_OPTS = Set to "-c populate_sdk" or whatever other bitbake options
36# you'd like to pass into the build.
37#
38###############################################################################
Chris Smart02651712015-11-11 11:09:00 +110039
Joel Stanley4b8b2392016-02-12 15:44:57 +103040# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103041set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110042
43# Default variables
44target=${target:-qemu}
45distro=${distro:-ubuntu}
Alanny Lopezccc650e2017-04-24 15:14:20 -050046imgtag=${imgtag:-latest}
Alanny Lopeze6870192017-04-24 15:25:59 -050047obmcdir=${obmcdir:-/tmp/openbmc}
Alanny Lopez97a79502017-04-24 16:19:25 -050048sscdir=${sscdir:-${HOME}}
Chris Smart02651712015-11-11 11:09:00 +110049WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050050ocache=${ocache:-${WORKSPACE}/openbmc}
Alanny Lopez3fbaa512017-04-24 15:46:52 -050051launch=${launch:-}
Chris Smart02651712015-11-11 11:09:00 +110052http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110053PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110054
Alanny Lopezccc650e2017-04-24 15:14:20 -050055# Determine the architecture
56ARCH=$(uname -m)
57
58# Determine the prefix of the Dockerfile's base image
59case ${ARCH} in
60 "ppc64le")
61 DOCKER_BASE="ppc64le/"
62 ;;
63 "x86_64")
64 DOCKER_BASE=""
65 ;;
66 *)
67 echo "Unsupported system architecture(${ARCH}) found for docker image"
68 exit 1
69esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050070
Chris Smart02651712015-11-11 11:09:00 +110071# Timestamp for job
72echo "Build started, $(date)"
73
Alanny Lopeze6870192017-04-24 15:25:59 -050074# If the ocache directory doesn't exist clone it in, ocache will be used as a cache for git clones
75if [ ! -d ${ocache} ]; then
76 echo "Clone in openbmc master to ${ocache} to act as cache for future builds"
77 git clone https://github.com/openbmc/openbmc ${ocache}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050078fi
79
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050080# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +110081case ${target} in
82 barreleye)
83 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
84 ;;
85 palmetto)
86 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
87 ;;
Joel Stanley0e077202016-06-28 16:42:45 +093088 witherspoon)
89 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
90 ;;
91 firestone)
92 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
93 ;;
94 garrison)
95 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
96 ;;
97 evb-ast2500)
98 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
99 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030100 zaius)
101 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env"
102 ;;
103 romulus)
104 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env"
105 ;;
Chris Smart02651712015-11-11 11:09:00 +1100106 qemu)
107 BITBAKE_CMD="source openbmc-env"
108 ;;
109 *)
110 exit 1
111 ;;
112esac
113
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500114# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100115if [[ "${distro}" == fedora ]];then
116
117 if [[ -n "${http_proxy}" ]]; then
118 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
119 fi
120
121 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500122 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100123
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500124 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100125
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500126 # Set the locale
127 RUN locale-gen en_US.UTF-8
128 ENV LANG en_US.UTF-8
129 ENV LANGUAGE en_US:en
130 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500131
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500132 RUN dnf --refresh install -y \
133 bzip2 \
134 chrpath \
135 cpio \
136 diffstat \
137 findutils \
138 gcc \
139 gcc-c++ \
140 git \
141 make \
142 patch \
143 perl-bignum \
144 perl-Data-Dumper \
145 perl-Thread-Queue \
146 python-devel \
147 python3-devel \
148 SDL-devel \
149 socat \
150 subversion \
151 tar \
152 texinfo \
153 wget \
154 which
Chris Smart02651712015-11-11 11:09:00 +1100155
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500156 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
157 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100158
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500159 USER ${USER}
160 ENV HOME ${HOME}
161 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100162EOF
163)
164
Alanny Lopezccc650e2017-04-24 15:14:20 -0500165elif [[ "${distro}" == ubuntu ]]; then
166
Chris Smart02651712015-11-11 11:09:00 +1100167 if [[ -n "${http_proxy}" ]]; then
168 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
169 fi
170
171 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500172 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100173
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500174 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100175
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500176 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500177
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500178 RUN apt-get update && apt-get install -yy \
179 build-essential \
180 chrpath \
181 debianutils \
182 diffstat \
183 gawk \
184 git \
185 libdata-dumper-simple-perl \
186 libsdl1.2-dev \
187 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500188 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500189 python \
190 python3 \
191 socat \
192 subversion \
193 texinfo \
194 cpio \
195 wget
Chris Smart02651712015-11-11 11:09:00 +1100196
Alanny Lopez27af3a02017-05-26 10:49:06 -0500197 # Set the locale
198 RUN locale-gen en_US.UTF-8
199 ENV LANG en_US.UTF-8
200 ENV LANGUAGE en_US:en
201 ENV LC_ALL en_US.UTF-8
202
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500203 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
204 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100205
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500206 USER ${USER}
207 ENV HOME ${HOME}
208 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100209EOF
210)
211fi
212
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500213# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100214export PROXY_HOST=${http_proxy/#http*:\/\/}
215export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
216export PROXY_PORT=${http_proxy/#http*:\/\/*:}
217
Chris Smart01d2b962015-11-11 18:05:30 +1100218mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100219
Chris Smart01d2b962015-11-11 18:05:30 +1100220cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100221#!/bin/bash
222
Joel Stanley38c9d142016-02-16 12:31:55 +1030223set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100224
Alanny Lopeze6870192017-04-24 15:25:59 -0500225# Use the mounted repo cache to make an internal repo not mounted externally
226git clone --reference ${ocache} --dissociate https://github.com/openbmc/openbmc ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100227
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500228# Go into the OpenBMC directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500229cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100230
231# Set up proxies
232export ftp_proxy=${http_proxy}
233export http_proxy=${http_proxy}
234export https_proxy=${http_proxy}
235
Chris Smart01d2b962015-11-11 18:05:30 +1100236mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100237
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500238# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100239if [[ -n "${http_proxy}" ]]; then
240
Chris Smartd30c5902016-03-01 15:00:54 +1100241 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500242 #!/bin/bash
243 # \$1 = hostname, \$2 = port
244 PROXY=${PROXY_HOST}
245 PROXY_PORT=${PROXY_PORT}
246 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100247EOF_GIT
248
Chris Smart01d2b962015-11-11 18:05:30 +1100249 chmod a+x ${WORKSPACE}/bin/git-proxy
250 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100251 git config core.gitProxy git-proxy
252
253 mkdir -p ~/.subversion
254
255 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500256 [global]
257 http-proxy-host = ${PROXY_HOST}
258 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100259EOF_SVN
260fi
261
262# Source our build env
263${BITBAKE_CMD}
264
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500265# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100266cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100267BB_NUMBER_THREADS = "$(nproc)"
268PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100269INHERIT += "rm_work"
270BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez97a79502017-04-24 16:19:25 -0500271DL_DIR="${sscdir}/bitbake_downloads"
272SSTATE_DIR="${sscdir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100273USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500274INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100275EOF_CONF
276
277# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500278bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100279
Alanny Lopeze6870192017-04-24 15:25:59 -0500280# Copy images out of internal obmcdir into workspace directory
Alanny Lopezb0a12dd2017-04-24 16:21:47 -0500281cp -R ${obmcdir}/build/tmp/deploy ${WORKSPACE}/deploy/
Alanny Lopeze6870192017-04-24 15:25:59 -0500282
Chris Smart02651712015-11-11 11:09:00 +1100283EOF_SCRIPT
284
285chmod a+x ${WORKSPACE}/build.sh
286
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500287# Determine if the build container will be launched with Docker or Kubernetes
288if [[ "${launch}" == "" ]]; then
289
290 # Give the Docker image a name based on the distro,tag,arch,and target
291 imgname=${imgname:-openbmc/${distro}:${imgtag}-${target}-${ARCH}}
292
293 # Build the Docker image
294 docker build -t ${imgname} - <<< "${Dockerfile}"
295
Alanny Lopez97a79502017-04-24 16:19:25 -0500296 # If ocache or sscdir are ${HOME} or a subdirectory they will not be mounted
297 mountocache="-v ""${ocache}"":""${ocache}"" "
298 mountsscdir="-v ""${sscdir}"":""${sscdir}"" "
299 if [[ "${ocache}" = "${HOME}/"* || "${ocache}" = "${HOME}" ]];then
300 mountocache=""
301 fi
302 if [[ "${sscdir}" = "${HOME}/"* || "${sscdir}" = "${HOME}" ]];then
303 mountsscdir=""
304 fi
305
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500306 # Run the Docker container, execute the build.sh script
307 docker run \
308 --cap-add=sys_admin \
309 --net=host \
310 --rm=true \
311 -e WORKSPACE=${WORKSPACE} \
312 -w "${HOME}" \
313 -v "${HOME}":"${HOME}" \
Alanny Lopez97a79502017-04-24 16:19:25 -0500314 ${mountocache} \
315 ${mountsscdir} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500316 -t ${imgname} \
317 ${WORKSPACE}/build.sh
318
319elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
320
321 # Source and run the helper script to launch the pod or job
322 . kubernetes/kubernetes-launch.sh
323
324else
325 echo "Launch Parameter is invalid"
326fi
Chris Smart02651712015-11-11 11:09:00 +1100327
328# Timestamp for build
Alanny Lopez27af3a02017-05-26 10:49:06 -0500329echo "Build completed, $(date)"