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 | # |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 4 | # This build script is for running the OpenBMC builds as containers with the |
| 5 | # option of launching the containers with Docker or Kubernetes. |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 6 | # |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 7 | ############################################################################### |
| 8 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 9 | # Script Variables: |
| 10 | # build_scripts_dir The path of the openbmc-build-scripts directory. |
| 11 | # Default: The directory containing this script |
| 12 | # http_proxy The HTTP address of the proxy server to connect to. |
| 13 | # Default: "", proxy is not setup if this is not set |
| 14 | # WORKSPACE Path of the workspace directory where some intermediate |
| 15 | # files and the images will be saved to. |
| 16 | # Default: "~/{RandomNumber}" |
Andrew Geissler | dc1e702 | 2018-03-26 07:54:48 -0700 | [diff] [blame] | 17 | # num_cpu Number of cpu's to give bitbake, default is total amount |
| 18 | # in system |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 19 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 20 | # Docker Image Build Variables: |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 21 | # BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 22 | # you'd like to pass into the build. |
| 23 | # Default: "", no options set |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 24 | # build_dir Path where the actual BitBake build occurs inside the |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 25 | # container, path cannot be located on network storage. |
| 26 | # Default: "/tmp/openbmc" |
| 27 | # distro The distro used as the base image for the build image: |
| 28 | # fedora|ubuntu |
| 29 | # Default: "ubuntu" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 30 | # img_name The name given to the target build's docker image. |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 31 | # Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 32 | # img_tag The base docker image distro tag: |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 33 | # ubuntu: latest|16.04|14.04|trusty|xenial |
| 34 | # fedora: 23|24|25 |
| 35 | # Default: "latest" |
| 36 | # target The target we aim to build: |
Andrew Geissler | dd82072 | 2018-02-20 13:42:58 -0600 | [diff] [blame] | 37 | # evb-ast2500|palmetto|qemu|qemux86-64 |
Ed Tanous | 6dc40d9 | 2018-07-30 11:13:36 -0700 | [diff] [blame] | 38 | # romulus|s2600wf|witherspoon|zaius |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 39 | # Default: "qemu" |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 40 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 41 | # Deployment Variables: |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 42 | # launch ""|job|pod |
| 43 | # Can be left blank to launch the container via Docker |
| 44 | # Job lets you keep a copy of job and container logs on the |
| 45 | # api, can be useful if not using Jenkins as you can run the |
| 46 | # job again via the api without needing this script. |
| 47 | # Pod launches a container which runs to completion without |
| 48 | # saving anything to the api when it completes. |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 49 | # obmc_dir Path of the OpenBMC repo directory used as a reference |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 50 | # for the build inside the container. |
| 51 | # Default: "${WORKSPACE}/openbmc" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 52 | # ssc_dir Path to use as the BitBake shared-state cache directory. |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 53 | # Default: "/home/${USER}" |
Charles Paul Hofer | b249c2c | 2018-09-12 12:15:13 -0500 | [diff] [blame] | 54 | # xtrct_small_copy_dir |
| 55 | # Directory within build_dir that should be copied to |
| 56 | # xtrct_path. The directory and all parents up to, but not |
| 57 | # including, build_dir will be copied. For example, if |
| 58 | # build_dir is set to "/tmp/openbmc" and this is set to |
| 59 | # "build/tmp", the directory at xtrct_path will have the |
| 60 | # following directory structure: |
| 61 | # xtrct_path |
| 62 | # | - build |
| 63 | # | - tmp |
| 64 | # ... |
| 65 | # Can also be set to the empty string to copy the entire |
| 66 | # contents of build_dir to xtrct_path. |
| 67 | # Default: "deploy/images". |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 68 | # xtrct_path Path where the build_dir contents will be copied out to |
| 69 | # when the build completes. |
| 70 | # Default: "${obmc_dir}/build/tmp" |
Charles Paul Hofer | be8700e | 2018-09-05 09:28:08 -0500 | [diff] [blame] | 71 | # xtrct_copy_timeout Timeout (in seconds) for copying the contents of |
| 72 | # build_dir to xtrct_path. |
| 73 | # Default: "300" |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 74 | # |
| 75 | ############################################################################### |
Joel Stanley | 4b8b239 | 2016-02-12 15:44:57 +1030 | [diff] [blame] | 76 | # 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] | 77 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 78 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 79 | # Script Variables: |
| 80 | build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"} |
| 81 | http_proxy=${http_proxy:-} |
| 82 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
Andrew Geissler | dc1e702 | 2018-03-26 07:54:48 -0700 | [diff] [blame] | 83 | num_cpu=${num_cpu:-$(nproc)} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 84 | |
| 85 | # Docker Image Build Variables: |
| 86 | build_dir=${build_dir:-/tmp/openbmc} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 87 | distro=${distro:-ubuntu} |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 88 | img_tag=${img_tag:-latest} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 89 | target=${target:-qemu} |
| 90 | |
| 91 | # Deployment variables |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 92 | launch=${launch:-} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 93 | obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc} |
| 94 | ssc_dir=${ssc_dir:-${HOME}} |
Charles Paul Hofer | b249c2c | 2018-09-12 12:15:13 -0500 | [diff] [blame] | 95 | xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 96 | xtrct_path=${xtrct_path:-${obmc_dir}/build/tmp} |
Charles Paul Hofer | be8700e | 2018-09-05 09:28:08 -0500 | [diff] [blame] | 97 | xtrct_copy_timeout=${xtrct_copy_timeout:-300} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 98 | |
Chris Smart | c352254 | 2016-02-16 11:59:36 +1100 | [diff] [blame] | 99 | PROXY="" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 100 | |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame] | 101 | # Determine the architecture |
| 102 | ARCH=$(uname -m) |
| 103 | |
| 104 | # Determine the prefix of the Dockerfile's base image |
| 105 | case ${ARCH} in |
| 106 | "ppc64le") |
| 107 | DOCKER_BASE="ppc64le/" |
| 108 | ;; |
| 109 | "x86_64") |
| 110 | DOCKER_BASE="" |
| 111 | ;; |
| 112 | *) |
| 113 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 114 | exit 1 |
| 115 | esac |
Andrew Geissler | 11abbbe | 2016-08-14 19:39:47 -0500 | [diff] [blame] | 116 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 117 | # Timestamp for job |
| 118 | echo "Build started, $(date)" |
| 119 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 120 | # If the obmc_dir directory doesn't exist clone it in |
| 121 | if [ ! -d ${obmc_dir} ]; then |
| 122 | echo "Clone in openbmc master to ${obmc_dir}" |
| 123 | git clone https://github.com/openbmc/openbmc ${obmc_dir} |
Andrew Geissler | c3c3520 | 2016-08-16 08:47:50 -0500 | [diff] [blame] | 124 | fi |
| 125 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 126 | # Make and chown the xtrct_path directory to avoid permission errors |
| 127 | if [ ! -d ${xtrct_path} ]; then |
| 128 | mkdir -p ${xtrct_path} |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 129 | fi |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 130 | chown ${UID}:${GROUPS} ${xtrct_path} |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 131 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 132 | # Work out what build target we should be running and set BitBake command |
Michael Shepos | 2de03e9 | 2018-11-07 15:54:56 -0600 | [diff] [blame] | 133 | MACHINE="" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 134 | case ${target} in |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 135 | palmetto) |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 136 | LAYER_DIR="meta-ibm/meta-palmetto" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 137 | ;; |
Joel Stanley | 0e07720 | 2016-06-28 16:42:45 +0930 | [diff] [blame] | 138 | witherspoon) |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 139 | LAYER_DIR="meta-ibm/meta-witherspoon" |
Joel Stanley | 0e07720 | 2016-06-28 16:42:45 +0930 | [diff] [blame] | 140 | ;; |
Joel Stanley | 0e07720 | 2016-06-28 16:42:45 +0930 | [diff] [blame] | 141 | evb-ast2500) |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 142 | LAYER_DIR="meta-evb/meta-evb-aspeed/meta-evb-ast2500" |
Joel Stanley | 0e07720 | 2016-06-28 16:42:45 +0930 | [diff] [blame] | 143 | ;; |
Ed Tanous | 6dc40d9 | 2018-07-30 11:13:36 -0700 | [diff] [blame] | 144 | s2600wf) |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 145 | LAYER_DIR="meta-intel/meta-s2600wf" |
Ed Tanous | 6dc40d9 | 2018-07-30 11:13:36 -0700 | [diff] [blame] | 146 | ;; |
Joel Stanley | 915381f | 2016-11-01 16:58:59 +1030 | [diff] [blame] | 147 | zaius) |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 148 | LAYER_DIR="meta-ingrasys/meta-zaius" |
Joel Stanley | 915381f | 2016-11-01 16:58:59 +1030 | [diff] [blame] | 149 | ;; |
| 150 | romulus) |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 151 | LAYER_DIR="meta-ibm/meta-romulus" |
Joel Stanley | 915381f | 2016-11-01 16:58:59 +1030 | [diff] [blame] | 152 | ;; |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 153 | qemu) |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 154 | LAYER_DIR="meta-phosphor" |
Michael Shepos | 2de03e9 | 2018-11-07 15:54:56 -0600 | [diff] [blame] | 155 | # MACHINE defaults to `qemuarm` in this layer, no change necessary |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 156 | ;; |
Andrew Geissler | dd82072 | 2018-02-20 13:42:58 -0600 | [diff] [blame] | 157 | qemux86-64) |
Michael Shepos | 2de03e9 | 2018-11-07 15:54:56 -0600 | [diff] [blame] | 158 | LAYER_DIR="meta-phosphor" |
| 159 | # MACHINE defaults to `qemuarm` in this layer, change to `qemux86-64` |
| 160 | MACHINE="qemux86-64" |
Andrew Geissler | dd82072 | 2018-02-20 13:42:58 -0600 | [diff] [blame] | 161 | ;; |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 162 | *) |
| 163 | exit 1 |
| 164 | ;; |
| 165 | esac |
| 166 | |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 167 | BITBAKE_CMD="TEMPLATECONF=${LAYER_DIR}/conf source oe-init-build-env" |
| 168 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 169 | # Configure Docker build |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 170 | if [[ "${distro}" == fedora ]];then |
| 171 | |
| 172 | if [[ -n "${http_proxy}" ]]; then |
| 173 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 174 | fi |
| 175 | |
| 176 | Dockerfile=$(cat << EOF |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 177 | FROM ${DOCKER_BASE}${distro}:${img_tag} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 178 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 179 | ${PROXY} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 180 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 181 | # Set the locale |
| 182 | RUN locale-gen en_US.UTF-8 |
| 183 | ENV LANG en_US.UTF-8 |
| 184 | ENV LANGUAGE en_US:en |
| 185 | ENV LC_ALL en_US.UTF-8 |
Saqib Khan | 7563512 | 2017-03-23 10:57:34 -0500 | [diff] [blame] | 186 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 187 | RUN dnf --refresh install -y \ |
| 188 | bzip2 \ |
| 189 | chrpath \ |
| 190 | cpio \ |
| 191 | diffstat \ |
| 192 | findutils \ |
| 193 | gcc \ |
| 194 | gcc-c++ \ |
| 195 | git \ |
| 196 | make \ |
| 197 | patch \ |
| 198 | perl-bignum \ |
| 199 | perl-Data-Dumper \ |
| 200 | perl-Thread-Queue \ |
| 201 | python-devel \ |
| 202 | python3-devel \ |
| 203 | SDL-devel \ |
| 204 | socat \ |
| 205 | subversion \ |
| 206 | tar \ |
| 207 | texinfo \ |
| 208 | wget \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 209 | which \ |
| 210 | iputils-ping |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 211 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 212 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 213 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 214 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 215 | USER ${USER} |
| 216 | ENV HOME ${HOME} |
| 217 | RUN /bin/bash |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 218 | EOF |
| 219 | ) |
| 220 | |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame] | 221 | elif [[ "${distro}" == ubuntu ]]; then |
| 222 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 223 | if [[ -n "${http_proxy}" ]]; then |
| 224 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 225 | fi |
| 226 | |
| 227 | Dockerfile=$(cat << EOF |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 228 | FROM ${DOCKER_BASE}${distro}:${img_tag} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 229 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 230 | ${PROXY} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 231 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 232 | ENV DEBIAN_FRONTEND noninteractive |
Saqib Khan | 7563512 | 2017-03-23 10:57:34 -0500 | [diff] [blame] | 233 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 234 | RUN apt-get update && apt-get install -yy \ |
| 235 | build-essential \ |
| 236 | chrpath \ |
| 237 | debianutils \ |
| 238 | diffstat \ |
| 239 | gawk \ |
| 240 | git \ |
| 241 | libdata-dumper-simple-perl \ |
| 242 | libsdl1.2-dev \ |
| 243 | libthread-queue-any-perl \ |
Alanny Lopez | 27af3a0 | 2017-05-26 10:49:06 -0500 | [diff] [blame] | 244 | locales \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 245 | python \ |
| 246 | python3 \ |
| 247 | socat \ |
| 248 | subversion \ |
| 249 | texinfo \ |
| 250 | cpio \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 251 | wget \ |
| 252 | iputils-ping |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 253 | |
Alanny Lopez | 27af3a0 | 2017-05-26 10:49:06 -0500 | [diff] [blame] | 254 | # Set the locale |
| 255 | RUN locale-gen en_US.UTF-8 |
| 256 | ENV LANG en_US.UTF-8 |
| 257 | ENV LANGUAGE en_US:en |
| 258 | ENV LC_ALL en_US.UTF-8 |
| 259 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 260 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 261 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${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} |
| 265 | RUN /bin/bash |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 266 | EOF |
| 267 | ) |
| 268 | fi |
| 269 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 270 | # Create the Docker run script |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 271 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 272 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 273 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 274 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 275 | mkdir -p ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 276 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 277 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 278 | #!/bin/bash |
| 279 | |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 280 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 281 | |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 282 | # Go into the OpenBMC directory, the build will handle changing directories |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 283 | cd ${obmc_dir} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 284 | |
| 285 | # Set up proxies |
| 286 | export ftp_proxy=${http_proxy} |
| 287 | export http_proxy=${http_proxy} |
| 288 | export https_proxy=${http_proxy} |
| 289 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 290 | mkdir -p ${WORKSPACE}/bin |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 291 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 292 | # Configure proxies for BitBake |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 293 | if [[ -n "${http_proxy}" ]]; then |
| 294 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 295 | cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 296 | #!/bin/bash |
| 297 | # \$1 = hostname, \$2 = port |
| 298 | PROXY=${PROXY_HOST} |
| 299 | PROXY_PORT=${PROXY_PORT} |
| 300 | exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 301 | EOF_GIT |
| 302 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 303 | chmod a+x ${WORKSPACE}/bin/git-proxy |
| 304 | 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] | 305 | git config core.gitProxy git-proxy |
| 306 | |
| 307 | mkdir -p ~/.subversion |
| 308 | |
| 309 | cat > ~/.subversion/servers << EOF_SVN |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 310 | [global] |
| 311 | http-proxy-host = ${PROXY_HOST} |
| 312 | http-proxy-port = ${PROXY_PORT} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 313 | EOF_SVN |
| 314 | fi |
| 315 | |
| 316 | # Source our build env |
| 317 | ${BITBAKE_CMD} |
| 318 | |
Michael Shepos | 2de03e9 | 2018-11-07 15:54:56 -0600 | [diff] [blame] | 319 | # Change MACHINE name when given for build target |
| 320 | if [[ -n "${MACHINE}" ]]; then |
| 321 | sed "s/^MACHINE\ ??=.*/MACHINE\ ??=\ \"${MACHINE}\"/" -i conf/local.conf |
| 322 | fi |
| 323 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 324 | # Custom BitBake config settings |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 325 | cat >> conf/local.conf << EOF_CONF |
Chris Smart | c650c20 | 2015-11-25 15:58:53 +1100 | [diff] [blame] | 326 | BB_NUMBER_THREADS = "$(nproc)" |
| 327 | PARALLEL_MAKE = "-j$(nproc)" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 328 | INHERIT += "rm_work" |
| 329 | BB_GENERATE_MIRROR_TARBALLS = "1" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 330 | DL_DIR="${ssc_dir}/bitbake_downloads" |
| 331 | SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 332 | USER_CLASSES += "buildstats" |
Andrew Geissler | 931ec67 | 2016-08-11 13:10:05 -0500 | [diff] [blame] | 333 | INHERIT_remove = "uninative" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 334 | TMPDIR="${build_dir}" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 335 | EOF_CONF |
| 336 | |
| 337 | # Kick off a build |
Andrew Geissler | 496a6b0 | 2016-10-03 10:04:49 -0500 | [diff] [blame] | 338 | bitbake ${BITBAKE_OPTS} obmc-phosphor-image |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 339 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 340 | # Copy internal build directory into xtrct_path directory |
Charles Paul Hofer | b249c2c | 2018-09-12 12:15:13 -0500 | [diff] [blame] | 341 | if [[ ${xtrct_small_copy_dir} ]]; then |
| 342 | mkdir -p ${xtrct_path}/${xtrct_small_copy_dir} |
| 343 | timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir} |
| 344 | else |
| 345 | timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path} |
| 346 | fi |
Charles Paul Hofer | be8700e | 2018-09-05 09:28:08 -0500 | [diff] [blame] | 347 | |
| 348 | if [[ 0 -ne $? ]]; then |
| 349 | echo "Received a non-zero exit code from timeout" |
| 350 | exit 1 |
| 351 | fi |
| 352 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 353 | EOF_SCRIPT |
| 354 | |
| 355 | chmod a+x ${WORKSPACE}/build.sh |
| 356 | |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 357 | # 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] | 358 | img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}} |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 359 | |
| 360 | # Build the Docker image |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 361 | docker build -t ${img_name} - <<< "${Dockerfile}" |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 362 | |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 363 | # Determine if the build container will be launched with Docker or Kubernetes |
| 364 | if [[ "${launch}" == "" ]]; then |
| 365 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 366 | # If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted |
| 367 | mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" " |
| 368 | mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" " |
| 369 | if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then |
| 370 | mount_obmc_dir="" |
Alanny Lopez | 97a7950 | 2017-04-24 16:19:25 -0500 | [diff] [blame] | 371 | fi |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 372 | if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then |
| 373 | mount_ssc_dir="" |
Alanny Lopez | 97a7950 | 2017-04-24 16:19:25 -0500 | [diff] [blame] | 374 | fi |
| 375 | |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 376 | # Run the Docker container, execute the build.sh script |
| 377 | docker run \ |
| 378 | --cap-add=sys_admin \ |
| 379 | --net=host \ |
| 380 | --rm=true \ |
| 381 | -e WORKSPACE=${WORKSPACE} \ |
| 382 | -w "${HOME}" \ |
| 383 | -v "${HOME}":"${HOME}" \ |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 384 | ${mount_obmc_dir} \ |
| 385 | ${mount_ssc_dir} \ |
Andrew Geissler | dc1e702 | 2018-03-26 07:54:48 -0700 | [diff] [blame] | 386 | --cpus="$num_cpu" \ |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 387 | -t ${img_name} \ |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 388 | ${WORKSPACE}/build.sh |
| 389 | |
| 390 | elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then |
| 391 | |
| 392 | # Source and run the helper script to launch the pod or job |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 393 | . ${build_scripts_dir}/kubernetes/kubernetes-launch.sh OpenBMC-build true true |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 394 | |
| 395 | else |
| 396 | echo "Launch Parameter is invalid" |
| 397 | fi |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 398 | |
Alanny Lopez | d32d332 | 2017-07-18 15:21:39 -0500 | [diff] [blame] | 399 | # To maintain function of resources that used an older path, add a link |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 400 | ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy |
Alanny Lopez | d32d332 | 2017-07-18 15:21:39 -0500 | [diff] [blame] | 401 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 402 | # Timestamp for build |
Alanny Lopez | 0e8ad99 | 2017-06-19 15:45:23 -0500 | [diff] [blame] | 403 | echo "Build completed, $(date)" |