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