blob: 5d80957d7300dfc1000f36d20305e5fa65af0068 [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
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050013# obmcext = Path of the OpenBMC repo directory used in creating a copy
14# inside the container that is not mounted to external storage
15# default directory location "${WORKSPACE}/openbmc"
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050016# obmcdir = Path of the OpenBMC directory, where the build occurs inside
17# the container cannot be placed on external storage default
18# directory location "/tmp/openbmc"
19# sscdir = Path of the BitBake shared-state cache directoy, will default
20# to directory "/home/${USER}", used to speed up builds.
21# WORKSPACE = Path of the workspace directory where some intermediate files
22# and the images will be saved to.
23#
24# Optional Variables:
25# launch = job|pod
26# Can be left blank to launch via Docker if not using
27# Kubernetes to launch the container.
28# Job lets you keep a copy of job and container logs on the
29# api, can be useful if not using Jenkins as you can run the
30# job again via the api without needing this script.
31# Pod launches a container which runs to completion without
32# saving anything to the api when it completes.
33# imgname = Defaults to a relatively long but descriptive name, can be
34# changed or passed to give a specific name to created image.
35# http_proxy = The HTTP address for the proxy server you wish to connect to.
36# BITBAKE_OPTS = Set to "-c populate_sdk" or whatever other bitbake options
37# you'd like to pass into the build.
38#
39###############################################################################
Chris Smart02651712015-11-11 11:09:00 +110040
Joel Stanley4b8b2392016-02-12 15:44:57 +103041# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103042set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110043
44# Default variables
45target=${target:-qemu}
46distro=${distro:-ubuntu}
Alanny Lopezccc650e2017-04-24 15:14:20 -050047imgtag=${imgtag:-latest}
Alanny Lopeze6870192017-04-24 15:25:59 -050048obmcdir=${obmcdir:-/tmp/openbmc}
Alanny Lopez97a79502017-04-24 16:19:25 -050049sscdir=${sscdir:-${HOME}}
Chris Smart02651712015-11-11 11:09:00 +110050WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050051obmcext=${obmcext:-${WORKSPACE}/openbmc}
Alanny Lopez3fbaa512017-04-24 15:46:52 -050052launch=${launch:-}
Chris Smart02651712015-11-11 11:09:00 +110053http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110054PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110055
Alanny Lopezccc650e2017-04-24 15:14:20 -050056# Determine the architecture
57ARCH=$(uname -m)
58
59# Determine the prefix of the Dockerfile's base image
60case ${ARCH} in
61 "ppc64le")
62 DOCKER_BASE="ppc64le/"
63 ;;
64 "x86_64")
65 DOCKER_BASE=""
66 ;;
67 *)
68 echo "Unsupported system architecture(${ARCH}) found for docker image"
69 exit 1
70esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050071
Chris Smart02651712015-11-11 11:09:00 +110072# Timestamp for job
73echo "Build started, $(date)"
74
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050075# If the obmcext directory doesn't exist clone it in
76if [ ! -d ${obmcext} ]; then
77 echo "Clone in openbmc master to ${obmcext}"
78 git clone https://github.com/openbmc/openbmc ${obmcext}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050079fi
80
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050081# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +110082case ${target} in
83 barreleye)
84 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
85 ;;
86 palmetto)
87 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
88 ;;
Joel Stanley0e077202016-06-28 16:42:45 +093089 witherspoon)
90 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
91 ;;
92 firestone)
93 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
94 ;;
95 garrison)
96 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
97 ;;
98 evb-ast2500)
99 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
100 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030101 zaius)
102 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env"
103 ;;
104 romulus)
105 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env"
106 ;;
Chris Smart02651712015-11-11 11:09:00 +1100107 qemu)
108 BITBAKE_CMD="source openbmc-env"
109 ;;
110 *)
111 exit 1
112 ;;
113esac
114
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500115# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100116if [[ "${distro}" == fedora ]];then
117
118 if [[ -n "${http_proxy}" ]]; then
119 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
120 fi
121
122 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500123 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100124
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500125 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100126
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500127 # Set the locale
128 RUN locale-gen en_US.UTF-8
129 ENV LANG en_US.UTF-8
130 ENV LANGUAGE en_US:en
131 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500132
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500133 RUN dnf --refresh install -y \
134 bzip2 \
135 chrpath \
136 cpio \
137 diffstat \
138 findutils \
139 gcc \
140 gcc-c++ \
141 git \
142 make \
143 patch \
144 perl-bignum \
145 perl-Data-Dumper \
146 perl-Thread-Queue \
147 python-devel \
148 python3-devel \
149 SDL-devel \
150 socat \
151 subversion \
152 tar \
153 texinfo \
154 wget \
155 which
Chris Smart02651712015-11-11 11:09:00 +1100156
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500157 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
158 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100159
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500160 USER ${USER}
161 ENV HOME ${HOME}
162 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100163EOF
164)
165
Alanny Lopezccc650e2017-04-24 15:14:20 -0500166elif [[ "${distro}" == ubuntu ]]; then
167
Chris Smart02651712015-11-11 11:09:00 +1100168 if [[ -n "${http_proxy}" ]]; then
169 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
170 fi
171
172 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500173 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100174
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500175 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100176
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500177 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500178
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500179 RUN apt-get update && apt-get install -yy \
180 build-essential \
181 chrpath \
182 debianutils \
183 diffstat \
184 gawk \
185 git \
186 libdata-dumper-simple-perl \
187 libsdl1.2-dev \
188 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500189 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500190 python \
191 python3 \
192 socat \
193 subversion \
194 texinfo \
195 cpio \
196 wget
Chris Smart02651712015-11-11 11:09:00 +1100197
Alanny Lopez27af3a02017-05-26 10:49:06 -0500198 # Set the locale
199 RUN locale-gen en_US.UTF-8
200 ENV LANG en_US.UTF-8
201 ENV LANGUAGE en_US:en
202 ENV LC_ALL en_US.UTF-8
203
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500204 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
205 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100206
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500207 USER ${USER}
208 ENV HOME ${HOME}
209 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100210EOF
211)
212fi
213
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500214# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100215export PROXY_HOST=${http_proxy/#http*:\/\/}
216export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
217export PROXY_PORT=${http_proxy/#http*:\/\/*:}
218
Chris Smart01d2b962015-11-11 18:05:30 +1100219mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100220
Chris Smart01d2b962015-11-11 18:05:30 +1100221cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100222#!/bin/bash
223
Joel Stanley38c9d142016-02-16 12:31:55 +1030224set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100225
Alanny Lopeze6870192017-04-24 15:25:59 -0500226# Use the mounted repo cache to make an internal repo not mounted externally
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500227cp -R ${obmcext} ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100228
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500229# Go into the OpenBMC directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500230cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100231
232# Set up proxies
233export ftp_proxy=${http_proxy}
234export http_proxy=${http_proxy}
235export https_proxy=${http_proxy}
236
Chris Smart01d2b962015-11-11 18:05:30 +1100237mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100238
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500239# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100240if [[ -n "${http_proxy}" ]]; then
241
Chris Smartd30c5902016-03-01 15:00:54 +1100242 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500243 #!/bin/bash
244 # \$1 = hostname, \$2 = port
245 PROXY=${PROXY_HOST}
246 PROXY_PORT=${PROXY_PORT}
247 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100248EOF_GIT
249
Chris Smart01d2b962015-11-11 18:05:30 +1100250 chmod a+x ${WORKSPACE}/bin/git-proxy
251 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100252 git config core.gitProxy git-proxy
253
254 mkdir -p ~/.subversion
255
256 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500257 [global]
258 http-proxy-host = ${PROXY_HOST}
259 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100260EOF_SVN
261fi
262
263# Source our build env
264${BITBAKE_CMD}
265
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500266# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100267cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100268BB_NUMBER_THREADS = "$(nproc)"
269PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100270INHERIT += "rm_work"
271BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez97a79502017-04-24 16:19:25 -0500272DL_DIR="${sscdir}/bitbake_downloads"
273SSTATE_DIR="${sscdir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100274USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500275INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100276EOF_CONF
277
278# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500279bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100280
Alanny Lopeze6870192017-04-24 15:25:59 -0500281# Copy images out of internal obmcdir into workspace directory
Alanny Lopezb0a12dd2017-04-24 16:21:47 -0500282cp -R ${obmcdir}/build/tmp/deploy ${WORKSPACE}/deploy/
Alanny Lopeze6870192017-04-24 15:25:59 -0500283
Chris Smart02651712015-11-11 11:09:00 +1100284EOF_SCRIPT
285
286chmod a+x ${WORKSPACE}/build.sh
287
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500288# Determine if the build container will be launched with Docker or Kubernetes
289if [[ "${launch}" == "" ]]; then
290
291 # Give the Docker image a name based on the distro,tag,arch,and target
292 imgname=${imgname:-openbmc/${distro}:${imgtag}-${target}-${ARCH}}
293
294 # Build the Docker image
295 docker build -t ${imgname} - <<< "${Dockerfile}"
296
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500297 # If obmcext or sscdir are ${HOME} or a subdirectory they will not be mounted
298 mountobmcext="-v ""${obmcext}"":""${obmcext}"" "
Alanny Lopez97a79502017-04-24 16:19:25 -0500299 mountsscdir="-v ""${sscdir}"":""${sscdir}"" "
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500300 if [[ "${obmcext}" = "${HOME}/"* || "${obmcext}" = "${HOME}" ]];then
301 mountobmcext=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500302 fi
303 if [[ "${sscdir}" = "${HOME}/"* || "${sscdir}" = "${HOME}" ]];then
304 mountsscdir=""
305 fi
306
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500307 # Run the Docker container, execute the build.sh script
308 docker run \
309 --cap-add=sys_admin \
310 --net=host \
311 --rm=true \
312 -e WORKSPACE=${WORKSPACE} \
313 -w "${HOME}" \
314 -v "${HOME}":"${HOME}" \
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500315 ${mountobmcext} \
Alanny Lopez97a79502017-04-24 16:19:25 -0500316 ${mountsscdir} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500317 -t ${imgname} \
318 ${WORKSPACE}/build.sh
319
320elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
321
322 # Source and run the helper script to launch the pod or job
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500323 . ./kubernetes/kubernetes-launch.sh OpenBMC-build true true
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500324
325else
326 echo "Launch Parameter is invalid"
327fi
Chris Smart02651712015-11-11 11:09:00 +1100328
329# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500330echo "Build completed, $(date)"