Alanny Lopez | 56fc36a | 2017-07-27 13:55:44 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 2 | ############################################################################### |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 3 | # |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 4 | # This build script is for running the OpenBMC builds as Docker containers. |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 5 | # |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 6 | ############################################################################### |
| 7 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 8 | # 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 Geissler | dc1e702 | 2018-03-26 07:54:48 -0700 | [diff] [blame] | 16 | # num_cpu Number of cpu's to give bitbake, default is total amount |
| 17 | # in system |
Lei YU | 237bd08 | 2020-09-22 11:15:08 +0800 | [diff] [blame] | 18 | # UBUNTU_MIRROR [optional] The URL of a mirror of Ubuntu to override the |
| 19 | # default ones in /etc/apt/sources.list |
Lei YU | 39587ad | 2020-06-17 19:55:54 +0800 | [diff] [blame] | 20 | # default is empty, and no mirror is used. |
Lei YU | 237bd08 | 2020-09-22 11:15:08 +0800 | [diff] [blame] | 21 | # 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 Geissler | 0edb68c | 2024-06-24 16:01:38 -0400 | [diff] [blame] | 24 | # CONTAINER_ONLY Set to "true" if you only want to build the docker |
| 25 | # container. The bitbake will not occur in this case. |
Andrew Geissler | b80ea07 | 2024-10-07 15:43:34 -0400 | [diff] [blame] | 26 | # DOCKER_REG: <optional, the URL of a docker registry to utilize |
Andrew Geissler | fb45daa | 2024-10-09 12:26:56 -0400 | [diff] [blame] | 27 | # instead of our default (public.ecr.aws/ubuntu) |
| 28 | # (ex. docker.io or public.ecr.aws/docker/library) |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 29 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 30 | # Docker Image Build Variables: |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 31 | # BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 32 | # you'd like to pass into the build. |
| 33 | # Default: "", no options set |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 34 | # build_dir Path where the actual BitBake build occurs inside the |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 35 | # container, path cannot be located on network storage. |
Andrew Geissler | bd11f69 | 2020-09-04 09:36:28 -0500 | [diff] [blame] | 36 | # Default: "$WORKSPACE/build" |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 37 | # distro The distro used as the base image for the build image: |
Andrew Geissler | fb45daa | 2024-10-09 12:26:56 -0400 | [diff] [blame] | 38 | # fedora|ubuntu. Note that if you chose fedora, you will |
| 39 | # need to also update DOCKER_REG to a supported fedora reg. |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 40 | # Default: "ubuntu" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 41 | # img_name The name given to the target build's docker image. |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 42 | # Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 43 | # img_tag The base docker image distro tag: |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 44 | # ubuntu: latest|16.04|14.04|trusty|xenial |
| 45 | # fedora: 23|24|25 |
| 46 | # Default: "latest" |
Patrick Williams | 01dd436 | 2021-02-19 17:45:40 -0600 | [diff] [blame] | 47 | # target The target we aim to build. Any system supported by |
| 48 | # the openbmc/openbmc `setup` script is an option. |
Ed Tanous | d3c516b | 2021-08-19 11:39:09 -0700 | [diff] [blame] | 49 | # repotest is a target to specifically run the CI checks |
Patrick Williams | 1642d13 | 2021-02-19 15:18:20 -0600 | [diff] [blame] | 50 | # Default: "qemuarm" |
Andrew Geissler | 215e43c | 2019-04-23 10:57:48 -0500 | [diff] [blame] | 51 | # no_tar Set to true if you do not want the debug tar built |
| 52 | # Default: "false" |
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 53 | # nice_priority Set nice priority for bitbake command. |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 54 | # Nice: |
| 55 | # Run with an adjusted niceness, which affects process |
| 56 | # scheduling. Nice values range from -20 (most favorable |
| 57 | # to the process) to 19 (least favorable to the process). |
| 58 | # Default: "", nice is not used if nice_priority is not set |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 59 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 60 | # Deployment Variables: |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 61 | # obmc_dir Path of the OpenBMC repo directory used as a reference |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 62 | # for the build inside the container. |
| 63 | # Default: "${WORKSPACE}/openbmc" |
Lei YU | df0e45c | 2020-09-03 11:25:57 +0800 | [diff] [blame] | 64 | # ssc_dir Path of the OpenBMC shared directory that contains the |
| 65 | # downloads dir and the sstate dir. |
| 66 | # Default: "${HOME}" |
Michael Shepos | 10afbb2 | 2019-02-06 13:33:07 -0600 | [diff] [blame] | 67 | # xtrct_small_copy_dir |
| 68 | # Directory within build_dir that should be copied to |
| 69 | # xtrct_path. The directory and all parents up to, but not |
| 70 | # including, build_dir will be copied. For example, if |
| 71 | # build_dir is set to "/tmp/openbmc" and this is set to |
| 72 | # "build/tmp", the directory at xtrct_path will have the |
| 73 | # following directory structure: |
| 74 | # xtrct_path |
| 75 | # | - build |
| 76 | # | - tmp |
| 77 | # ... |
| 78 | # Can also be set to the empty string to copy the entire |
| 79 | # contents of build_dir to xtrct_path. |
| 80 | # Default: "deploy/images". |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 81 | # |
| 82 | ############################################################################### |
Joel Stanley | 4b8b239 | 2016-02-12 15:44:57 +1030 | [diff] [blame] | 83 | # Trace bash processing. Set -e so when a step fails, we fail the build |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 84 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 85 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 86 | # Script Variables: |
| 87 | build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"} |
| 88 | http_proxy=${http_proxy:-} |
| 89 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
Andrew Geissler | dc1e702 | 2018-03-26 07:54:48 -0700 | [diff] [blame] | 90 | num_cpu=${num_cpu:-$(nproc)} |
Lei YU | 39587ad | 2020-06-17 19:55:54 +0800 | [diff] [blame] | 91 | UBUNTU_MIRROR=${UBUNTU_MIRROR:-""} |
Lei YU | 237bd08 | 2020-09-22 11:15:08 +0800 | [diff] [blame] | 92 | ENV_LOCAL_CONF=${ENV_LOCAL_CONF:-""} |
Andrew Geissler | 0edb68c | 2024-06-24 16:01:38 -0400 | [diff] [blame] | 93 | container_only=${CONTAINER_ONLY:-false} |
Andrew Geissler | fb45daa | 2024-10-09 12:26:56 -0400 | [diff] [blame] | 94 | docker_reg=${DOCKER_REG:-"public.ecr.aws/ubuntu"} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 95 | |
| 96 | # Docker Image Build Variables: |
Andrew Geissler | bd11f69 | 2020-09-04 09:36:28 -0500 | [diff] [blame] | 97 | build_dir=${build_dir:-${WORKSPACE}/build} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 98 | distro=${distro:-ubuntu} |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 99 | img_tag=${img_tag:-latest} |
Patrick Williams | 1642d13 | 2021-02-19 15:18:20 -0600 | [diff] [blame] | 100 | target=${target:-qemuarm} |
Andrew Geissler | 215e43c | 2019-04-23 10:57:48 -0500 | [diff] [blame] | 101 | no_tar=${no_tar:-false} |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 102 | nice_priority=${nice_priority:-} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 103 | |
| 104 | # Deployment variables |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 105 | obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc} |
Lei YU | df0e45c | 2020-09-03 11:25:57 +0800 | [diff] [blame] | 106 | ssc_dir=${ssc_dir:-${HOME}} |
Michael Shepos | 10afbb2 | 2019-02-06 13:33:07 -0600 | [diff] [blame] | 107 | xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images} |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 108 | xtrct_path="${obmc_dir}/build/tmp" |
| 109 | xtrct_copy_timeout="300" |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 110 | |
Andrew Geissler | 2eb45d3 | 2019-09-18 21:56:44 -0500 | [diff] [blame] | 111 | bitbake_target="obmc-phosphor-image" |
Chris Smart | c352254 | 2016-02-16 11:59:36 +1100 | [diff] [blame] | 112 | PROXY="" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 113 | |
Lei YU | 39587ad | 2020-06-17 19:55:54 +0800 | [diff] [blame] | 114 | MIRROR="" |
| 115 | if [[ -n "${UBUNTU_MIRROR}" ]]; then |
| 116 | MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \ |
| 117 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 118 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 119 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 120 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list" |
| 121 | fi |
| 122 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 123 | # Timestamp for job |
| 124 | echo "Build started, $(date)" |
| 125 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 126 | # If the obmc_dir directory doesn't exist clone it in |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 127 | if [ ! -d "${obmc_dir}" ]; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 128 | echo "Clone in openbmc master to ${obmc_dir}" |
| 129 | git clone https://github.com/openbmc/openbmc "${obmc_dir}" |
Andrew Geissler | c3c3520 | 2016-08-16 08:47:50 -0500 | [diff] [blame] | 130 | fi |
| 131 | |
Ed Tanous | d3c516b | 2021-08-19 11:39:09 -0700 | [diff] [blame] | 132 | if [[ "$target" = repotest ]]; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 133 | DOCKER_IMAGE_NAME=$(./scripts/build-unit-test-docker) |
| 134 | docker run --cap-add=sys_admin --rm=true \ |
| 135 | --network host \ |
| 136 | --privileged=true \ |
| 137 | -u "$USER" \ |
| 138 | -w "${obmc_dir}" -v "${obmc_dir}:${obmc_dir}" \ |
| 139 | -t "${DOCKER_IMAGE_NAME}" \ |
| 140 | "${obmc_dir}"/meta-phosphor/scripts/run-repotest |
| 141 | exit |
Ed Tanous | d3c516b | 2021-08-19 11:39:09 -0700 | [diff] [blame] | 142 | fi |
| 143 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 144 | # Make and chown the xtrct_path directory to avoid permission errors |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 145 | if [ ! -d "${xtrct_path}" ]; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 146 | mkdir -p "${xtrct_path}" |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 147 | fi |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 148 | chown "${UID}:${GROUPS[0]}" "${xtrct_path}" |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 149 | |
Patrick Williams | 01dd436 | 2021-02-19 17:45:40 -0600 | [diff] [blame] | 150 | # Perform overrides for specific machines as required. |
Adriana Kobylak | 1d2682b | 2021-04-01 18:40:42 +0000 | [diff] [blame] | 151 | DISTRO=${DISTRO:-} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 152 | |
Patrick Williams | 01dd436 | 2021-02-19 17:45:40 -0600 | [diff] [blame] | 153 | # Set build target and BitBake command |
| 154 | MACHINE="${target}" |
Patrick Williams | f88e83f | 2021-02-19 15:15:06 -0600 | [diff] [blame] | 155 | BITBAKE_CMD="source ./setup ${MACHINE} ${build_dir}" |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 156 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 157 | # Configure Docker build |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 158 | if [[ "${distro}" == fedora ]];then |
| 159 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 160 | if [[ -n "${http_proxy}" ]]; then |
| 161 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 162 | fi |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 163 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 164 | Dockerfile=$(cat << EOF |
Andrew Geissler | b80ea07 | 2024-10-07 15:43:34 -0400 | [diff] [blame] | 165 | FROM ${docker_reg}/${distro}:${img_tag} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 166 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 167 | ${PROXY} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 168 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 169 | RUN dnf --refresh install -y \ |
| 170 | bzip2 \ |
| 171 | chrpath \ |
| 172 | cpio \ |
| 173 | diffstat \ |
Andrew Geissler | 36a12ec | 2022-05-04 16:46:56 -0400 | [diff] [blame] | 174 | file \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 175 | findutils \ |
| 176 | gcc \ |
| 177 | gcc-c++ \ |
| 178 | git \ |
Frederic Jacob | 865a091 | 2023-07-07 19:05:53 -0700 | [diff] [blame] | 179 | lz4 \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 180 | make \ |
| 181 | patch \ |
| 182 | perl-bignum \ |
| 183 | perl-Data-Dumper \ |
| 184 | perl-Thread-Queue \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 185 | python3-devel \ |
| 186 | SDL-devel \ |
| 187 | socat \ |
| 188 | subversion \ |
| 189 | tar \ |
| 190 | texinfo \ |
| 191 | wget \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 192 | which \ |
Andrew Geissler | 40c1c9c | 2020-09-04 10:50:36 -0500 | [diff] [blame] | 193 | file \ |
| 194 | hostname \ |
| 195 | rpcgen \ |
| 196 | glibc-langpack-en \ |
Frederic Jacob | 865a091 | 2023-07-07 19:05:53 -0700 | [diff] [blame] | 197 | glibc-locale-source \ |
| 198 | zstd |
Andrew Geissler | 40c1c9c | 2020-09-04 10:50:36 -0500 | [diff] [blame] | 199 | |
| 200 | # Set the locale |
| 201 | ENV LANG=en_US.utf8 |
| 202 | RUN localedef -f UTF-8 -i en_US en_US.UTF-8 |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 203 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 204 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 205 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 206 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 207 | USER ${USER} |
| 208 | ENV HOME ${HOME} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 209 | EOF |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 210 | ) |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 211 | |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame] | 212 | elif [[ "${distro}" == ubuntu ]]; then |
| 213 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 214 | if [[ -n "${http_proxy}" ]]; then |
| 215 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 216 | fi |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 217 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 218 | Dockerfile=$(cat << EOF |
Andrew Geissler | b80ea07 | 2024-10-07 15:43:34 -0400 | [diff] [blame] | 219 | FROM ${docker_reg}/${distro}:${img_tag} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 220 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 221 | ${PROXY} |
Lei YU | 39587ad | 2020-06-17 19:55:54 +0800 | [diff] [blame] | 222 | ${MIRROR} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 223 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 224 | ENV DEBIAN_FRONTEND noninteractive |
Saqib Khan | 7563512 | 2017-03-23 10:57:34 -0500 | [diff] [blame] | 225 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 226 | RUN apt-get update && apt-get install -yy \ |
| 227 | build-essential \ |
| 228 | chrpath \ |
Andrew Geissler | ce47cad | 2021-09-03 08:45:03 -0500 | [diff] [blame] | 229 | cpio \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 230 | debianutils \ |
| 231 | diffstat \ |
Andrew Geissler | 36a12ec | 2022-05-04 16:46:56 -0400 | [diff] [blame] | 232 | file \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 233 | gawk \ |
| 234 | git \ |
Andrew Geissler | ce47cad | 2021-09-03 08:45:03 -0500 | [diff] [blame] | 235 | iputils-ping \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 236 | libdata-dumper-simple-perl \ |
Andrew Geissler | c75b543 | 2024-12-10 15:30:03 -0600 | [diff] [blame] | 237 | lz4 \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 238 | libsdl1.2-dev \ |
| 239 | libthread-queue-any-perl \ |
Alanny Lopez | 27af3a0 | 2017-05-26 10:49:06 -0500 | [diff] [blame] | 240 | locales \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 241 | python3 \ |
| 242 | socat \ |
| 243 | subversion \ |
| 244 | texinfo \ |
Andrew Geissler | b729142 | 2022-12-14 11:48:36 -0600 | [diff] [blame] | 245 | vim \ |
Andrew Geissler | 0a82a76 | 2021-09-03 08:46:24 -0500 | [diff] [blame] | 246 | wget \ |
| 247 | zstd |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 248 | |
Alanny Lopez | 27af3a0 | 2017-05-26 10:49:06 -0500 | [diff] [blame] | 249 | # Set the locale |
| 250 | RUN locale-gen en_US.UTF-8 |
| 251 | ENV LANG en_US.UTF-8 |
| 252 | ENV LANGUAGE en_US:en |
| 253 | ENV LC_ALL en_US.UTF-8 |
| 254 | |
Andrew Geissler | 58ad801 | 2024-05-21 16:25:07 -0500 | [diff] [blame] | 255 | # Latest Ubuntu added a default user (ubuntu), which takes 1000 UID. |
| 256 | # If the user calling this build script happens to also have a UID of 1000 |
| 257 | # then the container no longer will work. Delete the new ubuntu user |
| 258 | # so there is no conflict |
Andrew Geissler | 3adf1a3 | 2024-05-22 12:41:45 -0500 | [diff] [blame] | 259 | RUN if id ubuntu > /dev/null 2>&1; then userdel -r ubuntu > /dev/null 2>&1; fi |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 260 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 261 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 262 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 263 | USER ${USER} |
| 264 | ENV HOME ${HOME} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 265 | EOF |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 266 | ) |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 267 | fi |
| 268 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 269 | # Create the Docker run script |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 270 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 271 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 272 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 273 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 274 | mkdir -p "${WORKSPACE}" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 275 | |
Andrew Geissler | 215e43c | 2019-04-23 10:57:48 -0500 | [diff] [blame] | 276 | # Determine command for bitbake image build |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 277 | if [ "$no_tar" = "false" ]; then |
Andrew Geissler | 2eb45d3 | 2019-09-18 21:56:44 -0500 | [diff] [blame] | 278 | bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball" |
Andrew Geissler | 215e43c | 2019-04-23 10:57:48 -0500 | [diff] [blame] | 279 | fi |
| 280 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 281 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 282 | #!/bin/bash |
| 283 | |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 284 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 285 | |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 286 | # Go into the OpenBMC directory, the build will handle changing directories |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 287 | cd ${obmc_dir} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 288 | |
| 289 | # Set up proxies |
| 290 | export ftp_proxy=${http_proxy} |
| 291 | export http_proxy=${http_proxy} |
| 292 | export https_proxy=${http_proxy} |
| 293 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 294 | mkdir -p ${WORKSPACE}/bin |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 295 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 296 | # Configure proxies for BitBake |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 297 | if [[ -n "${http_proxy}" ]]; then |
| 298 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 299 | cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 300 | #!/bin/bash |
| 301 | # \$1 = hostname, \$2 = port |
| 302 | PROXY=${PROXY_HOST} |
| 303 | PROXY_PORT=${PROXY_PORT} |
| 304 | exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 305 | EOF_GIT |
| 306 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 307 | chmod a+x ${WORKSPACE}/bin/git-proxy |
| 308 | export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 309 | |
Lei YU | a76d7ce | 2020-05-11 15:20:56 +0800 | [diff] [blame] | 310 | lock=${HOME}/build-setup.lock |
| 311 | flock \${lock} git config --global core.gitProxy ${WORKSPACE}/bin/git-proxy |
| 312 | flock \${lock} git config --global http.proxy ${http_proxy} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 313 | |
Lei YU | a76d7ce | 2020-05-11 15:20:56 +0800 | [diff] [blame] | 314 | flock \${lock} mkdir -p ~/.subversion |
| 315 | flock \${lock} cat > ~/.subversion/servers << EOF_SVN |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 316 | [global] |
| 317 | http-proxy-host = ${PROXY_HOST} |
| 318 | http-proxy-port = ${PROXY_PORT} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 319 | EOF_SVN |
Lei YU | 58cb3ad | 2020-04-30 13:04:58 +0800 | [diff] [blame] | 320 | |
Lei YU | a76d7ce | 2020-05-11 15:20:56 +0800 | [diff] [blame] | 321 | flock \${lock} cat > ~/.wgetrc << EOF_WGETRC |
Lei YU | 58cb3ad | 2020-04-30 13:04:58 +0800 | [diff] [blame] | 322 | https_proxy = ${http_proxy} |
| 323 | http_proxy = ${http_proxy} |
| 324 | use_proxy = on |
| 325 | EOF_WGETRC |
| 326 | |
Lei YU | a76d7ce | 2020-05-11 15:20:56 +0800 | [diff] [blame] | 327 | flock \${lock} cat > ~/.curlrc << EOF_CURLRC |
Lei YU | 58cb3ad | 2020-04-30 13:04:58 +0800 | [diff] [blame] | 328 | proxy = ${PROXY_HOST}:${PROXY_PORT} |
| 329 | EOF_CURLRC |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 330 | fi |
| 331 | |
| 332 | # Source our build env |
| 333 | ${BITBAKE_CMD} |
| 334 | |
Andrew Geissler | 8565d2a | 2020-04-20 15:22:14 -0500 | [diff] [blame] | 335 | if [[ -z "${MACHINE}" ]]; then |
| 336 | echo "MACHINE is not configured for ${target}" |
Brad Bishop | 91a200b | 2019-08-22 14:24:33 -0400 | [diff] [blame] | 337 | exit 1 |
Michael Shepos | 2de03e9 | 2018-11-07 15:54:56 -0600 | [diff] [blame] | 338 | fi |
| 339 | |
Brad Bishop | 91a200b | 2019-08-22 14:24:33 -0400 | [diff] [blame] | 340 | export MACHINE="${MACHINE}" |
Andrew Geissler | 8565d2a | 2020-04-20 15:22:14 -0500 | [diff] [blame] | 341 | if [[ -z "${DISTRO}" ]]; then |
| 342 | echo "DISTRO is not configured for ${target} so will use default" |
| 343 | unset DISTRO |
| 344 | else |
| 345 | export DISTRO="${DISTRO}" |
| 346 | fi |
Brad Bishop | 91a200b | 2019-08-22 14:24:33 -0400 | [diff] [blame] | 347 | |
Andrew Geissler | f87a7bc | 2021-01-29 09:28:40 -0600 | [diff] [blame] | 348 | # bitbake requires SDKMACHINE be x86 |
| 349 | export SDKMACHINE=x86_64 |
| 350 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 351 | # Custom BitBake config settings |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 352 | cat >> conf/local.conf << EOF_CONF |
Andrew Geissler | 4b9df8d | 2023-01-06 15:29:39 -0600 | [diff] [blame] | 353 | BB_NUMBER_THREADS = "$num_cpu" |
| 354 | PARALLEL_MAKE = "-j$num_cpu" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 355 | INHERIT += "rm_work" |
| 356 | BB_GENERATE_MIRROR_TARBALLS = "1" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 357 | DL_DIR="${ssc_dir}/bitbake_downloads" |
| 358 | SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 359 | USER_CLASSES += "buildstats" |
Patrick Williams | 120c99e | 2021-08-10 11:05:00 -0500 | [diff] [blame] | 360 | INHERIT:remove = "uninative" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 361 | TMPDIR="${build_dir}" |
Lei YU | 237bd08 | 2020-09-22 11:15:08 +0800 | [diff] [blame] | 362 | ${ENV_LOCAL_CONF} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 363 | EOF_CONF |
| 364 | |
| 365 | # Kick off a build |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 366 | if [[ -n "${nice_priority}" ]]; then |
Patrick Williams | 625f285 | 2022-04-27 21:56:02 -0500 | [diff] [blame] | 367 | nice -${nice_priority} bitbake -k ${BITBAKE_OPTS} ${bitbake_target} |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 368 | else |
Patrick Williams | 625f285 | 2022-04-27 21:56:02 -0500 | [diff] [blame] | 369 | bitbake -k ${BITBAKE_OPTS} ${bitbake_target} |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 370 | fi |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 371 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 372 | # Copy internal build directory into xtrct_path directory |
Charles Paul Hofer | b249c2c | 2018-09-12 12:15:13 -0500 | [diff] [blame] | 373 | if [[ ${xtrct_small_copy_dir} ]]; then |
| 374 | mkdir -p ${xtrct_path}/${xtrct_small_copy_dir} |
| 375 | timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir} |
| 376 | else |
| 377 | timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path} |
| 378 | fi |
Charles Paul Hofer | be8700e | 2018-09-05 09:28:08 -0500 | [diff] [blame] | 379 | |
| 380 | if [[ 0 -ne $? ]]; then |
| 381 | echo "Received a non-zero exit code from timeout" |
| 382 | exit 1 |
| 383 | fi |
| 384 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 385 | EOF_SCRIPT |
| 386 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 387 | chmod a+x "${WORKSPACE}/build.sh" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 388 | |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 389 | # Give the Docker image a name based on the distro,tag,arch,and target |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 390 | img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}} |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 391 | |
Andrew Geissler | d0dabc3 | 2023-04-04 08:09:21 -0600 | [diff] [blame] | 392 | # Ensure appropriate docker build output to see progress and identify |
| 393 | # any issues |
| 394 | export BUILDKIT_PROGRESS=plain |
| 395 | |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 396 | # Build the Docker image |
Frederic Jacob | 35b39a9 | 2023-07-07 19:16:10 -0700 | [diff] [blame] | 397 | docker build --network=host -t "${img_name}" - <<< "${Dockerfile}" |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 398 | |
Andrew Geissler | 0edb68c | 2024-06-24 16:01:38 -0400 | [diff] [blame] | 399 | if [[ "$container_only" = "true" ]]; then |
| 400 | exit 0 |
| 401 | fi |
| 402 | |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 403 | # If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted |
| 404 | mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" " |
| 405 | mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" " |
Lei YU | de2a320 | 2020-04-28 11:34:23 +0800 | [diff] [blame] | 406 | mount_workspace_dir="-v ""${WORKSPACE}"":""${WORKSPACE}"" " |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 407 | if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 408 | mount_obmc_dir="" |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 409 | fi |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 410 | if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 411 | mount_ssc_dir="" |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 412 | fi |
Lei YU | de2a320 | 2020-04-28 11:34:23 +0800 | [diff] [blame] | 413 | if [[ "${WORKSPACE}" = "${HOME}/"* || "${WORKSPACE}" = "${HOME}" ]];then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 414 | mount_workspace_dir="" |
Lei YU | de2a320 | 2020-04-28 11:34:23 +0800 | [diff] [blame] | 415 | fi |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 416 | |
Andrew Geissler | afdc054 | 2023-03-31 15:55:22 -0600 | [diff] [blame] | 417 | # If we are building on a podman based machine, need to have this set in |
| 418 | # the env to allow the home mount to work (no impact on non-podman systems) |
| 419 | export PODMAN_USERNS="keep-id" |
| 420 | |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 421 | # Run the Docker container, execute the build.sh script |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 422 | # shellcheck disable=SC2086 # mount commands word-split purposefully |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 423 | docker run \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 424 | --cap-add=sys_admin \ |
| 425 | --cap-add=sys_nice \ |
| 426 | --net=host \ |
| 427 | --rm=true \ |
| 428 | -e WORKSPACE="${WORKSPACE}" \ |
| 429 | -w "${HOME}" \ |
| 430 | -v "${HOME}:${HOME}" \ |
| 431 | ${mount_obmc_dir} \ |
| 432 | ${mount_ssc_dir} \ |
| 433 | ${mount_workspace_dir} \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 434 | "${img_name}" \ |
| 435 | "${WORKSPACE}/build.sh" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 436 | |
Alanny Lopez | d32d332 | 2017-07-18 15:21:39 -0500 | [diff] [blame] | 437 | # To maintain function of resources that used an older path, add a link |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 438 | ln -sf "${xtrct_path}/deploy" "${WORKSPACE}/deploy" |
Alanny Lopez | d32d332 | 2017-07-18 15:21:39 -0500 | [diff] [blame] | 439 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 440 | # Timestamp for build |
Alanny Lopez | 0e8ad99 | 2017-06-19 15:45:23 -0500 | [diff] [blame] | 441 | echo "Build completed, $(date)" |