blob: 09d87df3e62be633ee4aa6590065faf4e3bf57f8 [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 \
Saqib Khan5158a322017-10-23 11:31:24 -0500166 which \
167 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100168
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500169 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
170 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100171
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500172 USER ${USER}
173 ENV HOME ${HOME}
174 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100175EOF
176)
177
Alanny Lopezccc650e2017-04-24 15:14:20 -0500178elif [[ "${distro}" == ubuntu ]]; then
179
Chris Smart02651712015-11-11 11:09:00 +1100180 if [[ -n "${http_proxy}" ]]; then
181 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
182 fi
183
184 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500185 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100186
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500187 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100188
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500189 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500190
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500191 RUN apt-get update && apt-get install -yy \
192 build-essential \
193 chrpath \
194 debianutils \
195 diffstat \
196 gawk \
197 git \
198 libdata-dumper-simple-perl \
199 libsdl1.2-dev \
200 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500201 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500202 python \
203 python3 \
204 socat \
205 subversion \
206 texinfo \
207 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500208 wget \
209 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100210
Alanny Lopez27af3a02017-05-26 10:49:06 -0500211 # Set the locale
212 RUN locale-gen en_US.UTF-8
213 ENV LANG en_US.UTF-8
214 ENV LANGUAGE en_US:en
215 ENV LC_ALL en_US.UTF-8
216
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500217 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
218 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100219
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500220 USER ${USER}
221 ENV HOME ${HOME}
222 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100223EOF
224)
225fi
226
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500227# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100228export PROXY_HOST=${http_proxy/#http*:\/\/}
229export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
230export PROXY_PORT=${http_proxy/#http*:\/\/*:}
231
Chris Smart01d2b962015-11-11 18:05:30 +1100232mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100233
Chris Smart01d2b962015-11-11 18:05:30 +1100234cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100235#!/bin/bash
236
Joel Stanley38c9d142016-02-16 12:31:55 +1030237set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100238
Alanny Lopez723fea62017-09-12 11:22:17 -0500239# Go into the OpenBMC directory, the build will handle changing directories
240cd ${obmcext}
Chris Smart02651712015-11-11 11:09:00 +1100241
242# Set up proxies
243export ftp_proxy=${http_proxy}
244export http_proxy=${http_proxy}
245export https_proxy=${http_proxy}
246
Chris Smart01d2b962015-11-11 18:05:30 +1100247mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100248
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500249# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100250if [[ -n "${http_proxy}" ]]; then
251
Chris Smartd30c5902016-03-01 15:00:54 +1100252 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500253 #!/bin/bash
254 # \$1 = hostname, \$2 = port
255 PROXY=${PROXY_HOST}
256 PROXY_PORT=${PROXY_PORT}
257 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100258EOF_GIT
259
Chris Smart01d2b962015-11-11 18:05:30 +1100260 chmod a+x ${WORKSPACE}/bin/git-proxy
261 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100262 git config core.gitProxy git-proxy
263
264 mkdir -p ~/.subversion
265
266 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500267 [global]
268 http-proxy-host = ${PROXY_HOST}
269 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100270EOF_SVN
271fi
272
273# Source our build env
274${BITBAKE_CMD}
275
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500276# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100277cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100278BB_NUMBER_THREADS = "$(nproc)"
279PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100280INHERIT += "rm_work"
281BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez97a79502017-04-24 16:19:25 -0500282DL_DIR="${sscdir}/bitbake_downloads"
283SSTATE_DIR="${sscdir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100284USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500285INHERIT_remove = "uninative"
Alanny Lopez723fea62017-09-12 11:22:17 -0500286TMPDIR="${builddir}"
Chris Smart02651712015-11-11 11:09:00 +1100287EOF_CONF
288
289# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500290bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100291
Alanny Lopezd32d3322017-07-18 15:21:39 -0500292# Copy build directory of internal obmcdir into workspace directory
Alanny Lopez723fea62017-09-12 11:22:17 -0500293cp -r ${builddir}/* ${extraction}
Chris Smart02651712015-11-11 11:09:00 +1100294EOF_SCRIPT
295
296chmod a+x ${WORKSPACE}/build.sh
297
Alanny Lopez51186882017-08-01 16:14:41 -0500298# Give the Docker image a name based on the distro,tag,arch,and target
299imgname=${imgname:-openbmc/${distro}:${imgtag}-${target}-${ARCH}}
300
301# Build the Docker image
302docker build -t ${imgname} - <<< "${Dockerfile}"
303
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500304# Determine if the build container will be launched with Docker or Kubernetes
305if [[ "${launch}" == "" ]]; then
306
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500307 # If obmcext or sscdir are ${HOME} or a subdirectory they will not be mounted
308 mountobmcext="-v ""${obmcext}"":""${obmcext}"" "
Alanny Lopez97a79502017-04-24 16:19:25 -0500309 mountsscdir="-v ""${sscdir}"":""${sscdir}"" "
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500310 if [[ "${obmcext}" = "${HOME}/"* || "${obmcext}" = "${HOME}" ]];then
311 mountobmcext=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500312 fi
313 if [[ "${sscdir}" = "${HOME}/"* || "${sscdir}" = "${HOME}" ]];then
314 mountsscdir=""
315 fi
316
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500317 # Run the Docker container, execute the build.sh script
318 docker run \
319 --cap-add=sys_admin \
320 --net=host \
321 --rm=true \
322 -e WORKSPACE=${WORKSPACE} \
323 -w "${HOME}" \
324 -v "${HOME}":"${HOME}" \
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500325 ${mountobmcext} \
Alanny Lopez97a79502017-04-24 16:19:25 -0500326 ${mountsscdir} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500327 -t ${imgname} \
328 ${WORKSPACE}/build.sh
329
330elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
331
332 # Source and run the helper script to launch the pod or job
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500333 . ./kubernetes/kubernetes-launch.sh OpenBMC-build true true
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500334
335else
336 echo "Launch Parameter is invalid"
337fi
Chris Smart02651712015-11-11 11:09:00 +1100338
Alanny Lopezd32d3322017-07-18 15:21:39 -0500339# To maintain function of resources that used an older path, add a link
Alanny Lopez723fea62017-09-12 11:22:17 -0500340ln -sf ${extraction}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500341
Chris Smart02651712015-11-11 11:09:00 +1100342# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500343echo "Build completed, $(date)"