blob: fecf0dca74d7b912151c12e5e9725fa8a1500be5 [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.
Andrew Geissler0edb68c2024-06-24 16:01:38 -040024# CONTAINER_ONLY Set to "true" if you only want to build the docker
25# container. The bitbake will not occur in this case.
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050026#
Alanny Lopeze08e8702018-02-24 18:07:13 -060027# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060028# BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options
Alanny Lopeze08e8702018-02-24 18:07:13 -060029# you'd like to pass into the build.
30# Default: "", no options set
Alanny Lopez1246b032018-02-24 23:34:55 -060031# build_dir Path where the actual BitBake build occurs inside the
Alanny Lopeze08e8702018-02-24 18:07:13 -060032# container, path cannot be located on network storage.
Andrew Geisslerbd11f692020-09-04 09:36:28 -050033# Default: "$WORKSPACE/build"
Alanny Lopeze08e8702018-02-24 18:07:13 -060034# distro The distro used as the base image for the build image:
35# fedora|ubuntu
36# Default: "ubuntu"
Alanny Lopez1246b032018-02-24 23:34:55 -060037# img_name The name given to the target build's docker image.
Alanny Lopeze08e8702018-02-24 18:07:13 -060038# Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}"
Alanny Lopez1246b032018-02-24 23:34:55 -060039# img_tag The base docker image distro tag:
Alanny Lopeze08e8702018-02-24 18:07:13 -060040# ubuntu: latest|16.04|14.04|trusty|xenial
41# fedora: 23|24|25
42# Default: "latest"
Patrick Williams01dd4362021-02-19 17:45:40 -060043# target The target we aim to build. Any system supported by
44# the openbmc/openbmc `setup` script is an option.
Ed Tanousd3c516b2021-08-19 11:39:09 -070045# repotest is a target to specifically run the CI checks
Patrick Williams1642d132021-02-19 15:18:20 -060046# Default: "qemuarm"
Andrew Geissler215e43c2019-04-23 10:57:48 -050047# no_tar Set to true if you do not want the debug tar built
48# Default: "false"
Manojkiran Edaa6ebc6e2024-06-17 11:51:45 +053049# nice_priority Set nice priority for bitbake command.
Michael Shepos33aeca42019-06-13 02:36:17 -050050# Nice:
51# Run with an adjusted niceness, which affects process
52# scheduling. Nice values range from -20 (most favorable
53# to the process) to 19 (least favorable to the process).
54# Default: "", nice is not used if nice_priority is not set
Alanny Lopez723fea62017-09-12 11:22:17 -050055#
Alanny Lopeze08e8702018-02-24 18:07:13 -060056# Deployment Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060057# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060058# for the build inside the container.
59# Default: "${WORKSPACE}/openbmc"
Lei YUdf0e45c2020-09-03 11:25:57 +080060# ssc_dir Path of the OpenBMC shared directory that contains the
61# downloads dir and the sstate dir.
62# Default: "${HOME}"
Michael Shepos10afbb22019-02-06 13:33:07 -060063# xtrct_small_copy_dir
64# Directory within build_dir that should be copied to
65# xtrct_path. The directory and all parents up to, but not
66# including, build_dir will be copied. For example, if
67# build_dir is set to "/tmp/openbmc" and this is set to
68# "build/tmp", the directory at xtrct_path will have the
69# following directory structure:
70# xtrct_path
71# | - build
72# | - tmp
73# ...
74# Can also be set to the empty string to copy the entire
75# contents of build_dir to xtrct_path.
76# Default: "deploy/images".
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050077#
78###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103079# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103080set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110081
Alanny Lopez46967702018-02-25 00:29:14 -060082# Script Variables:
83build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
84http_proxy=${http_proxy:-}
85WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070086num_cpu=${num_cpu:-$(nproc)}
Lei YU39587ad2020-06-17 19:55:54 +080087UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
Lei YU237bd082020-09-22 11:15:08 +080088ENV_LOCAL_CONF=${ENV_LOCAL_CONF:-""}
Andrew Geissler0edb68c2024-06-24 16:01:38 -040089container_only=${CONTAINER_ONLY:-false}
Alanny Lopez46967702018-02-25 00:29:14 -060090
91# Docker Image Build Variables:
Andrew Geisslerbd11f692020-09-04 09:36:28 -050092build_dir=${build_dir:-${WORKSPACE}/build}
Chris Smart02651712015-11-11 11:09:00 +110093distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060094img_tag=${img_tag:-latest}
Patrick Williams1642d132021-02-19 15:18:20 -060095target=${target:-qemuarm}
Andrew Geissler215e43c2019-04-23 10:57:48 -050096no_tar=${no_tar:-false}
Michael Shepos33aeca42019-06-13 02:36:17 -050097nice_priority=${nice_priority:-}
Alanny Lopez46967702018-02-25 00:29:14 -060098
99# Deployment variables
Alanny Lopez46967702018-02-25 00:29:14 -0600100obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
Lei YUdf0e45c2020-09-03 11:25:57 +0800101ssc_dir=${ssc_dir:-${HOME}}
Michael Shepos10afbb22019-02-06 13:33:07 -0600102xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images}
Michael Shepos3939e952019-01-16 16:00:35 -0600103xtrct_path="${obmc_dir}/build/tmp"
104xtrct_copy_timeout="300"
Alanny Lopez46967702018-02-25 00:29:14 -0600105
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500106bitbake_target="obmc-phosphor-image"
Chris Smartc3522542016-02-16 11:59:36 +1100107PROXY=""
Chris Smart02651712015-11-11 11:09:00 +1100108
Lei YU39587ad2020-06-17 19:55:54 +0800109MIRROR=""
110if [[ -n "${UBUNTU_MIRROR}" ]]; then
111 MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
112 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
113 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
114 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
115 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
116fi
117
Alanny Lopezccc650e2017-04-24 15:14:20 -0500118# Determine the architecture
119ARCH=$(uname -m)
120
121# Determine the prefix of the Dockerfile's base image
122case ${ARCH} in
Patrick Williams476a7e92022-12-06 09:52:53 -0600123 "ppc64le")
124 DOCKER_BASE="ppc64le/"
125 ;;
126 "x86_64")
127 DOCKER_BASE=""
128 ;;
129 "aarch64")
130 DOCKER_BASE="arm64v8/"
131 ;;
132 *)
133 echo "Unsupported system architecture(${ARCH}) found for docker image"
134 exit 1
Alanny Lopezccc650e2017-04-24 15:14:20 -0500135esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500136
Chris Smart02651712015-11-11 11:09:00 +1100137# Timestamp for job
138echo "Build started, $(date)"
139
Alanny Lopez1246b032018-02-24 23:34:55 -0600140# If the obmc_dir directory doesn't exist clone it in
Patrick Williams384d7412020-11-06 16:15:41 -0600141if [ ! -d "${obmc_dir}" ]; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600142 echo "Clone in openbmc master to ${obmc_dir}"
143 git clone https://github.com/openbmc/openbmc "${obmc_dir}"
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500144fi
145
Ed Tanousd3c516b2021-08-19 11:39:09 -0700146if [[ "$target" = repotest ]]; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600147 DOCKER_IMAGE_NAME=$(./scripts/build-unit-test-docker)
148 docker run --cap-add=sys_admin --rm=true \
149 --network host \
150 --privileged=true \
151 -u "$USER" \
152 -w "${obmc_dir}" -v "${obmc_dir}:${obmc_dir}" \
153 -t "${DOCKER_IMAGE_NAME}" \
154 "${obmc_dir}"/meta-phosphor/scripts/run-repotest
155 exit
Ed Tanousd3c516b2021-08-19 11:39:09 -0700156fi
157
Alanny Lopez1246b032018-02-24 23:34:55 -0600158# Make and chown the xtrct_path directory to avoid permission errors
Patrick Williams384d7412020-11-06 16:15:41 -0600159if [ ! -d "${xtrct_path}" ]; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600160 mkdir -p "${xtrct_path}"
Alanny Lopez723fea62017-09-12 11:22:17 -0500161fi
Patrick Williams384d7412020-11-06 16:15:41 -0600162chown "${UID}:${GROUPS[0]}" "${xtrct_path}"
Alanny Lopez723fea62017-09-12 11:22:17 -0500163
Patrick Williams01dd4362021-02-19 17:45:40 -0600164# Perform overrides for specific machines as required.
Adriana Kobylak1d2682b2021-04-01 18:40:42 +0000165DISTRO=${DISTRO:-}
Chris Smart02651712015-11-11 11:09:00 +1100166
Patrick Williams01dd4362021-02-19 17:45:40 -0600167# Set build target and BitBake command
168MACHINE="${target}"
Patrick Williamsf88e83f2021-02-19 15:15:06 -0600169BITBAKE_CMD="source ./setup ${MACHINE} ${build_dir}"
Brad Bishop7161a172018-10-05 16:48:06 -0400170
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500171# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100172if [[ "${distro}" == fedora ]];then
173
Patrick Williams476a7e92022-12-06 09:52:53 -0600174 if [[ -n "${http_proxy}" ]]; then
175 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
176 fi
Chris Smart02651712015-11-11 11:09:00 +1100177
Patrick Williams476a7e92022-12-06 09:52:53 -0600178 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600179 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100180
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500181 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100182
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500183 RUN dnf --refresh install -y \
184 bzip2 \
185 chrpath \
186 cpio \
187 diffstat \
Andrew Geissler36a12ec2022-05-04 16:46:56 -0400188 file \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500189 findutils \
190 gcc \
191 gcc-c++ \
192 git \
Frederic Jacob865a0912023-07-07 19:05:53 -0700193 lz4 \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500194 make \
195 patch \
196 perl-bignum \
197 perl-Data-Dumper \
198 perl-Thread-Queue \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500199 python3-devel \
200 SDL-devel \
201 socat \
202 subversion \
203 tar \
204 texinfo \
205 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500206 which \
Andrew Geissler40c1c9c2020-09-04 10:50:36 -0500207 file \
208 hostname \
209 rpcgen \
210 glibc-langpack-en \
Frederic Jacob865a0912023-07-07 19:05:53 -0700211 glibc-locale-source \
212 zstd
Andrew Geissler40c1c9c2020-09-04 10:50:36 -0500213
214 # Set the locale
215 ENV LANG=en_US.utf8
216 RUN localedef -f UTF-8 -i en_US en_US.UTF-8
Chris Smart02651712015-11-11 11:09:00 +1100217
Patrick Williams384d7412020-11-06 16:15:41 -0600218 RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
219 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100220
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500221 USER ${USER}
222 ENV HOME ${HOME}
Chris Smart02651712015-11-11 11:09:00 +1100223EOF
Patrick Williams476a7e92022-12-06 09:52:53 -0600224 )
Chris Smart02651712015-11-11 11:09:00 +1100225
Alanny Lopezccc650e2017-04-24 15:14:20 -0500226elif [[ "${distro}" == ubuntu ]]; then
227
Patrick Williams476a7e92022-12-06 09:52:53 -0600228 if [[ -n "${http_proxy}" ]]; then
229 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
230 fi
Chris Smart02651712015-11-11 11:09:00 +1100231
Patrick Williams476a7e92022-12-06 09:52:53 -0600232 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600233 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100234
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500235 ${PROXY}
Lei YU39587ad2020-06-17 19:55:54 +0800236 ${MIRROR}
Chris Smart02651712015-11-11 11:09:00 +1100237
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500238 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500239
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500240 RUN apt-get update && apt-get install -yy \
241 build-essential \
242 chrpath \
Andrew Geisslerce47cad2021-09-03 08:45:03 -0500243 cpio \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500244 debianutils \
245 diffstat \
Andrew Geissler36a12ec2022-05-04 16:46:56 -0400246 file \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500247 gawk \
248 git \
Andrew Geisslerce47cad2021-09-03 08:45:03 -0500249 iputils-ping \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500250 libdata-dumper-simple-perl \
Andrew Geissler0a82a762021-09-03 08:46:24 -0500251 liblz4-tool \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500252 libsdl1.2-dev \
253 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500254 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500255 python3 \
256 socat \
257 subversion \
258 texinfo \
Andrew Geisslerb7291422022-12-14 11:48:36 -0600259 vim \
Andrew Geissler0a82a762021-09-03 08:46:24 -0500260 wget \
261 zstd
Chris Smart02651712015-11-11 11:09:00 +1100262
Alanny Lopez27af3a02017-05-26 10:49:06 -0500263 # Set the locale
264 RUN locale-gen en_US.UTF-8
265 ENV LANG en_US.UTF-8
266 ENV LANGUAGE en_US:en
267 ENV LC_ALL en_US.UTF-8
268
Andrew Geissler58ad8012024-05-21 16:25:07 -0500269 # Latest Ubuntu added a default user (ubuntu), which takes 1000 UID.
270 # If the user calling this build script happens to also have a UID of 1000
271 # then the container no longer will work. Delete the new ubuntu user
272 # so there is no conflict
Andrew Geissler3adf1a32024-05-22 12:41:45 -0500273 RUN if id ubuntu > /dev/null 2>&1; then userdel -r ubuntu > /dev/null 2>&1; fi
Patrick Williams384d7412020-11-06 16:15:41 -0600274 RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
275 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100276
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500277 USER ${USER}
278 ENV HOME ${HOME}
Chris Smart02651712015-11-11 11:09:00 +1100279EOF
Patrick Williams476a7e92022-12-06 09:52:53 -0600280 )
Chris Smart02651712015-11-11 11:09:00 +1100281fi
282
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500283# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100284export PROXY_HOST=${http_proxy/#http*:\/\/}
285export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
286export PROXY_PORT=${http_proxy/#http*:\/\/*:}
287
Patrick Williams384d7412020-11-06 16:15:41 -0600288mkdir -p "${WORKSPACE}"
Chris Smart02651712015-11-11 11:09:00 +1100289
Andrew Geissler215e43c2019-04-23 10:57:48 -0500290# Determine command for bitbake image build
Patrick Williams384d7412020-11-06 16:15:41 -0600291if [ "$no_tar" = "false" ]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500292 bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball"
Andrew Geissler215e43c2019-04-23 10:57:48 -0500293fi
294
Chris Smart01d2b962015-11-11 18:05:30 +1100295cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100296#!/bin/bash
297
Joel Stanley38c9d142016-02-16 12:31:55 +1030298set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100299
Alanny Lopez723fea62017-09-12 11:22:17 -0500300# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600301cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100302
303# Set up proxies
304export ftp_proxy=${http_proxy}
305export http_proxy=${http_proxy}
306export https_proxy=${http_proxy}
307
Chris Smart01d2b962015-11-11 18:05:30 +1100308mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100309
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500310# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100311if [[ -n "${http_proxy}" ]]; then
312
Chris Smartd30c5902016-03-01 15:00:54 +1100313 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500314 #!/bin/bash
315 # \$1 = hostname, \$2 = port
316 PROXY=${PROXY_HOST}
317 PROXY_PORT=${PROXY_PORT}
318 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100319EOF_GIT
320
Chris Smart01d2b962015-11-11 18:05:30 +1100321 chmod a+x ${WORKSPACE}/bin/git-proxy
322 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100323
Lei YUa76d7ce2020-05-11 15:20:56 +0800324 lock=${HOME}/build-setup.lock
325 flock \${lock} git config --global core.gitProxy ${WORKSPACE}/bin/git-proxy
326 flock \${lock} git config --global http.proxy ${http_proxy}
Chris Smart02651712015-11-11 11:09:00 +1100327
Lei YUa76d7ce2020-05-11 15:20:56 +0800328 flock \${lock} mkdir -p ~/.subversion
329 flock \${lock} cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500330 [global]
331 http-proxy-host = ${PROXY_HOST}
332 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100333EOF_SVN
Lei YU58cb3ad2020-04-30 13:04:58 +0800334
Lei YUa76d7ce2020-05-11 15:20:56 +0800335 flock \${lock} cat > ~/.wgetrc << EOF_WGETRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800336 https_proxy = ${http_proxy}
337 http_proxy = ${http_proxy}
338 use_proxy = on
339EOF_WGETRC
340
Lei YUa76d7ce2020-05-11 15:20:56 +0800341 flock \${lock} cat > ~/.curlrc << EOF_CURLRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800342 proxy = ${PROXY_HOST}:${PROXY_PORT}
343EOF_CURLRC
Chris Smart02651712015-11-11 11:09:00 +1100344fi
345
346# Source our build env
347${BITBAKE_CMD}
348
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500349if [[ -z "${MACHINE}" ]]; then
350 echo "MACHINE is not configured for ${target}"
Brad Bishop91a200b2019-08-22 14:24:33 -0400351 exit 1
Michael Shepos2de03e92018-11-07 15:54:56 -0600352fi
353
Brad Bishop91a200b2019-08-22 14:24:33 -0400354export MACHINE="${MACHINE}"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500355if [[ -z "${DISTRO}" ]]; then
356 echo "DISTRO is not configured for ${target} so will use default"
357 unset DISTRO
358else
359 export DISTRO="${DISTRO}"
360fi
Brad Bishop91a200b2019-08-22 14:24:33 -0400361
Andrew Geisslerf87a7bc2021-01-29 09:28:40 -0600362# bitbake requires SDKMACHINE be x86
363export SDKMACHINE=x86_64
364
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500365# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100366cat >> conf/local.conf << EOF_CONF
Andrew Geissler4b9df8d2023-01-06 15:29:39 -0600367BB_NUMBER_THREADS = "$num_cpu"
368PARALLEL_MAKE = "-j$num_cpu"
Chris Smart02651712015-11-11 11:09:00 +1100369INHERIT += "rm_work"
370BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600371DL_DIR="${ssc_dir}/bitbake_downloads"
372SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100373USER_CLASSES += "buildstats"
Patrick Williams120c99e2021-08-10 11:05:00 -0500374INHERIT:remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600375TMPDIR="${build_dir}"
Lei YU237bd082020-09-22 11:15:08 +0800376${ENV_LOCAL_CONF}
Chris Smart02651712015-11-11 11:09:00 +1100377EOF_CONF
378
379# Kick off a build
Michael Shepos33aeca42019-06-13 02:36:17 -0500380if [[ -n "${nice_priority}" ]]; then
Patrick Williams625f2852022-04-27 21:56:02 -0500381 nice -${nice_priority} bitbake -k ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500382else
Patrick Williams625f2852022-04-27 21:56:02 -0500383 bitbake -k ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500384fi
Chris Smart02651712015-11-11 11:09:00 +1100385
Alanny Lopez1246b032018-02-24 23:34:55 -0600386# Copy internal build directory into xtrct_path directory
Charles Paul Hoferb249c2c2018-09-12 12:15:13 -0500387if [[ ${xtrct_small_copy_dir} ]]; then
388 mkdir -p ${xtrct_path}/${xtrct_small_copy_dir}
389 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir}
390else
391 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
392fi
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500393
394if [[ 0 -ne $? ]]; then
395 echo "Received a non-zero exit code from timeout"
396 exit 1
397fi
398
Chris Smart02651712015-11-11 11:09:00 +1100399EOF_SCRIPT
400
Patrick Williams384d7412020-11-06 16:15:41 -0600401chmod a+x "${WORKSPACE}/build.sh"
Chris Smart02651712015-11-11 11:09:00 +1100402
Alanny Lopez51186882017-08-01 16:14:41 -0500403# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600404img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500405
Andrew Geisslerd0dabc32023-04-04 08:09:21 -0600406# Ensure appropriate docker build output to see progress and identify
407# any issues
408export BUILDKIT_PROGRESS=plain
409
Alanny Lopez51186882017-08-01 16:14:41 -0500410# Build the Docker image
Frederic Jacob35b39a92023-07-07 19:16:10 -0700411docker build --network=host -t "${img_name}" - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500412
Andrew Geissler0edb68c2024-06-24 16:01:38 -0400413if [[ "$container_only" = "true" ]]; then
414 exit 0
415fi
416
Michael Shepos3939e952019-01-16 16:00:35 -0600417# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
418mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
419mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
Lei YUde2a3202020-04-28 11:34:23 +0800420mount_workspace_dir="-v ""${WORKSPACE}"":""${WORKSPACE}"" "
Michael Shepos3939e952019-01-16 16:00:35 -0600421if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
Patrick Williams476a7e92022-12-06 09:52:53 -0600422 mount_obmc_dir=""
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500423fi
Michael Shepos3939e952019-01-16 16:00:35 -0600424if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
Patrick Williams476a7e92022-12-06 09:52:53 -0600425 mount_ssc_dir=""
Michael Shepos3939e952019-01-16 16:00:35 -0600426fi
Lei YUde2a3202020-04-28 11:34:23 +0800427if [[ "${WORKSPACE}" = "${HOME}/"* || "${WORKSPACE}" = "${HOME}" ]];then
Patrick Williams476a7e92022-12-06 09:52:53 -0600428 mount_workspace_dir=""
Lei YUde2a3202020-04-28 11:34:23 +0800429fi
Michael Shepos3939e952019-01-16 16:00:35 -0600430
Andrew Geisslerafdc0542023-03-31 15:55:22 -0600431# If we are building on a podman based machine, need to have this set in
432# the env to allow the home mount to work (no impact on non-podman systems)
433export PODMAN_USERNS="keep-id"
434
Michael Shepos3939e952019-01-16 16:00:35 -0600435# Run the Docker container, execute the build.sh script
Patrick Williams384d7412020-11-06 16:15:41 -0600436# shellcheck disable=SC2086 # mount commands word-split purposefully
Michael Shepos3939e952019-01-16 16:00:35 -0600437docker run \
Patrick Williams476a7e92022-12-06 09:52:53 -0600438 --cap-add=sys_admin \
439 --cap-add=sys_nice \
440 --net=host \
441 --rm=true \
442 -e WORKSPACE="${WORKSPACE}" \
443 -w "${HOME}" \
444 -v "${HOME}:${HOME}" \
445 ${mount_obmc_dir} \
446 ${mount_ssc_dir} \
447 ${mount_workspace_dir} \
Patrick Williams476a7e92022-12-06 09:52:53 -0600448 "${img_name}" \
449 "${WORKSPACE}/build.sh"
Chris Smart02651712015-11-11 11:09:00 +1100450
Alanny Lopezd32d3322017-07-18 15:21:39 -0500451# To maintain function of resources that used an older path, add a link
Patrick Williams384d7412020-11-06 16:15:41 -0600452ln -sf "${xtrct_path}/deploy" "${WORKSPACE}/deploy"
Alanny Lopezd32d3322017-07-18 15:21:39 -0500453
Chris Smart02651712015-11-11 11:09:00 +1100454# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500455echo "Build completed, $(date)"