blob: 19fab9fe02b3f2a897357f1581779f38e43db801 [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
38# romulus|witherspoon|zaius
39# 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"
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050057#
58###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103059# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103060set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110061
Alanny Lopez46967702018-02-25 00:29:14 -060062# Script Variables:
63build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
64http_proxy=${http_proxy:-}
65WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070066num_cpu=${num_cpu:-$(nproc)}
Alanny Lopez46967702018-02-25 00:29:14 -060067
68# Docker Image Build Variables:
69build_dir=${build_dir:-/tmp/openbmc}
Chris Smart02651712015-11-11 11:09:00 +110070distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060071img_tag=${img_tag:-latest}
Alanny Lopez46967702018-02-25 00:29:14 -060072target=${target:-qemu}
73
74# Deployment variables
Alanny Lopez3fbaa512017-04-24 15:46:52 -050075launch=${launch:-}
Alanny Lopez46967702018-02-25 00:29:14 -060076obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
77ssc_dir=${ssc_dir:-${HOME}}
78xtrct_path=${xtrct_path:-${obmc_dir}/build/tmp}
79
Chris Smartc3522542016-02-16 11:59:36 +110080PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110081
Alanny Lopezccc650e2017-04-24 15:14:20 -050082# Determine the architecture
83ARCH=$(uname -m)
84
85# Determine the prefix of the Dockerfile's base image
86case ${ARCH} in
87 "ppc64le")
88 DOCKER_BASE="ppc64le/"
89 ;;
90 "x86_64")
91 DOCKER_BASE=""
92 ;;
93 *)
94 echo "Unsupported system architecture(${ARCH}) found for docker image"
95 exit 1
96esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050097
Chris Smart02651712015-11-11 11:09:00 +110098# Timestamp for job
99echo "Build started, $(date)"
100
Alanny Lopez1246b032018-02-24 23:34:55 -0600101# If the obmc_dir directory doesn't exist clone it in
102if [ ! -d ${obmc_dir} ]; then
103 echo "Clone in openbmc master to ${obmc_dir}"
104 git clone https://github.com/openbmc/openbmc ${obmc_dir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500105fi
106
Alanny Lopez1246b032018-02-24 23:34:55 -0600107# Make and chown the xtrct_path directory to avoid permission errors
108if [ ! -d ${xtrct_path} ]; then
109 mkdir -p ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500110fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600111chown ${UID}:${GROUPS} ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500112
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500113# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +1100114case ${target} in
115 barreleye)
116 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
117 ;;
118 palmetto)
119 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
120 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930121 witherspoon)
122 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
123 ;;
124 firestone)
125 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
126 ;;
127 garrison)
128 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
129 ;;
130 evb-ast2500)
131 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
132 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030133 zaius)
134 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env"
135 ;;
136 romulus)
137 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env"
138 ;;
Chris Smart02651712015-11-11 11:09:00 +1100139 qemu)
140 BITBAKE_CMD="source openbmc-env"
141 ;;
142 *)
143 exit 1
144 ;;
145esac
146
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500147# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100148if [[ "${distro}" == fedora ]];then
149
150 if [[ -n "${http_proxy}" ]]; then
151 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
152 fi
153
154 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600155 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100156
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500157 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100158
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500159 # Set the locale
160 RUN locale-gen en_US.UTF-8
161 ENV LANG en_US.UTF-8
162 ENV LANGUAGE en_US:en
163 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500164
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500165 RUN dnf --refresh install -y \
166 bzip2 \
167 chrpath \
168 cpio \
169 diffstat \
170 findutils \
171 gcc \
172 gcc-c++ \
173 git \
174 make \
175 patch \
176 perl-bignum \
177 perl-Data-Dumper \
178 perl-Thread-Queue \
179 python-devel \
180 python3-devel \
181 SDL-devel \
182 socat \
183 subversion \
184 tar \
185 texinfo \
186 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500187 which \
188 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100189
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500190 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
191 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100192
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500193 USER ${USER}
194 ENV HOME ${HOME}
195 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100196EOF
197)
198
Alanny Lopezccc650e2017-04-24 15:14:20 -0500199elif [[ "${distro}" == ubuntu ]]; then
200
Chris Smart02651712015-11-11 11:09:00 +1100201 if [[ -n "${http_proxy}" ]]; then
202 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
203 fi
204
205 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600206 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100207
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500208 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100209
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500210 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500211
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500212 RUN apt-get update && apt-get install -yy \
213 build-essential \
214 chrpath \
215 debianutils \
216 diffstat \
217 gawk \
218 git \
219 libdata-dumper-simple-perl \
220 libsdl1.2-dev \
221 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500222 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500223 python \
224 python3 \
225 socat \
226 subversion \
227 texinfo \
228 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500229 wget \
230 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100231
Alanny Lopez27af3a02017-05-26 10:49:06 -0500232 # Set the locale
233 RUN locale-gen en_US.UTF-8
234 ENV LANG en_US.UTF-8
235 ENV LANGUAGE en_US:en
236 ENV LC_ALL en_US.UTF-8
237
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500238 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
239 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100240
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500241 USER ${USER}
242 ENV HOME ${HOME}
243 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100244EOF
245)
246fi
247
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500248# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100249export PROXY_HOST=${http_proxy/#http*:\/\/}
250export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
251export PROXY_PORT=${http_proxy/#http*:\/\/*:}
252
Chris Smart01d2b962015-11-11 18:05:30 +1100253mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100254
Chris Smart01d2b962015-11-11 18:05:30 +1100255cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100256#!/bin/bash
257
Joel Stanley38c9d142016-02-16 12:31:55 +1030258set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100259
Alanny Lopez723fea62017-09-12 11:22:17 -0500260# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600261cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100262
263# Set up proxies
264export ftp_proxy=${http_proxy}
265export http_proxy=${http_proxy}
266export https_proxy=${http_proxy}
267
Chris Smart01d2b962015-11-11 18:05:30 +1100268mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100269
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500270# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100271if [[ -n "${http_proxy}" ]]; then
272
Chris Smartd30c5902016-03-01 15:00:54 +1100273 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500274 #!/bin/bash
275 # \$1 = hostname, \$2 = port
276 PROXY=${PROXY_HOST}
277 PROXY_PORT=${PROXY_PORT}
278 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100279EOF_GIT
280
Chris Smart01d2b962015-11-11 18:05:30 +1100281 chmod a+x ${WORKSPACE}/bin/git-proxy
282 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100283 git config core.gitProxy git-proxy
284
285 mkdir -p ~/.subversion
286
287 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500288 [global]
289 http-proxy-host = ${PROXY_HOST}
290 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100291EOF_SVN
292fi
293
294# Source our build env
295${BITBAKE_CMD}
296
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500297# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100298cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100299BB_NUMBER_THREADS = "$(nproc)"
300PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100301INHERIT += "rm_work"
302BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600303DL_DIR="${ssc_dir}/bitbake_downloads"
304SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100305USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500306INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600307TMPDIR="${build_dir}"
Chris Smart02651712015-11-11 11:09:00 +1100308EOF_CONF
309
310# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500311bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100312
Alanny Lopez1246b032018-02-24 23:34:55 -0600313# Copy internal build directory into xtrct_path directory
314cp -r ${build_dir}/* ${xtrct_path}
Chris Smart02651712015-11-11 11:09:00 +1100315EOF_SCRIPT
316
317chmod a+x ${WORKSPACE}/build.sh
318
Alanny Lopez51186882017-08-01 16:14:41 -0500319# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600320img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500321
322# Build the Docker image
Alanny Lopez1246b032018-02-24 23:34:55 -0600323docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500324
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500325# Determine if the build container will be launched with Docker or Kubernetes
326if [[ "${launch}" == "" ]]; then
327
Alanny Lopez1246b032018-02-24 23:34:55 -0600328 # If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
329 mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
330 mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
331 if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
332 mount_obmc_dir=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500333 fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600334 if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
335 mount_ssc_dir=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500336 fi
337
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500338 # Run the Docker container, execute the build.sh script
339 docker run \
340 --cap-add=sys_admin \
341 --net=host \
342 --rm=true \
343 -e WORKSPACE=${WORKSPACE} \
344 -w "${HOME}" \
345 -v "${HOME}":"${HOME}" \
Alanny Lopez1246b032018-02-24 23:34:55 -0600346 ${mount_obmc_dir} \
347 ${mount_ssc_dir} \
Andrew Geisslerdc1e7022018-03-26 07:54:48 -0700348 --cpus="$num_cpu" \
Alanny Lopez1246b032018-02-24 23:34:55 -0600349 -t ${img_name} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500350 ${WORKSPACE}/build.sh
351
352elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
353
354 # Source and run the helper script to launch the pod or job
Alanny Lopeze08e8702018-02-24 18:07:13 -0600355 . ${build_scripts_dir}/kubernetes/kubernetes-launch.sh OpenBMC-build true true
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500356
357else
358 echo "Launch Parameter is invalid"
359fi
Chris Smart02651712015-11-11 11:09:00 +1100360
Alanny Lopezd32d3322017-07-18 15:21:39 -0500361# To maintain function of resources that used an older path, add a link
Alanny Lopez1246b032018-02-24 23:34:55 -0600362ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500363
Chris Smart02651712015-11-11 11:09:00 +1100364# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500365echo "Build completed, $(date)"