Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 3 | # This build script is for running the Jenkins builds using Docker. |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 4 | # |
| 5 | # It expects a few variables which are part of Jenkins build job matrix: |
| 6 | # target = barreleye|palmetto|qemu |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame^] | 7 | # distro = fedora|ubuntu |
| 8 | # imgtag = tag of the Ubuntu or Fedora image to use (default latest) |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 9 | # obmcdir = <name of OpenBMC src dir> (default openbmc) |
| 10 | # WORKSPACE = <location of base OpenBMC/OpenBMC repo> |
Andrew Geissler | 496a6b0 | 2016-10-03 10:04:49 -0500 | [diff] [blame] | 11 | # BITBAKE_OPTS = <optional, set to "-c populate_sdk" or whatever other |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 12 | # BitBake options you'd like to pass into the build> |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 13 | |
Joel Stanley | 4b8b239 | 2016-02-12 15:44:57 +1030 | [diff] [blame] | 14 | # 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] | 15 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 16 | |
| 17 | # Default variables |
| 18 | target=${target:-qemu} |
| 19 | distro=${distro:-ubuntu} |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame^] | 20 | imgtag=${imgtag:-latest} |
Andrew Geissler | c3c3520 | 2016-08-16 08:47:50 -0500 | [diff] [blame] | 21 | obmcdir=${obmcdir:-openbmc} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 22 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 23 | http_proxy=${http_proxy:-} |
Chris Smart | c352254 | 2016-02-16 11:59:36 +1100 | [diff] [blame] | 24 | PROXY="" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 25 | |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame^] | 26 | # Determine the architecture |
| 27 | ARCH=$(uname -m) |
| 28 | |
| 29 | # Determine the prefix of the Dockerfile's base image |
| 30 | case ${ARCH} in |
| 31 | "ppc64le") |
| 32 | DOCKER_BASE="ppc64le/" |
| 33 | ;; |
| 34 | "x86_64") |
| 35 | DOCKER_BASE="" |
| 36 | ;; |
| 37 | *) |
| 38 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 39 | exit 1 |
| 40 | esac |
Andrew Geissler | 11abbbe | 2016-08-14 19:39:47 -0500 | [diff] [blame] | 41 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 42 | # Timestamp for job |
| 43 | echo "Build started, $(date)" |
| 44 | |
Andrew Geissler | c3c3520 | 2016-08-16 08:47:50 -0500 | [diff] [blame] | 45 | # If there's no openbmc dir in WORKSPACE then just clone in master |
| 46 | if [ ! -d ${WORKSPACE}/${obmcdir} ]; then |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 47 | echo "Clone in openbmc master to ${WORKSPACE}/${obmcdir}" |
| 48 | git clone https://github.com/openbmc/openbmc ${WORKSPACE}/${obmcdir} |
Andrew Geissler | c3c3520 | 2016-08-16 08:47:50 -0500 | [diff] [blame] | 49 | fi |
| 50 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 51 | # Work out what build target we should be running and set BitBake command |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 52 | case ${target} in |
| 53 | barreleye) |
| 54 | BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env" |
| 55 | ;; |
| 56 | palmetto) |
| 57 | BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env" |
| 58 | ;; |
Joel Stanley | 0e07720 | 2016-06-28 16:42:45 +0930 | [diff] [blame] | 59 | witherspoon) |
| 60 | BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env" |
| 61 | ;; |
| 62 | firestone) |
| 63 | BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env" |
| 64 | ;; |
| 65 | garrison) |
| 66 | BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env" |
| 67 | ;; |
| 68 | evb-ast2500) |
| 69 | BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env" |
| 70 | ;; |
Joel Stanley | 915381f | 2016-11-01 16:58:59 +1030 | [diff] [blame] | 71 | zaius) |
| 72 | BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env" |
| 73 | ;; |
| 74 | romulus) |
| 75 | BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env" |
| 76 | ;; |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 77 | qemu) |
| 78 | BITBAKE_CMD="source openbmc-env" |
| 79 | ;; |
| 80 | *) |
| 81 | exit 1 |
| 82 | ;; |
| 83 | esac |
| 84 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 85 | # Configure Docker build |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 86 | if [[ "${distro}" == fedora ]];then |
| 87 | |
| 88 | if [[ -n "${http_proxy}" ]]; then |
| 89 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 90 | fi |
| 91 | |
| 92 | Dockerfile=$(cat << EOF |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame^] | 93 | FROM ${DOCKER_BASE}${distro}:${imgtag} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 94 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 95 | ${PROXY} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 96 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 97 | # Set the locale |
| 98 | RUN locale-gen en_US.UTF-8 |
| 99 | ENV LANG en_US.UTF-8 |
| 100 | ENV LANGUAGE en_US:en |
| 101 | ENV LC_ALL en_US.UTF-8 |
Saqib Khan | 7563512 | 2017-03-23 10:57:34 -0500 | [diff] [blame] | 102 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 103 | RUN dnf --refresh install -y \ |
| 104 | bzip2 \ |
| 105 | chrpath \ |
| 106 | cpio \ |
| 107 | diffstat \ |
| 108 | findutils \ |
| 109 | gcc \ |
| 110 | gcc-c++ \ |
| 111 | git \ |
| 112 | make \ |
| 113 | patch \ |
| 114 | perl-bignum \ |
| 115 | perl-Data-Dumper \ |
| 116 | perl-Thread-Queue \ |
| 117 | python-devel \ |
| 118 | python3-devel \ |
| 119 | SDL-devel \ |
| 120 | socat \ |
| 121 | subversion \ |
| 122 | tar \ |
| 123 | texinfo \ |
| 124 | wget \ |
| 125 | which |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 126 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 127 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 128 | 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] | 129 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 130 | USER ${USER} |
| 131 | ENV HOME ${HOME} |
| 132 | RUN /bin/bash |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 133 | EOF |
| 134 | ) |
| 135 | |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame^] | 136 | elif [[ "${distro}" == ubuntu ]]; then |
| 137 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 138 | if [[ -n "${http_proxy}" ]]; then |
| 139 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 140 | fi |
| 141 | |
| 142 | Dockerfile=$(cat << EOF |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame^] | 143 | FROM ${DOCKER_BASE}${distro}:${imgtag} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 144 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 145 | ${PROXY} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 146 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 147 | ENV DEBIAN_FRONTEND noninteractive |
Saqib Khan | 7563512 | 2017-03-23 10:57:34 -0500 | [diff] [blame] | 148 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 149 | # Set the locale |
| 150 | RUN locale-gen en_US.UTF-8 |
| 151 | ENV LANG en_US.UTF-8 |
| 152 | ENV LANGUAGE en_US:en |
| 153 | ENV LC_ALL en_US.UTF-8 |
Saqib Khan | 7563512 | 2017-03-23 10:57:34 -0500 | [diff] [blame] | 154 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 155 | RUN apt-get update && apt-get install -yy \ |
| 156 | build-essential \ |
| 157 | chrpath \ |
| 158 | debianutils \ |
| 159 | diffstat \ |
| 160 | gawk \ |
| 161 | git \ |
| 162 | libdata-dumper-simple-perl \ |
| 163 | libsdl1.2-dev \ |
| 164 | libthread-queue-any-perl \ |
| 165 | python \ |
| 166 | python3 \ |
| 167 | socat \ |
| 168 | subversion \ |
| 169 | texinfo \ |
| 170 | cpio \ |
| 171 | wget |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 172 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 173 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 174 | 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] | 175 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 176 | USER ${USER} |
| 177 | ENV HOME ${HOME} |
| 178 | RUN /bin/bash |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 179 | EOF |
| 180 | ) |
| 181 | fi |
| 182 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 183 | # Build the Docker container |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame^] | 184 | docker build -t openbmc/${distro}:${imgtag}-${ARCH} - <<< "${Dockerfile}" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 185 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 186 | # Create the Docker run script |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 187 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 188 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 189 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 190 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 191 | mkdir -p ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 192 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 193 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 194 | #!/bin/bash |
| 195 | |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 196 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 197 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 198 | cd ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 199 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 200 | # Go into the OpenBMC directory (the openbmc script will put us in a build subdir) |
Andrew Geissler | c3c3520 | 2016-08-16 08:47:50 -0500 | [diff] [blame] | 201 | cd ${obmcdir} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 202 | |
| 203 | # Set up proxies |
| 204 | export ftp_proxy=${http_proxy} |
| 205 | export http_proxy=${http_proxy} |
| 206 | export https_proxy=${http_proxy} |
| 207 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 208 | mkdir -p ${WORKSPACE}/bin |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 209 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 210 | # Configure proxies for BitBake |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 211 | if [[ -n "${http_proxy}" ]]; then |
| 212 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 213 | cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 214 | #!/bin/bash |
| 215 | # \$1 = hostname, \$2 = port |
| 216 | PROXY=${PROXY_HOST} |
| 217 | PROXY_PORT=${PROXY_PORT} |
| 218 | exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 219 | EOF_GIT |
| 220 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 221 | chmod a+x ${WORKSPACE}/bin/git-proxy |
| 222 | 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] | 223 | git config core.gitProxy git-proxy |
| 224 | |
| 225 | mkdir -p ~/.subversion |
| 226 | |
| 227 | cat > ~/.subversion/servers << EOF_SVN |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 228 | [global] |
| 229 | http-proxy-host = ${PROXY_HOST} |
| 230 | http-proxy-port = ${PROXY_PORT} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 231 | EOF_SVN |
| 232 | fi |
| 233 | |
| 234 | # Source our build env |
| 235 | ${BITBAKE_CMD} |
| 236 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 237 | # Custom BitBake config settings |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 238 | cat >> conf/local.conf << EOF_CONF |
Chris Smart | c650c20 | 2015-11-25 15:58:53 +1100 | [diff] [blame] | 239 | BB_NUMBER_THREADS = "$(nproc)" |
| 240 | PARALLEL_MAKE = "-j$(nproc)" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 241 | INHERIT += "rm_work" |
| 242 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 243 | DL_DIR="${HOME}/bitbake_downloads" |
Joel Stanley | 1dda089 | 2016-06-06 16:09:56 -0500 | [diff] [blame] | 244 | SSTATE_DIR="${HOME}/bitbake_sharedstatecache" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 245 | USER_CLASSES += "buildstats" |
Andrew Geissler | 931ec67 | 2016-08-11 13:10:05 -0500 | [diff] [blame] | 246 | INHERIT_remove = "uninative" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 247 | EOF_CONF |
| 248 | |
| 249 | # Kick off a build |
Andrew Geissler | 496a6b0 | 2016-10-03 10:04:49 -0500 | [diff] [blame] | 250 | bitbake ${BITBAKE_OPTS} obmc-phosphor-image |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 251 | |
| 252 | EOF_SCRIPT |
| 253 | |
| 254 | chmod a+x ${WORKSPACE}/build.sh |
| 255 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 256 | # Run the Docker container, execute the build script we just built |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 257 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame^] | 258 | -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro}:${imgtag}-${ARCH} ${WORKSPACE}/build.sh |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 259 | |
| 260 | # Create link to images for archiving |
| 261 | ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images |
| 262 | |
| 263 | # Timestamp for build |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 264 | echo "Build completed, $(date)" |