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 | |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 91 | RUN dnf --refresh install -y \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 92 | bzip2 \ |
| 93 | chrpath \ |
| 94 | cpio \ |
| 95 | diffstat \ |
| 96 | findutils \ |
| 97 | gcc \ |
| 98 | gcc-c++ \ |
| 99 | git \ |
| 100 | make \ |
| 101 | patch \ |
| 102 | perl-bignum \ |
| 103 | perl-Data-Dumper \ |
| 104 | perl-Thread-Queue \ |
| 105 | python-devel \ |
Saqib Khan | 362ca85 | 2017-03-21 10:48:46 -0500 | [diff] [blame^] | 106 | python3-devel \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 107 | SDL-devel \ |
| 108 | socat \ |
| 109 | subversion \ |
| 110 | tar \ |
| 111 | texinfo \ |
| 112 | wget \ |
| 113 | which |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 114 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 115 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 116 | 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] | 117 | |
| 118 | USER ${USER} |
| 119 | ENV HOME ${HOME} |
| 120 | RUN /bin/bash |
| 121 | EOF |
| 122 | ) |
| 123 | |
Andrew Geissler | c16868c | 2016-08-23 21:55:13 -0500 | [diff] [blame] | 124 | elif [[ "${distro}" == "ubuntu"* ]]; then |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 125 | if [[ -n "${http_proxy}" ]]; then |
| 126 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 127 | fi |
| 128 | |
| 129 | Dockerfile=$(cat << EOF |
Andrew Geissler | c16868c | 2016-08-23 21:55:13 -0500 | [diff] [blame] | 130 | FROM ${DOCKER_BASE}${distro} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 131 | |
| 132 | ${PROXY} |
| 133 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 134 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 135 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 136 | build-essential \ |
| 137 | chrpath \ |
| 138 | debianutils \ |
| 139 | diffstat \ |
| 140 | gawk \ |
| 141 | git \ |
| 142 | libdata-dumper-simple-perl \ |
| 143 | libsdl1.2-dev \ |
| 144 | libthread-queue-any-perl \ |
| 145 | python \ |
Saqib Khan | 362ca85 | 2017-03-21 10:48:46 -0500 | [diff] [blame^] | 146 | python3 \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 147 | socat \ |
| 148 | subversion \ |
| 149 | texinfo \ |
Andrew Geissler | 11abbbe | 2016-08-14 19:39:47 -0500 | [diff] [blame] | 150 | cpio \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 151 | wget |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 152 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 153 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 154 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 155 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 156 | USER ${USER} |
| 157 | ENV HOME ${HOME} |
| 158 | RUN /bin/bash |
| 159 | EOF |
| 160 | ) |
| 161 | fi |
| 162 | |
| 163 | # Build the docker container |
| 164 | docker build -t openbmc/${distro} - <<< "${Dockerfile}" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 165 | |
| 166 | # Create the docker run script |
| 167 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 168 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 169 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 170 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 171 | mkdir -p ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 172 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 173 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 174 | #!/bin/bash |
| 175 | |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 176 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 177 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 178 | cd ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 179 | |
| 180 | # 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] | 181 | cd ${obmcdir} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 182 | |
| 183 | # Set up proxies |
| 184 | export ftp_proxy=${http_proxy} |
| 185 | export http_proxy=${http_proxy} |
| 186 | export https_proxy=${http_proxy} |
| 187 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 188 | mkdir -p ${WORKSPACE}/bin |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 189 | |
| 190 | # Configure proxies for bitbake |
| 191 | if [[ -n "${http_proxy}" ]]; then |
| 192 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 193 | cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 194 | #!/bin/bash |
| 195 | # \$1 = hostname, \$2 = port |
| 196 | PROXY=${PROXY_HOST} |
| 197 | PROXY_PORT=${PROXY_PORT} |
| 198 | exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT} |
| 199 | EOF_GIT |
| 200 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 201 | chmod a+x ${WORKSPACE}/bin/git-proxy |
| 202 | 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] | 203 | git config core.gitProxy git-proxy |
| 204 | |
| 205 | mkdir -p ~/.subversion |
| 206 | |
| 207 | cat > ~/.subversion/servers << EOF_SVN |
| 208 | [global] |
| 209 | http-proxy-host = ${PROXY_HOST} |
| 210 | http-proxy-port = ${PROXY_PORT} |
| 211 | EOF_SVN |
| 212 | fi |
| 213 | |
| 214 | # Source our build env |
| 215 | ${BITBAKE_CMD} |
| 216 | |
| 217 | # Custom bitbake config settings |
| 218 | cat >> conf/local.conf << EOF_CONF |
Chris Smart | c650c20 | 2015-11-25 15:58:53 +1100 | [diff] [blame] | 219 | BB_NUMBER_THREADS = "$(nproc)" |
| 220 | PARALLEL_MAKE = "-j$(nproc)" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 221 | INHERIT += "rm_work" |
| 222 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 223 | DL_DIR="${HOME}/bitbake_downloads" |
Joel Stanley | 1dda089 | 2016-06-06 16:09:56 -0500 | [diff] [blame] | 224 | SSTATE_DIR="${HOME}/bitbake_sharedstatecache" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 225 | USER_CLASSES += "buildstats" |
Andrew Geissler | 931ec67 | 2016-08-11 13:10:05 -0500 | [diff] [blame] | 226 | INHERIT_remove = "uninative" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 227 | EOF_CONF |
| 228 | |
| 229 | # Kick off a build |
Andrew Geissler | 496a6b0 | 2016-10-03 10:04:49 -0500 | [diff] [blame] | 230 | bitbake ${BITBAKE_OPTS} obmc-phosphor-image |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 231 | |
| 232 | EOF_SCRIPT |
| 233 | |
| 234 | chmod a+x ${WORKSPACE}/build.sh |
| 235 | |
| 236 | # Run the docker container, execute the build script we just built |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 237 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 238 | -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 239 | |
| 240 | # Create link to images for archiving |
| 241 | ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images |
| 242 | |
| 243 | # Timestamp for build |
| 244 | echo "Build completed, $(date)" |
| 245 | |