blob: d62e97245e76813acd35b6636e2c5db54190c272 [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}"
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050017#
Alanny Lopeze08e8702018-02-24 18:07:13 -060018# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060019# BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options
Alanny Lopeze08e8702018-02-24 18:07:13 -060020# you'd like to pass into the build.
21# Default: "", no options set
Alanny Lopez1246b032018-02-24 23:34:55 -060022# build_dir Path where the actual BitBake build occurs inside the
Alanny Lopeze08e8702018-02-24 18:07:13 -060023# container, path cannot be located on network storage.
24# Default: "/tmp/openbmc"
25# distro The distro used as the base image for the build image:
26# fedora|ubuntu
27# Default: "ubuntu"
Alanny Lopez1246b032018-02-24 23:34:55 -060028# img_name The name given to the target build's docker image.
Alanny Lopeze08e8702018-02-24 18:07:13 -060029# Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}"
Alanny Lopez1246b032018-02-24 23:34:55 -060030# img_tag The base docker image distro tag:
Alanny Lopeze08e8702018-02-24 18:07:13 -060031# ubuntu: latest|16.04|14.04|trusty|xenial
32# fedora: 23|24|25
33# Default: "latest"
34# target The target we aim to build:
35# barreleye|evb-ast2500|firestone|garrison|palmetto|qemu
36# romulus|witherspoon|zaius
37# Default: "qemu"
Alanny Lopez723fea62017-09-12 11:22:17 -050038#
Alanny Lopeze08e8702018-02-24 18:07:13 -060039# Deployment Variables:
Alanny Lopeze08e8702018-02-24 18:07:13 -060040# launch ""|job|pod
41# Can be left blank to launch the container via Docker
42# Job lets you keep a copy of job and container logs on the
43# api, can be useful if not using Jenkins as you can run the
44# job again via the api without needing this script.
45# Pod launches a container which runs to completion without
46# saving anything to the api when it completes.
Alanny Lopez1246b032018-02-24 23:34:55 -060047# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060048# for the build inside the container.
49# Default: "${WORKSPACE}/openbmc"
Alanny Lopez1246b032018-02-24 23:34:55 -060050# ssc_dir Path to use as the BitBake shared-state cache directory.
Alanny Lopeze08e8702018-02-24 18:07:13 -060051# Default: "/home/${USER}"
Alanny Lopez1246b032018-02-24 23:34:55 -060052# xtrct_path Path where the build_dir contents will be copied out to
53# when the build completes.
54# Default: "${obmc_dir}/build/tmp"
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050055#
56###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103057# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103058set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110059
Alanny Lopez46967702018-02-25 00:29:14 -060060# Script Variables:
61build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
62http_proxy=${http_proxy:-}
63WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
64
65# Docker Image Build Variables:
66build_dir=${build_dir:-/tmp/openbmc}
Chris Smart02651712015-11-11 11:09:00 +110067distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060068img_tag=${img_tag:-latest}
Alanny Lopez46967702018-02-25 00:29:14 -060069target=${target:-qemu}
70
71# Deployment variables
Alanny Lopez3fbaa512017-04-24 15:46:52 -050072launch=${launch:-}
Alanny Lopez46967702018-02-25 00:29:14 -060073obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
74ssc_dir=${ssc_dir:-${HOME}}
75xtrct_path=${xtrct_path:-${obmc_dir}/build/tmp}
76
Chris Smartc3522542016-02-16 11:59:36 +110077PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110078
Alanny Lopezccc650e2017-04-24 15:14:20 -050079# Determine the architecture
80ARCH=$(uname -m)
81
82# Determine the prefix of the Dockerfile's base image
83case ${ARCH} in
84 "ppc64le")
85 DOCKER_BASE="ppc64le/"
86 ;;
87 "x86_64")
88 DOCKER_BASE=""
89 ;;
90 *)
91 echo "Unsupported system architecture(${ARCH}) found for docker image"
92 exit 1
93esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050094
Chris Smart02651712015-11-11 11:09:00 +110095# Timestamp for job
96echo "Build started, $(date)"
97
Alanny Lopez1246b032018-02-24 23:34:55 -060098# If the obmc_dir directory doesn't exist clone it in
99if [ ! -d ${obmc_dir} ]; then
100 echo "Clone in openbmc master to ${obmc_dir}"
101 git clone https://github.com/openbmc/openbmc ${obmc_dir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500102fi
103
Alanny Lopez1246b032018-02-24 23:34:55 -0600104# Make and chown the xtrct_path directory to avoid permission errors
105if [ ! -d ${xtrct_path} ]; then
106 mkdir -p ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500107fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600108chown ${UID}:${GROUPS} ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500109
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500110# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +1100111case ${target} in
112 barreleye)
113 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
114 ;;
115 palmetto)
116 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
117 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930118 witherspoon)
119 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
120 ;;
121 firestone)
122 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
123 ;;
124 garrison)
125 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
126 ;;
127 evb-ast2500)
128 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
129 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030130 zaius)
131 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env"
132 ;;
133 romulus)
134 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env"
135 ;;
Chris Smart02651712015-11-11 11:09:00 +1100136 qemu)
137 BITBAKE_CMD="source openbmc-env"
138 ;;
139 *)
140 exit 1
141 ;;
142esac
143
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500144# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100145if [[ "${distro}" == fedora ]];then
146
147 if [[ -n "${http_proxy}" ]]; then
148 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
149 fi
150
151 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600152 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100153
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500154 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100155
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500156 # Set the locale
157 RUN locale-gen en_US.UTF-8
158 ENV LANG en_US.UTF-8
159 ENV LANGUAGE en_US:en
160 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500161
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500162 RUN dnf --refresh install -y \
163 bzip2 \
164 chrpath \
165 cpio \
166 diffstat \
167 findutils \
168 gcc \
169 gcc-c++ \
170 git \
171 make \
172 patch \
173 perl-bignum \
174 perl-Data-Dumper \
175 perl-Thread-Queue \
176 python-devel \
177 python3-devel \
178 SDL-devel \
179 socat \
180 subversion \
181 tar \
182 texinfo \
183 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500184 which \
185 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100186
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500187 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
188 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100189
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500190 USER ${USER}
191 ENV HOME ${HOME}
192 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100193EOF
194)
195
Alanny Lopezccc650e2017-04-24 15:14:20 -0500196elif [[ "${distro}" == ubuntu ]]; then
197
Chris Smart02651712015-11-11 11:09:00 +1100198 if [[ -n "${http_proxy}" ]]; then
199 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
200 fi
201
202 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600203 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100204
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500205 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100206
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500207 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500208
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500209 RUN apt-get update && apt-get install -yy \
210 build-essential \
211 chrpath \
212 debianutils \
213 diffstat \
214 gawk \
215 git \
216 libdata-dumper-simple-perl \
217 libsdl1.2-dev \
218 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500219 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500220 python \
221 python3 \
222 socat \
223 subversion \
224 texinfo \
225 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500226 wget \
227 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100228
Alanny Lopez27af3a02017-05-26 10:49:06 -0500229 # Set the locale
230 RUN locale-gen en_US.UTF-8
231 ENV LANG en_US.UTF-8
232 ENV LANGUAGE en_US:en
233 ENV LC_ALL en_US.UTF-8
234
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500235 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
236 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100237
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500238 USER ${USER}
239 ENV HOME ${HOME}
240 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100241EOF
242)
243fi
244
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500245# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100246export PROXY_HOST=${http_proxy/#http*:\/\/}
247export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
248export PROXY_PORT=${http_proxy/#http*:\/\/*:}
249
Chris Smart01d2b962015-11-11 18:05:30 +1100250mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100251
Chris Smart01d2b962015-11-11 18:05:30 +1100252cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100253#!/bin/bash
254
Joel Stanley38c9d142016-02-16 12:31:55 +1030255set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100256
Alanny Lopez723fea62017-09-12 11:22:17 -0500257# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600258cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100259
260# Set up proxies
261export ftp_proxy=${http_proxy}
262export http_proxy=${http_proxy}
263export https_proxy=${http_proxy}
264
Chris Smart01d2b962015-11-11 18:05:30 +1100265mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100266
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500267# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100268if [[ -n "${http_proxy}" ]]; then
269
Chris Smartd30c5902016-03-01 15:00:54 +1100270 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500271 #!/bin/bash
272 # \$1 = hostname, \$2 = port
273 PROXY=${PROXY_HOST}
274 PROXY_PORT=${PROXY_PORT}
275 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100276EOF_GIT
277
Chris Smart01d2b962015-11-11 18:05:30 +1100278 chmod a+x ${WORKSPACE}/bin/git-proxy
279 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100280 git config core.gitProxy git-proxy
281
282 mkdir -p ~/.subversion
283
284 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500285 [global]
286 http-proxy-host = ${PROXY_HOST}
287 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100288EOF_SVN
289fi
290
291# Source our build env
292${BITBAKE_CMD}
293
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500294# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100295cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100296BB_NUMBER_THREADS = "$(nproc)"
297PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100298INHERIT += "rm_work"
299BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600300DL_DIR="${ssc_dir}/bitbake_downloads"
301SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100302USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500303INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600304TMPDIR="${build_dir}"
Chris Smart02651712015-11-11 11:09:00 +1100305EOF_CONF
306
307# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500308bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100309
Alanny Lopez1246b032018-02-24 23:34:55 -0600310# Copy internal build directory into xtrct_path directory
311cp -r ${build_dir}/* ${xtrct_path}
Chris Smart02651712015-11-11 11:09:00 +1100312EOF_SCRIPT
313
314chmod a+x ${WORKSPACE}/build.sh
315
Alanny Lopez51186882017-08-01 16:14:41 -0500316# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600317img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500318
319# Build the Docker image
Alanny Lopez1246b032018-02-24 23:34:55 -0600320docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500321
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500322# Determine if the build container will be launched with Docker or Kubernetes
323if [[ "${launch}" == "" ]]; then
324
Alanny Lopez1246b032018-02-24 23:34:55 -0600325 # If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
326 mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
327 mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
328 if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
329 mount_obmc_dir=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500330 fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600331 if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
332 mount_ssc_dir=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500333 fi
334
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500335 # Run the Docker container, execute the build.sh script
336 docker run \
337 --cap-add=sys_admin \
338 --net=host \
339 --rm=true \
340 -e WORKSPACE=${WORKSPACE} \
341 -w "${HOME}" \
342 -v "${HOME}":"${HOME}" \
Alanny Lopez1246b032018-02-24 23:34:55 -0600343 ${mount_obmc_dir} \
344 ${mount_ssc_dir} \
345 -t ${img_name} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500346 ${WORKSPACE}/build.sh
347
348elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
349
350 # Source and run the helper script to launch the pod or job
Alanny Lopeze08e8702018-02-24 18:07:13 -0600351 . ${build_scripts_dir}/kubernetes/kubernetes-launch.sh OpenBMC-build true true
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500352
353else
354 echo "Launch Parameter is invalid"
355fi
Chris Smart02651712015-11-11 11:09:00 +1100356
Alanny Lopezd32d3322017-07-18 15:21:39 -0500357# To maintain function of resources that used an older path, add a link
Alanny Lopez1246b032018-02-24 23:34:55 -0600358ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500359
Chris Smart02651712015-11-11 11:09:00 +1100360# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500361echo "Build completed, $(date)"