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