blob: 7b184a724e99fb83f80b3feca3c7023d599337b6 [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#
Alanny Lopeze08e8702018-02-24 18:07:13 -06009# Script Variables:
10# build_scripts_dir The path of the openbmc-build-scripts directory.
11# Default: The directory containing this script
12# http_proxy The HTTP address of the proxy server to connect to.
13# Default: "", proxy is not setup if this is not set
14# WORKSPACE Path of the workspace directory where some intermediate
15# files and the images will be saved to.
16# Default: "~/{RandomNumber}"
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070017# num_cpu Number of cpu's to give bitbake, default is total amount
18# in system
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050019#
Alanny Lopeze08e8702018-02-24 18:07:13 -060020# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060021# BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options
Alanny Lopeze08e8702018-02-24 18:07:13 -060022# you'd like to pass into the build.
23# Default: "", no options set
Alanny Lopez1246b032018-02-24 23:34:55 -060024# build_dir Path where the actual BitBake build occurs inside the
Alanny Lopeze08e8702018-02-24 18:07:13 -060025# container, path cannot be located on network storage.
26# Default: "/tmp/openbmc"
27# distro The distro used as the base image for the build image:
28# fedora|ubuntu
29# Default: "ubuntu"
Alanny Lopez1246b032018-02-24 23:34:55 -060030# img_name The name given to the target build's docker image.
Alanny Lopeze08e8702018-02-24 18:07:13 -060031# Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}"
Alanny Lopez1246b032018-02-24 23:34:55 -060032# img_tag The base docker image distro tag:
Alanny Lopeze08e8702018-02-24 18:07:13 -060033# ubuntu: latest|16.04|14.04|trusty|xenial
34# fedora: 23|24|25
35# Default: "latest"
36# target The target we aim to build:
37# barreleye|evb-ast2500|firestone|garrison|palmetto|qemu
Ed Tanous6dc40d92018-07-30 11:13:36 -070038# romulus|s2600wf|witherspoon|zaius
Alanny Lopeze08e8702018-02-24 18:07:13 -060039# Default: "qemu"
Alanny Lopez723fea62017-09-12 11:22:17 -050040#
Alanny Lopeze08e8702018-02-24 18:07:13 -060041# Deployment Variables:
Alanny Lopeze08e8702018-02-24 18:07:13 -060042# launch ""|job|pod
43# Can be left blank to launch the container via Docker
44# Job lets you keep a copy of job and container logs on the
45# api, can be useful if not using Jenkins as you can run the
46# job again via the api without needing this script.
47# Pod launches a container which runs to completion without
48# saving anything to the api when it completes.
Alanny Lopez1246b032018-02-24 23:34:55 -060049# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060050# for the build inside the container.
51# Default: "${WORKSPACE}/openbmc"
Alanny Lopez1246b032018-02-24 23:34:55 -060052# ssc_dir Path to use as the BitBake shared-state cache directory.
Alanny Lopeze08e8702018-02-24 18:07:13 -060053# Default: "/home/${USER}"
Alanny Lopez1246b032018-02-24 23:34:55 -060054# xtrct_path Path where the build_dir contents will be copied out to
55# when the build completes.
56# Default: "${obmc_dir}/build/tmp"
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -050057# xtrct_copy_timeout Timeout (in seconds) for copying the contents of
58# build_dir to xtrct_path.
59# Default: "300"
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050060#
61###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103062# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103063set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110064
Alanny Lopez46967702018-02-25 00:29:14 -060065# Script Variables:
66build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
67http_proxy=${http_proxy:-}
68WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070069num_cpu=${num_cpu:-$(nproc)}
Alanny Lopez46967702018-02-25 00:29:14 -060070
71# Docker Image Build Variables:
72build_dir=${build_dir:-/tmp/openbmc}
Chris Smart02651712015-11-11 11:09:00 +110073distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060074img_tag=${img_tag:-latest}
Alanny Lopez46967702018-02-25 00:29:14 -060075target=${target:-qemu}
76
77# Deployment variables
Alanny Lopez3fbaa512017-04-24 15:46:52 -050078launch=${launch:-}
Alanny Lopez46967702018-02-25 00:29:14 -060079obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
80ssc_dir=${ssc_dir:-${HOME}}
81xtrct_path=${xtrct_path:-${obmc_dir}/build/tmp}
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -050082xtrct_copy_timeout=${xtrct_copy_timeout:-300}
Alanny Lopez46967702018-02-25 00:29:14 -060083
Chris Smartc3522542016-02-16 11:59:36 +110084PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110085
Alanny Lopezccc650e2017-04-24 15:14:20 -050086# Determine the architecture
87ARCH=$(uname -m)
88
89# Determine the prefix of the Dockerfile's base image
90case ${ARCH} in
91 "ppc64le")
92 DOCKER_BASE="ppc64le/"
93 ;;
94 "x86_64")
95 DOCKER_BASE=""
96 ;;
97 *)
98 echo "Unsupported system architecture(${ARCH}) found for docker image"
99 exit 1
100esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500101
Chris Smart02651712015-11-11 11:09:00 +1100102# Timestamp for job
103echo "Build started, $(date)"
104
Alanny Lopez1246b032018-02-24 23:34:55 -0600105# If the obmc_dir directory doesn't exist clone it in
106if [ ! -d ${obmc_dir} ]; then
107 echo "Clone in openbmc master to ${obmc_dir}"
108 git clone https://github.com/openbmc/openbmc ${obmc_dir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500109fi
110
Alanny Lopez1246b032018-02-24 23:34:55 -0600111# Make and chown the xtrct_path directory to avoid permission errors
112if [ ! -d ${xtrct_path} ]; then
113 mkdir -p ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500114fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600115chown ${UID}:${GROUPS} ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500116
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500117# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +1100118case ${target} in
Chris Smart02651712015-11-11 11:09:00 +1100119 palmetto)
Dave Cobbley06ffc072018-08-14 16:13:49 -0700120 BITBAKE_CMD="TEMPLATECONF=meta-ibm/meta-palmetto/conf source oe-init-build-env"
Chris Smart02651712015-11-11 11:09:00 +1100121 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930122 witherspoon)
Dave Cobbley06ffc072018-08-14 16:13:49 -0700123 BITBAKE_CMD="TEMPLATECONF=meta-ibm/meta-witherspoon/conf source oe-init-build-env"
Joel Stanley0e077202016-06-28 16:42:45 +0930124 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930125 evb-ast2500)
Dave Cobbley06ffc072018-08-14 16:13:49 -0700126 BITBAKE_CMD="TEMPLATECONF=meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
Joel Stanley0e077202016-06-28 16:42:45 +0930127 ;;
Ed Tanous6dc40d92018-07-30 11:13:36 -0700128 s2600wf)
Dave Cobbley06ffc072018-08-14 16:13:49 -0700129 BITBAKE_CMD="TEMPLATECONF=meta-intel/meta-s2600wf/conf source oe-init-build-env"
Ed Tanous6dc40d92018-07-30 11:13:36 -0700130 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030131 zaius)
Dave Cobbley06ffc072018-08-14 16:13:49 -0700132 BITBAKE_CMD="TEMPLATECONF=meta-ingrasys/meta-zaius/conf source oe-init-build-env"
Joel Stanley915381f2016-11-01 16:58:59 +1030133 ;;
134 romulus)
Dave Cobbley06ffc072018-08-14 16:13:49 -0700135 BITBAKE_CMD="TEMPLATECONF=meta-ibm/meta-romulus/conf source oe-init-build-env"
Joel Stanley915381f2016-11-01 16:58:59 +1030136 ;;
Chris Smart02651712015-11-11 11:09:00 +1100137 qemu)
138 BITBAKE_CMD="source openbmc-env"
139 ;;
140 *)
141 exit 1
142 ;;
143esac
144
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500145# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100146if [[ "${distro}" == fedora ]];then
147
148 if [[ -n "${http_proxy}" ]]; then
149 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
150 fi
151
152 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600153 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100154
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500155 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100156
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500157 # Set the locale
158 RUN locale-gen en_US.UTF-8
159 ENV LANG en_US.UTF-8
160 ENV LANGUAGE en_US:en
161 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500162
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500163 RUN dnf --refresh install -y \
164 bzip2 \
165 chrpath \
166 cpio \
167 diffstat \
168 findutils \
169 gcc \
170 gcc-c++ \
171 git \
172 make \
173 patch \
174 perl-bignum \
175 perl-Data-Dumper \
176 perl-Thread-Queue \
177 python-devel \
178 python3-devel \
179 SDL-devel \
180 socat \
181 subversion \
182 tar \
183 texinfo \
184 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500185 which \
186 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100187
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500188 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
189 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100190
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500191 USER ${USER}
192 ENV HOME ${HOME}
193 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100194EOF
195)
196
Alanny Lopezccc650e2017-04-24 15:14:20 -0500197elif [[ "${distro}" == ubuntu ]]; then
198
Chris Smart02651712015-11-11 11:09:00 +1100199 if [[ -n "${http_proxy}" ]]; then
200 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
201 fi
202
203 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600204 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100205
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500206 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100207
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500208 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500209
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500210 RUN apt-get update && apt-get install -yy \
211 build-essential \
212 chrpath \
213 debianutils \
214 diffstat \
215 gawk \
216 git \
217 libdata-dumper-simple-perl \
218 libsdl1.2-dev \
219 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500220 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500221 python \
222 python3 \
223 socat \
224 subversion \
225 texinfo \
226 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500227 wget \
228 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100229
Alanny Lopez27af3a02017-05-26 10:49:06 -0500230 # Set the locale
231 RUN locale-gen en_US.UTF-8
232 ENV LANG en_US.UTF-8
233 ENV LANGUAGE en_US:en
234 ENV LC_ALL en_US.UTF-8
235
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500236 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
237 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100238
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500239 USER ${USER}
240 ENV HOME ${HOME}
241 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100242EOF
243)
244fi
245
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500246# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100247export PROXY_HOST=${http_proxy/#http*:\/\/}
248export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
249export PROXY_PORT=${http_proxy/#http*:\/\/*:}
250
Chris Smart01d2b962015-11-11 18:05:30 +1100251mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100252
Chris Smart01d2b962015-11-11 18:05:30 +1100253cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100254#!/bin/bash
255
Joel Stanley38c9d142016-02-16 12:31:55 +1030256set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100257
Alanny Lopez723fea62017-09-12 11:22:17 -0500258# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600259cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100260
261# Set up proxies
262export ftp_proxy=${http_proxy}
263export http_proxy=${http_proxy}
264export https_proxy=${http_proxy}
265
Chris Smart01d2b962015-11-11 18:05:30 +1100266mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100267
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500268# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100269if [[ -n "${http_proxy}" ]]; then
270
Chris Smartd30c5902016-03-01 15:00:54 +1100271 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500272 #!/bin/bash
273 # \$1 = hostname, \$2 = port
274 PROXY=${PROXY_HOST}
275 PROXY_PORT=${PROXY_PORT}
276 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100277EOF_GIT
278
Chris Smart01d2b962015-11-11 18:05:30 +1100279 chmod a+x ${WORKSPACE}/bin/git-proxy
280 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100281 git config core.gitProxy git-proxy
282
283 mkdir -p ~/.subversion
284
285 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500286 [global]
287 http-proxy-host = ${PROXY_HOST}
288 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100289EOF_SVN
290fi
291
292# Source our build env
293${BITBAKE_CMD}
294
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500295# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100296cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100297BB_NUMBER_THREADS = "$(nproc)"
298PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100299INHERIT += "rm_work"
300BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600301DL_DIR="${ssc_dir}/bitbake_downloads"
302SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100303USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500304INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600305TMPDIR="${build_dir}"
Chris Smart02651712015-11-11 11:09:00 +1100306EOF_CONF
307
308# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500309bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100310
Alanny Lopez1246b032018-02-24 23:34:55 -0600311# Copy internal build directory into xtrct_path directory
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500312timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
313
314
315if [[ 0 -ne $? ]]; then
316 echo "Received a non-zero exit code from timeout"
317 exit 1
318fi
319
Chris Smart02651712015-11-11 11:09:00 +1100320EOF_SCRIPT
321
322chmod a+x ${WORKSPACE}/build.sh
323
Alanny Lopez51186882017-08-01 16:14:41 -0500324# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600325img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500326
327# Build the Docker image
Alanny Lopez1246b032018-02-24 23:34:55 -0600328docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500329
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500330# Determine if the build container will be launched with Docker or Kubernetes
331if [[ "${launch}" == "" ]]; then
332
Alanny Lopez1246b032018-02-24 23:34:55 -0600333 # If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
334 mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
335 mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
336 if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
337 mount_obmc_dir=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500338 fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600339 if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
340 mount_ssc_dir=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500341 fi
342
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500343 # Run the Docker container, execute the build.sh script
344 docker run \
345 --cap-add=sys_admin \
346 --net=host \
347 --rm=true \
348 -e WORKSPACE=${WORKSPACE} \
349 -w "${HOME}" \
350 -v "${HOME}":"${HOME}" \
Alanny Lopez1246b032018-02-24 23:34:55 -0600351 ${mount_obmc_dir} \
352 ${mount_ssc_dir} \
Andrew Geisslerdc1e7022018-03-26 07:54:48 -0700353 --cpus="$num_cpu" \
Alanny Lopez1246b032018-02-24 23:34:55 -0600354 -t ${img_name} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500355 ${WORKSPACE}/build.sh
356
357elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
358
359 # Source and run the helper script to launch the pod or job
Alanny Lopeze08e8702018-02-24 18:07:13 -0600360 . ${build_scripts_dir}/kubernetes/kubernetes-launch.sh OpenBMC-build true true
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500361
362else
363 echo "Launch Parameter is invalid"
364fi
Chris Smart02651712015-11-11 11:09:00 +1100365
Alanny Lopezd32d3322017-07-18 15:21:39 -0500366# To maintain function of resources that used an older path, add a link
Alanny Lopez1246b032018-02-24 23:34:55 -0600367ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500368
Chris Smart02651712015-11-11 11:09:00 +1100369# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500370echo "Build completed, $(date)"