blob: 26ff8263080aca69ec344ef7cf3c6ae2e5122795 [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 # Set the locale
179 RUN locale-gen en_US.UTF-8
180 ENV LANG en_US.UTF-8
181 ENV LANGUAGE en_US:en
182 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500183
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500184 RUN apt-get update && apt-get install -yy \
185 build-essential \
186 chrpath \
187 debianutils \
188 diffstat \
189 gawk \
190 git \
191 libdata-dumper-simple-perl \
192 libsdl1.2-dev \
193 libthread-queue-any-perl \
194 python \
195 python3 \
196 socat \
197 subversion \
198 texinfo \
199 cpio \
200 wget
Chris Smart02651712015-11-11 11:09:00 +1100201
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500202 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
203 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100204
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500205 USER ${USER}
206 ENV HOME ${HOME}
207 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100208EOF
209)
210fi
211
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500212# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100213export PROXY_HOST=${http_proxy/#http*:\/\/}
214export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
215export PROXY_PORT=${http_proxy/#http*:\/\/*:}
216
Chris Smart01d2b962015-11-11 18:05:30 +1100217mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100218
Chris Smart01d2b962015-11-11 18:05:30 +1100219cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100220#!/bin/bash
221
Joel Stanley38c9d142016-02-16 12:31:55 +1030222set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100223
Alanny Lopeze6870192017-04-24 15:25:59 -0500224# Use the mounted repo cache to make an internal repo not mounted externally
225git clone --reference ${ocache} --dissociate https://github.com/openbmc/openbmc ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100226
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500227# Go into the OpenBMC directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500228cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100229
230# Set up proxies
231export ftp_proxy=${http_proxy}
232export http_proxy=${http_proxy}
233export https_proxy=${http_proxy}
234
Chris Smart01d2b962015-11-11 18:05:30 +1100235mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100236
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500237# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100238if [[ -n "${http_proxy}" ]]; then
239
Chris Smartd30c5902016-03-01 15:00:54 +1100240 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500241 #!/bin/bash
242 # \$1 = hostname, \$2 = port
243 PROXY=${PROXY_HOST}
244 PROXY_PORT=${PROXY_PORT}
245 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100246EOF_GIT
247
Chris Smart01d2b962015-11-11 18:05:30 +1100248 chmod a+x ${WORKSPACE}/bin/git-proxy
249 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100250 git config core.gitProxy git-proxy
251
252 mkdir -p ~/.subversion
253
254 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500255 [global]
256 http-proxy-host = ${PROXY_HOST}
257 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100258EOF_SVN
259fi
260
261# Source our build env
262${BITBAKE_CMD}
263
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500264# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100265cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100266BB_NUMBER_THREADS = "$(nproc)"
267PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100268INHERIT += "rm_work"
269BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez97a79502017-04-24 16:19:25 -0500270DL_DIR="${sscdir}/bitbake_downloads"
271SSTATE_DIR="${sscdir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100272USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500273INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100274EOF_CONF
275
276# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500277bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100278
Alanny Lopeze6870192017-04-24 15:25:59 -0500279# Copy images out of internal obmcdir into workspace directory
Alanny Lopezb0a12dd2017-04-24 16:21:47 -0500280cp -R ${obmcdir}/build/tmp/deploy ${WORKSPACE}/deploy/
Alanny Lopeze6870192017-04-24 15:25:59 -0500281
Chris Smart02651712015-11-11 11:09:00 +1100282EOF_SCRIPT
283
284chmod a+x ${WORKSPACE}/build.sh
285
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500286# Determine if the build container will be launched with Docker or Kubernetes
287if [[ "${launch}" == "" ]]; then
288
289 # Give the Docker image a name based on the distro,tag,arch,and target
290 imgname=${imgname:-openbmc/${distro}:${imgtag}-${target}-${ARCH}}
291
292 # Build the Docker image
293 docker build -t ${imgname} - <<< "${Dockerfile}"
294
Alanny Lopez97a79502017-04-24 16:19:25 -0500295 # If ocache or sscdir are ${HOME} or a subdirectory they will not be mounted
296 mountocache="-v ""${ocache}"":""${ocache}"" "
297 mountsscdir="-v ""${sscdir}"":""${sscdir}"" "
298 if [[ "${ocache}" = "${HOME}/"* || "${ocache}" = "${HOME}" ]];then
299 mountocache=""
300 fi
301 if [[ "${sscdir}" = "${HOME}/"* || "${sscdir}" = "${HOME}" ]];then
302 mountsscdir=""
303 fi
304
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500305 # Run the Docker container, execute the build.sh script
306 docker run \
307 --cap-add=sys_admin \
308 --net=host \
309 --rm=true \
310 -e WORKSPACE=${WORKSPACE} \
311 -w "${HOME}" \
312 -v "${HOME}":"${HOME}" \
Alanny Lopez97a79502017-04-24 16:19:25 -0500313 ${mountocache} \
314 ${mountsscdir} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500315 -t ${imgname} \
316 ${WORKSPACE}/build.sh
317
318elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
319
320 # Source and run the helper script to launch the pod or job
321 . kubernetes/kubernetes-launch.sh
322
323else
324 echo "Launch Parameter is invalid"
325fi
Chris Smart02651712015-11-11 11:09:00 +1100326
327# Timestamp for build
Alanny Lopezb0a12dd2017-04-24 16:21:47 -0500328echo "Build completed, $(date)"