blob: 4e9eb2ed232312d4a7eea16f1ed48d834ea438eb [file] [log] [blame]
Alanny Lopez56fc36a2017-07-27 13:55:44 -05001#!/bin/bash
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05002###############################################################################
Chris Smart02651712015-11-11 11:09:00 +11003#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05004# This build script is for running the OpenBMC builds as containers with the
5# option of launching the containers with Docker or Kubernetes.
Alanny Lopez3fbaa512017-04-24 15:46:52 -05006#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05007###############################################################################
8#
9# Variables used for Jenkins build job matrix:
10# target = barreleye|palmetto|witherspoon|firestone|garrison|evb-ast2500
11# zaius|romulus|qemu
12# distro = fedora|ubuntu
13# imgtag = Varies by distro. latest|16.04|14.04|trusty|xenial; 23|24|25
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050014# obmcext = Path of the OpenBMC repo directory used in creating a copy
15# inside the container that is not mounted to external storage
16# default directory location "${WORKSPACE}/openbmc"
Alanny Lopez723fea62017-09-12 11:22:17 -050017# builddir = Path of the OpenBMC directory where the build occurs inside
18# the container, cannot be placed on external storage default
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050019# directory location "/tmp/openbmc"
20# sscdir = Path of the BitBake shared-state cache directoy, will default
21# to directory "/home/${USER}", used to speed up builds.
22# WORKSPACE = Path of the workspace directory where some intermediate files
23# and the images will be saved to.
24#
Alanny Lopez723fea62017-09-12 11:22:17 -050025# extraction = Path where the ombcdir contents will be copied out to when
26# the build completes. Defaults to ${obmcext}/build/tmp.
27#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050028# Optional Variables:
29# launch = job|pod
30# Can be left blank to launch via Docker if not using
31# Kubernetes to launch the container.
32# Job lets you keep a copy of job and container logs on the
33# api, can be useful if not using Jenkins as you can run the
34# job again via the api without needing this script.
35# Pod launches a container which runs to completion without
36# saving anything to the api when it completes.
37# imgname = Defaults to a relatively long but descriptive name, can be
38# changed or passed to give a specific name to created image.
39# http_proxy = The HTTP address for the proxy server you wish to connect to.
40# BITBAKE_OPTS = Set to "-c populate_sdk" or whatever other bitbake options
41# you'd like to pass into the build.
42#
43###############################################################################
Chris Smart02651712015-11-11 11:09:00 +110044
Joel Stanley4b8b2392016-02-12 15:44:57 +103045# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103046set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110047
48# Default variables
49target=${target:-qemu}
50distro=${distro:-ubuntu}
Alanny Lopezccc650e2017-04-24 15:14:20 -050051imgtag=${imgtag:-latest}
Alanny Lopez723fea62017-09-12 11:22:17 -050052builddir=${builddir:-/tmp/openbmc}
Alanny Lopez97a79502017-04-24 16:19:25 -050053sscdir=${sscdir:-${HOME}}
Chris Smart02651712015-11-11 11:09:00 +110054WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050055obmcext=${obmcext:-${WORKSPACE}/openbmc}
Alanny Lopez723fea62017-09-12 11:22:17 -050056extraction=${extraction:-${obmcext}/build/tmp}
Alanny Lopez3fbaa512017-04-24 15:46:52 -050057launch=${launch:-}
Chris Smart02651712015-11-11 11:09:00 +110058http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110059PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110060
Alanny Lopezccc650e2017-04-24 15:14:20 -050061# Determine the architecture
62ARCH=$(uname -m)
63
64# Determine the prefix of the Dockerfile's base image
65case ${ARCH} in
66 "ppc64le")
67 DOCKER_BASE="ppc64le/"
68 ;;
69 "x86_64")
70 DOCKER_BASE=""
71 ;;
72 *)
73 echo "Unsupported system architecture(${ARCH}) found for docker image"
74 exit 1
75esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050076
Chris Smart02651712015-11-11 11:09:00 +110077# Timestamp for job
78echo "Build started, $(date)"
79
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050080# If the obmcext directory doesn't exist clone it in
81if [ ! -d ${obmcext} ]; then
82 echo "Clone in openbmc master to ${obmcext}"
83 git clone https://github.com/openbmc/openbmc ${obmcext}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050084fi
85
Alanny Lopez723fea62017-09-12 11:22:17 -050086# Make and chown the extraction directory to avoid permission errors
87if [ ! -d ${extraction} ]; then
88 mkdir -p ${extraction}
89fi
90chown ${UID}:${GROUPS} ${extraction}
91
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050092# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +110093case ${target} in
94 barreleye)
95 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
96 ;;
97 palmetto)
98 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
99 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930100 witherspoon)
101 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
102 ;;
103 firestone)
104 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
105 ;;
106 garrison)
107 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
108 ;;
109 evb-ast2500)
110 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
111 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030112 zaius)
113 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env"
114 ;;
115 romulus)
116 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env"
117 ;;
Chris Smart02651712015-11-11 11:09:00 +1100118 qemu)
119 BITBAKE_CMD="source openbmc-env"
120 ;;
121 *)
122 exit 1
123 ;;
124esac
125
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500126# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100127if [[ "${distro}" == fedora ]];then
128
129 if [[ -n "${http_proxy}" ]]; then
130 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
131 fi
132
133 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500134 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100135
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500136 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100137
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500138 # Set the locale
139 RUN locale-gen en_US.UTF-8
140 ENV LANG en_US.UTF-8
141 ENV LANGUAGE en_US:en
142 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500143
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500144 RUN dnf --refresh install -y \
145 bzip2 \
146 chrpath \
147 cpio \
148 diffstat \
149 findutils \
150 gcc \
151 gcc-c++ \
152 git \
153 make \
154 patch \
155 perl-bignum \
156 perl-Data-Dumper \
157 perl-Thread-Queue \
158 python-devel \
159 python3-devel \
160 SDL-devel \
161 socat \
162 subversion \
163 tar \
164 texinfo \
165 wget \
166 which
Chris Smart02651712015-11-11 11:09:00 +1100167
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500168 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
169 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100170
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500171 USER ${USER}
172 ENV HOME ${HOME}
173 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100174EOF
175)
176
Alanny Lopezccc650e2017-04-24 15:14:20 -0500177elif [[ "${distro}" == ubuntu ]]; then
178
Chris Smart02651712015-11-11 11:09:00 +1100179 if [[ -n "${http_proxy}" ]]; then
180 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
181 fi
182
183 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500184 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100185
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500186 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100187
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500188 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500189
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500190 RUN apt-get update && apt-get install -yy \
191 build-essential \
192 chrpath \
193 debianutils \
194 diffstat \
195 gawk \
196 git \
197 libdata-dumper-simple-perl \
198 libsdl1.2-dev \
199 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500200 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500201 python \
202 python3 \
203 socat \
204 subversion \
205 texinfo \
206 cpio \
207 wget
Chris Smart02651712015-11-11 11:09:00 +1100208
Alanny Lopez27af3a02017-05-26 10:49:06 -0500209 # Set the locale
210 RUN locale-gen en_US.UTF-8
211 ENV LANG en_US.UTF-8
212 ENV LANGUAGE en_US:en
213 ENV LC_ALL en_US.UTF-8
214
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500215 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
216 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100217
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500218 USER ${USER}
219 ENV HOME ${HOME}
220 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100221EOF
222)
223fi
224
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500225# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100226export PROXY_HOST=${http_proxy/#http*:\/\/}
227export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
228export PROXY_PORT=${http_proxy/#http*:\/\/*:}
229
Chris Smart01d2b962015-11-11 18:05:30 +1100230mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100231
Chris Smart01d2b962015-11-11 18:05:30 +1100232cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100233#!/bin/bash
234
Joel Stanley38c9d142016-02-16 12:31:55 +1030235set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100236
Alanny Lopez723fea62017-09-12 11:22:17 -0500237# Go into the OpenBMC directory, the build will handle changing directories
238cd ${obmcext}
Chris Smart02651712015-11-11 11:09:00 +1100239
240# Set up proxies
241export ftp_proxy=${http_proxy}
242export http_proxy=${http_proxy}
243export https_proxy=${http_proxy}
244
Chris Smart01d2b962015-11-11 18:05:30 +1100245mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100246
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500247# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100248if [[ -n "${http_proxy}" ]]; then
249
Chris Smartd30c5902016-03-01 15:00:54 +1100250 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500251 #!/bin/bash
252 # \$1 = hostname, \$2 = port
253 PROXY=${PROXY_HOST}
254 PROXY_PORT=${PROXY_PORT}
255 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100256EOF_GIT
257
Chris Smart01d2b962015-11-11 18:05:30 +1100258 chmod a+x ${WORKSPACE}/bin/git-proxy
259 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100260 git config core.gitProxy git-proxy
261
262 mkdir -p ~/.subversion
263
264 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500265 [global]
266 http-proxy-host = ${PROXY_HOST}
267 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100268EOF_SVN
269fi
270
271# Source our build env
272${BITBAKE_CMD}
273
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500274# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100275cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100276BB_NUMBER_THREADS = "$(nproc)"
277PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100278INHERIT += "rm_work"
279BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez97a79502017-04-24 16:19:25 -0500280DL_DIR="${sscdir}/bitbake_downloads"
281SSTATE_DIR="${sscdir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100282USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500283INHERIT_remove = "uninative"
Alanny Lopez723fea62017-09-12 11:22:17 -0500284TMPDIR="${builddir}"
Chris Smart02651712015-11-11 11:09:00 +1100285EOF_CONF
286
287# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500288bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100289
Alanny Lopezd32d3322017-07-18 15:21:39 -0500290# Copy build directory of internal obmcdir into workspace directory
Alanny Lopez723fea62017-09-12 11:22:17 -0500291cp -r ${builddir}/* ${extraction}
Chris Smart02651712015-11-11 11:09:00 +1100292EOF_SCRIPT
293
294chmod a+x ${WORKSPACE}/build.sh
295
Alanny Lopez51186882017-08-01 16:14:41 -0500296# Give the Docker image a name based on the distro,tag,arch,and target
297imgname=${imgname:-openbmc/${distro}:${imgtag}-${target}-${ARCH}}
298
299# Build the Docker image
300docker build -t ${imgname} - <<< "${Dockerfile}"
301
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500302# Determine if the build container will be launched with Docker or Kubernetes
303if [[ "${launch}" == "" ]]; then
304
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500305 # If obmcext or sscdir are ${HOME} or a subdirectory they will not be mounted
306 mountobmcext="-v ""${obmcext}"":""${obmcext}"" "
Alanny Lopez97a79502017-04-24 16:19:25 -0500307 mountsscdir="-v ""${sscdir}"":""${sscdir}"" "
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500308 if [[ "${obmcext}" = "${HOME}/"* || "${obmcext}" = "${HOME}" ]];then
309 mountobmcext=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500310 fi
311 if [[ "${sscdir}" = "${HOME}/"* || "${sscdir}" = "${HOME}" ]];then
312 mountsscdir=""
313 fi
314
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500315 # Run the Docker container, execute the build.sh script
316 docker run \
317 --cap-add=sys_admin \
318 --net=host \
319 --rm=true \
320 -e WORKSPACE=${WORKSPACE} \
321 -w "${HOME}" \
322 -v "${HOME}":"${HOME}" \
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500323 ${mountobmcext} \
Alanny Lopez97a79502017-04-24 16:19:25 -0500324 ${mountsscdir} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500325 -t ${imgname} \
326 ${WORKSPACE}/build.sh
327
328elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
329
330 # Source and run the helper script to launch the pod or job
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500331 . ./kubernetes/kubernetes-launch.sh OpenBMC-build true true
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500332
333else
334 echo "Launch Parameter is invalid"
335fi
Chris Smart02651712015-11-11 11:09:00 +1100336
Alanny Lopezd32d3322017-07-18 15:21:39 -0500337# To maintain function of resources that used an older path, add a link
Alanny Lopez723fea62017-09-12 11:22:17 -0500338ln -sf ${extraction}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500339
Chris Smart02651712015-11-11 11:09:00 +1100340# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500341echo "Build completed, $(date)"