blob: 4ea63555fbae03f692fd40796f681463b832e75b [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#
Michael Shepos3939e952019-01-16 16:00:35 -06004# This build script is for running the OpenBMC builds as Docker containers.
Alanny Lopez3fbaa512017-04-24 15:46:52 -05005#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05006###############################################################################
7#
Alanny Lopeze08e8702018-02-24 18:07:13 -06008# Script Variables:
9# build_scripts_dir The path of the openbmc-build-scripts directory.
10# Default: The directory containing this script
11# http_proxy The HTTP address of the proxy server to connect to.
12# Default: "", proxy is not setup if this is not set
13# WORKSPACE Path of the workspace directory where some intermediate
14# files and the images will be saved to.
15# Default: "~/{RandomNumber}"
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070016# num_cpu Number of cpu's to give bitbake, default is total amount
17# in system
Lei YU237bd082020-09-22 11:15:08 +080018# UBUNTU_MIRROR [optional] The URL of a mirror of Ubuntu to override the
19# default ones in /etc/apt/sources.list
Lei YU39587ad2020-06-17 19:55:54 +080020# default is empty, and no mirror is used.
Lei YU237bd082020-09-22 11:15:08 +080021# ENV_LOCAL_CONF [optional] The environment variables to inject into the
22# build, which will be written into local.conf.
23# default is empty.
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050024#
Alanny Lopeze08e8702018-02-24 18:07:13 -060025# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060026# BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options
Alanny Lopeze08e8702018-02-24 18:07:13 -060027# you'd like to pass into the build.
28# Default: "", no options set
Alanny Lopez1246b032018-02-24 23:34:55 -060029# build_dir Path where the actual BitBake build occurs inside the
Alanny Lopeze08e8702018-02-24 18:07:13 -060030# container, path cannot be located on network storage.
Andrew Geisslerbd11f692020-09-04 09:36:28 -050031# Default: "$WORKSPACE/build"
Alanny Lopeze08e8702018-02-24 18:07:13 -060032# distro The distro used as the base image for the build image:
33# fedora|ubuntu
34# Default: "ubuntu"
Alanny Lopez1246b032018-02-24 23:34:55 -060035# img_name The name given to the target build's docker image.
Alanny Lopeze08e8702018-02-24 18:07:13 -060036# Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}"
Alanny Lopez1246b032018-02-24 23:34:55 -060037# img_tag The base docker image distro tag:
Alanny Lopeze08e8702018-02-24 18:07:13 -060038# ubuntu: latest|16.04|14.04|trusty|xenial
39# fedora: 23|24|25
40# Default: "latest"
Patrick Williams01dd4362021-02-19 17:45:40 -060041# target The target we aim to build. Any system supported by
42# the openbmc/openbmc `setup` script is an option.
Patrick Williams1642d132021-02-19 15:18:20 -060043# Default: "qemuarm"
Andrew Geissler215e43c2019-04-23 10:57:48 -050044# no_tar Set to true if you do not want the debug tar built
45# Default: "false"
Michael Shepos33aeca42019-06-13 02:36:17 -050046# nice_priority Set nice priotity for bitbake command.
47# Nice:
48# Run with an adjusted niceness, which affects process
49# scheduling. Nice values range from -20 (most favorable
50# to the process) to 19 (least favorable to the process).
51# Default: "", nice is not used if nice_priority is not set
Alanny Lopez723fea62017-09-12 11:22:17 -050052#
Alanny Lopeze08e8702018-02-24 18:07:13 -060053# Deployment Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060054# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060055# for the build inside the container.
56# Default: "${WORKSPACE}/openbmc"
Lei YUdf0e45c2020-09-03 11:25:57 +080057# ssc_dir Path of the OpenBMC shared directory that contains the
58# downloads dir and the sstate dir.
59# Default: "${HOME}"
Michael Shepos10afbb22019-02-06 13:33:07 -060060# xtrct_small_copy_dir
61# Directory within build_dir that should be copied to
62# xtrct_path. The directory and all parents up to, but not
63# including, build_dir will be copied. For example, if
64# build_dir is set to "/tmp/openbmc" and this is set to
65# "build/tmp", the directory at xtrct_path will have the
66# following directory structure:
67# xtrct_path
68# | - build
69# | - tmp
70# ...
71# Can also be set to the empty string to copy the entire
72# contents of build_dir to xtrct_path.
73# Default: "deploy/images".
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050074#
75###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103076# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103077set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110078
Alanny Lopez46967702018-02-25 00:29:14 -060079# Script Variables:
80build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
81http_proxy=${http_proxy:-}
82WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070083num_cpu=${num_cpu:-$(nproc)}
Lei YU39587ad2020-06-17 19:55:54 +080084UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
Lei YU237bd082020-09-22 11:15:08 +080085ENV_LOCAL_CONF=${ENV_LOCAL_CONF:-""}
Alanny Lopez46967702018-02-25 00:29:14 -060086
87# Docker Image Build Variables:
Andrew Geisslerbd11f692020-09-04 09:36:28 -050088build_dir=${build_dir:-${WORKSPACE}/build}
Chris Smart02651712015-11-11 11:09:00 +110089distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060090img_tag=${img_tag:-latest}
Patrick Williams1642d132021-02-19 15:18:20 -060091target=${target:-qemuarm}
Andrew Geissler215e43c2019-04-23 10:57:48 -050092no_tar=${no_tar:-false}
Michael Shepos33aeca42019-06-13 02:36:17 -050093nice_priority=${nice_priority:-}
Alanny Lopez46967702018-02-25 00:29:14 -060094
95# Deployment variables
Alanny Lopez46967702018-02-25 00:29:14 -060096obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
Lei YUdf0e45c2020-09-03 11:25:57 +080097ssc_dir=${ssc_dir:-${HOME}}
Michael Shepos10afbb22019-02-06 13:33:07 -060098xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images}
Michael Shepos3939e952019-01-16 16:00:35 -060099xtrct_path="${obmc_dir}/build/tmp"
100xtrct_copy_timeout="300"
Alanny Lopez46967702018-02-25 00:29:14 -0600101
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500102bitbake_target="obmc-phosphor-image"
Chris Smartc3522542016-02-16 11:59:36 +1100103PROXY=""
Chris Smart02651712015-11-11 11:09:00 +1100104
Lei YU39587ad2020-06-17 19:55:54 +0800105MIRROR=""
106if [[ -n "${UBUNTU_MIRROR}" ]]; then
107 MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
108 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
109 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
110 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
111 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
112fi
113
Alanny Lopezccc650e2017-04-24 15:14:20 -0500114# Determine the architecture
115ARCH=$(uname -m)
116
117# Determine the prefix of the Dockerfile's base image
118case ${ARCH} in
119 "ppc64le")
120 DOCKER_BASE="ppc64le/"
121 ;;
122 "x86_64")
123 DOCKER_BASE=""
124 ;;
125 *)
126 echo "Unsupported system architecture(${ARCH}) found for docker image"
127 exit 1
128esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500129
Chris Smart02651712015-11-11 11:09:00 +1100130# Timestamp for job
131echo "Build started, $(date)"
132
Alanny Lopez1246b032018-02-24 23:34:55 -0600133# If the obmc_dir directory doesn't exist clone it in
Patrick Williams384d7412020-11-06 16:15:41 -0600134if [ ! -d "${obmc_dir}" ]; then
Alanny Lopez1246b032018-02-24 23:34:55 -0600135 echo "Clone in openbmc master to ${obmc_dir}"
Patrick Williams384d7412020-11-06 16:15:41 -0600136 git clone https://github.com/openbmc/openbmc "${obmc_dir}"
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500137fi
138
Alanny Lopez1246b032018-02-24 23:34:55 -0600139# Make and chown the xtrct_path directory to avoid permission errors
Patrick Williams384d7412020-11-06 16:15:41 -0600140if [ ! -d "${xtrct_path}" ]; then
141 mkdir -p "${xtrct_path}"
Alanny Lopez723fea62017-09-12 11:22:17 -0500142fi
Patrick Williams384d7412020-11-06 16:15:41 -0600143chown "${UID}:${GROUPS[0]}" "${xtrct_path}"
Alanny Lopez723fea62017-09-12 11:22:17 -0500144
Patrick Williams01dd4362021-02-19 17:45:40 -0600145# Perform overrides for specific machines as required.
Adriana Kobylak1d2682b2021-04-01 18:40:42 +0000146DISTRO=${DISTRO:-}
Chris Smart02651712015-11-11 11:09:00 +1100147
Patrick Williams01dd4362021-02-19 17:45:40 -0600148# Set build target and BitBake command
149MACHINE="${target}"
Patrick Williamsf88e83f2021-02-19 15:15:06 -0600150BITBAKE_CMD="source ./setup ${MACHINE} ${build_dir}"
Brad Bishop7161a172018-10-05 16:48:06 -0400151
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500152# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100153if [[ "${distro}" == fedora ]];then
154
155 if [[ -n "${http_proxy}" ]]; then
156 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
157 fi
158
159 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600160 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100161
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500162 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100163
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500164 RUN dnf --refresh install -y \
165 bzip2 \
166 chrpath \
167 cpio \
168 diffstat \
169 findutils \
170 gcc \
171 gcc-c++ \
172 git \
173 make \
174 patch \
175 perl-bignum \
176 perl-Data-Dumper \
177 perl-Thread-Queue \
178 python-devel \
179 python3-devel \
180 SDL-devel \
181 socat \
182 subversion \
183 tar \
184 texinfo \
185 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500186 which \
Andrew Geissler40c1c9c2020-09-04 10:50:36 -0500187 file \
188 hostname \
189 rpcgen \
190 glibc-langpack-en \
191 glibc-locale-source
192
193 # Set the locale
194 ENV LANG=en_US.utf8
195 RUN localedef -f UTF-8 -i en_US en_US.UTF-8
Chris Smart02651712015-11-11 11:09:00 +1100196
Patrick Williams384d7412020-11-06 16:15:41 -0600197 RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
198 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100199
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500200 USER ${USER}
201 ENV HOME ${HOME}
202 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100203EOF
204)
205
Alanny Lopezccc650e2017-04-24 15:14:20 -0500206elif [[ "${distro}" == ubuntu ]]; then
207
Chris Smart02651712015-11-11 11:09:00 +1100208 if [[ -n "${http_proxy}" ]]; then
209 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
210 fi
211
212 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600213 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100214
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500215 ${PROXY}
Lei YU39587ad2020-06-17 19:55:54 +0800216 ${MIRROR}
Chris Smart02651712015-11-11 11:09:00 +1100217
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500218 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500219
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500220 RUN apt-get update && apt-get install -yy \
221 build-essential \
222 chrpath \
223 debianutils \
224 diffstat \
225 gawk \
226 git \
227 libdata-dumper-simple-perl \
228 libsdl1.2-dev \
229 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500230 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500231 python \
232 python3 \
233 socat \
234 subversion \
235 texinfo \
236 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500237 wget \
238 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100239
Alanny Lopez27af3a02017-05-26 10:49:06 -0500240 # Set the locale
241 RUN locale-gen en_US.UTF-8
242 ENV LANG en_US.UTF-8
243 ENV LANGUAGE en_US:en
244 ENV LC_ALL en_US.UTF-8
245
Patrick Williams384d7412020-11-06 16:15:41 -0600246 RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
247 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100248
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500249 USER ${USER}
250 ENV HOME ${HOME}
251 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100252EOF
253)
254fi
255
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500256# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100257export PROXY_HOST=${http_proxy/#http*:\/\/}
258export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
259export PROXY_PORT=${http_proxy/#http*:\/\/*:}
260
Patrick Williams384d7412020-11-06 16:15:41 -0600261mkdir -p "${WORKSPACE}"
Chris Smart02651712015-11-11 11:09:00 +1100262
Andrew Geissler215e43c2019-04-23 10:57:48 -0500263# Determine command for bitbake image build
Patrick Williams384d7412020-11-06 16:15:41 -0600264if [ "$no_tar" = "false" ]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500265 bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball"
Andrew Geissler215e43c2019-04-23 10:57:48 -0500266fi
267
Chris Smart01d2b962015-11-11 18:05:30 +1100268cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100269#!/bin/bash
270
Joel Stanley38c9d142016-02-16 12:31:55 +1030271set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100272
Alanny Lopez723fea62017-09-12 11:22:17 -0500273# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600274cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100275
276# Set up proxies
277export ftp_proxy=${http_proxy}
278export http_proxy=${http_proxy}
279export https_proxy=${http_proxy}
280
Chris Smart01d2b962015-11-11 18:05:30 +1100281mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100282
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500283# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100284if [[ -n "${http_proxy}" ]]; then
285
Chris Smartd30c5902016-03-01 15:00:54 +1100286 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500287 #!/bin/bash
288 # \$1 = hostname, \$2 = port
289 PROXY=${PROXY_HOST}
290 PROXY_PORT=${PROXY_PORT}
291 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100292EOF_GIT
293
Chris Smart01d2b962015-11-11 18:05:30 +1100294 chmod a+x ${WORKSPACE}/bin/git-proxy
295 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100296
Lei YUa76d7ce2020-05-11 15:20:56 +0800297 lock=${HOME}/build-setup.lock
298 flock \${lock} git config --global core.gitProxy ${WORKSPACE}/bin/git-proxy
299 flock \${lock} git config --global http.proxy ${http_proxy}
Chris Smart02651712015-11-11 11:09:00 +1100300
Lei YUa76d7ce2020-05-11 15:20:56 +0800301 flock \${lock} mkdir -p ~/.subversion
302 flock \${lock} cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500303 [global]
304 http-proxy-host = ${PROXY_HOST}
305 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100306EOF_SVN
Lei YU58cb3ad2020-04-30 13:04:58 +0800307
Lei YUa76d7ce2020-05-11 15:20:56 +0800308 flock \${lock} cat > ~/.wgetrc << EOF_WGETRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800309 https_proxy = ${http_proxy}
310 http_proxy = ${http_proxy}
311 use_proxy = on
312EOF_WGETRC
313
Lei YUa76d7ce2020-05-11 15:20:56 +0800314 flock \${lock} cat > ~/.curlrc << EOF_CURLRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800315 proxy = ${PROXY_HOST}:${PROXY_PORT}
316EOF_CURLRC
Chris Smart02651712015-11-11 11:09:00 +1100317fi
318
319# Source our build env
320${BITBAKE_CMD}
321
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500322if [[ -z "${MACHINE}" ]]; then
323 echo "MACHINE is not configured for ${target}"
Brad Bishop91a200b2019-08-22 14:24:33 -0400324 exit 1
Michael Shepos2de03e92018-11-07 15:54:56 -0600325fi
326
Brad Bishop91a200b2019-08-22 14:24:33 -0400327export MACHINE="${MACHINE}"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500328if [[ -z "${DISTRO}" ]]; then
329 echo "DISTRO is not configured for ${target} so will use default"
330 unset DISTRO
331else
332 export DISTRO="${DISTRO}"
333fi
Brad Bishop91a200b2019-08-22 14:24:33 -0400334
Andrew Geisslerf87a7bc2021-01-29 09:28:40 -0600335# bitbake requires SDKMACHINE be x86
336export SDKMACHINE=x86_64
337
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500338# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100339cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100340BB_NUMBER_THREADS = "$(nproc)"
341PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100342INHERIT += "rm_work"
343BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600344DL_DIR="${ssc_dir}/bitbake_downloads"
345SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100346USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500347INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600348TMPDIR="${build_dir}"
Lei YU237bd082020-09-22 11:15:08 +0800349${ENV_LOCAL_CONF}
Chris Smart02651712015-11-11 11:09:00 +1100350EOF_CONF
351
352# Kick off a build
Michael Shepos33aeca42019-06-13 02:36:17 -0500353if [[ -n "${nice_priority}" ]]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500354 nice -${nice_priority} bitbake ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500355else
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500356 bitbake ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500357fi
Chris Smart02651712015-11-11 11:09:00 +1100358
Alanny Lopez1246b032018-02-24 23:34:55 -0600359# Copy internal build directory into xtrct_path directory
Charles Paul Hoferb249c2c2018-09-12 12:15:13 -0500360if [[ ${xtrct_small_copy_dir} ]]; then
361 mkdir -p ${xtrct_path}/${xtrct_small_copy_dir}
362 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir}
363else
364 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
365fi
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500366
367if [[ 0 -ne $? ]]; then
368 echo "Received a non-zero exit code from timeout"
369 exit 1
370fi
371
Chris Smart02651712015-11-11 11:09:00 +1100372EOF_SCRIPT
373
Patrick Williams384d7412020-11-06 16:15:41 -0600374chmod a+x "${WORKSPACE}/build.sh"
Chris Smart02651712015-11-11 11:09:00 +1100375
Alanny Lopez51186882017-08-01 16:14:41 -0500376# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600377img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500378
379# Build the Docker image
Patrick Williams384d7412020-11-06 16:15:41 -0600380docker build -t "${img_name}" - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500381
Michael Shepos3939e952019-01-16 16:00:35 -0600382# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
383mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
384mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
Lei YUde2a3202020-04-28 11:34:23 +0800385mount_workspace_dir="-v ""${WORKSPACE}"":""${WORKSPACE}"" "
Michael Shepos3939e952019-01-16 16:00:35 -0600386if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
387mount_obmc_dir=""
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500388fi
Michael Shepos3939e952019-01-16 16:00:35 -0600389if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
390mount_ssc_dir=""
391fi
Lei YUde2a3202020-04-28 11:34:23 +0800392if [[ "${WORKSPACE}" = "${HOME}/"* || "${WORKSPACE}" = "${HOME}" ]];then
393mount_workspace_dir=""
394fi
Michael Shepos3939e952019-01-16 16:00:35 -0600395
396# Run the Docker container, execute the build.sh script
Patrick Williams384d7412020-11-06 16:15:41 -0600397# shellcheck disable=SC2086 # mount commands word-split purposefully
Michael Shepos3939e952019-01-16 16:00:35 -0600398docker run \
399--cap-add=sys_admin \
Michael Shepos33aeca42019-06-13 02:36:17 -0500400--cap-add=sys_nice \
Michael Shepos3939e952019-01-16 16:00:35 -0600401--net=host \
402--rm=true \
Patrick Williams384d7412020-11-06 16:15:41 -0600403-e WORKSPACE="${WORKSPACE}" \
Michael Shepos3939e952019-01-16 16:00:35 -0600404-w "${HOME}" \
Patrick Williams384d7412020-11-06 16:15:41 -0600405-v "${HOME}:${HOME}" \
Michael Shepos3939e952019-01-16 16:00:35 -0600406${mount_obmc_dir} \
407${mount_ssc_dir} \
Lei YUde2a3202020-04-28 11:34:23 +0800408${mount_workspace_dir} \
Michael Shepos3939e952019-01-16 16:00:35 -0600409--cpus="$num_cpu" \
Ed Tanous3af51682021-01-28 13:57:00 -0800410"${img_name}" \
Patrick Williams384d7412020-11-06 16:15:41 -0600411"${WORKSPACE}/build.sh"
Chris Smart02651712015-11-11 11:09:00 +1100412
Alanny Lopezd32d3322017-07-18 15:21:39 -0500413# To maintain function of resources that used an older path, add a link
Patrick Williams384d7412020-11-06 16:15:41 -0600414ln -sf "${xtrct_path}/deploy" "${WORKSPACE}/deploy"
Alanny Lopezd32d3322017-07-18 15:21:39 -0500415
Chris Smart02651712015-11-11 11:09:00 +1100416# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500417echo "Build completed, $(date)"