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