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