blob: b3b9b489070e5c0ff1c05d00b6c3ec5d063811ec [file] [log] [blame]
Chris Smart02651712015-11-11 11:09:00 +11001#!/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 Geisslerc16868c2016-08-23 21:55:13 -05007# distro = fedora|ubuntu|ubuntu:14.04|ubuntu:16.04
Andrew Geisslerc3c35202016-08-16 08:47:50 -05008# obmcdir = <name of openbmc src dir> (default openbmc)
Andrew Geissler11abbbe2016-08-14 19:39:47 -05009# WORKSPACE = <location of base openbmc/openbmc repo>
Andrew Geissler496a6b02016-10-03 10:04:49 -050010# BITBAKE_OPTS = <optional, set to "-c populate_sdk" or whatever other
11# bitbake options you'd like to pass into the build>
Chris Smart02651712015-11-11 11:09:00 +110012
Joel Stanley4b8b2392016-02-12 15:44:57 +103013# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103014set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110015
16# Default variables
17target=${target:-qemu}
18distro=${distro:-ubuntu}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050019obmcdir=${obmcdir:-openbmc}
Chris Smart02651712015-11-11 11:09:00 +110020WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
21http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110022PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110023
Andrew Geissler11abbbe2016-08-14 19:39:47 -050024# Determine our architecture, ppc64le or the other one
25if [ $(uname -m) == "ppc64le" ]; then
26 DOCKER_BASE="ppc64le/"
27else
28 DOCKER_BASE=""
29fi
30
Chris Smart02651712015-11-11 11:09:00 +110031# Timestamp for job
32echo "Build started, $(date)"
33
Andrew Geisslerc3c35202016-08-16 08:47:50 -050034# If there's no openbmc dir in WORKSPACE then just clone in master
35if [ ! -d ${WORKSPACE}/${obmcdir} ]; then
36 echo "Clone in openbmc master to ${WORKSPACE}/${obmcdir}"
37 git clone https://github.com/openbmc/openbmc ${WORKSPACE}/${obmcdir}
38fi
39
Andrew Geisslerc16868c2016-08-23 21:55:13 -050040# if user just passed in ubuntu then use latest
41if [[ $distro == "ubuntu" ]]; then
42 distro="ubuntu:latest"
43fi
44
Chris Smart02651712015-11-11 11:09:00 +110045# Work out what build target we should be running and set bitbake command
46case ${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 Stanley0e077202016-06-28 16:42:45 +093053 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 Stanley915381f2016-11-01 16:58:59 +103065 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 Smart02651712015-11-11 11:09:00 +110071 qemu)
72 BITBAKE_CMD="source openbmc-env"
73 ;;
74 *)
75 exit 1
76 ;;
77esac
78
79# Configure docker build
80if [[ "${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 Geissler11abbbe2016-08-14 19:39:47 -050087FROM ${DOCKER_BASE}fedora:latest
Chris Smart02651712015-11-11 11:09:00 +110088
89${PROXY}
90
Chris Smartfc730ff2016-03-09 20:17:19 +110091RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110092 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 \
106 SDL-devel \
107 socat \
108 subversion \
109 tar \
110 texinfo \
111 wget \
112 which
Chris Smart02651712015-11-11 11:09:00 +1100113
Chris Smartd30c5902016-03-01 15:00:54 +1100114RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
115RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100116
117USER ${USER}
118ENV HOME ${HOME}
119RUN /bin/bash
120EOF
121)
122
Andrew Geisslerc16868c2016-08-23 21:55:13 -0500123elif [[ "${distro}" == "ubuntu"* ]]; then
Chris Smart02651712015-11-11 11:09:00 +1100124 if [[ -n "${http_proxy}" ]]; then
125 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
126 fi
127
128 Dockerfile=$(cat << EOF
Andrew Geisslerc16868c2016-08-23 21:55:13 -0500129FROM ${DOCKER_BASE}${distro}
Chris Smart02651712015-11-11 11:09:00 +1100130
131${PROXY}
132
Chris Smart4593d4f2016-03-09 15:50:59 +1100133ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100134RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100135 build-essential \
136 chrpath \
137 debianutils \
138 diffstat \
139 gawk \
140 git \
141 libdata-dumper-simple-perl \
142 libsdl1.2-dev \
143 libthread-queue-any-perl \
144 python \
145 socat \
146 subversion \
147 texinfo \
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500148 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100149 wget
Chris Smart02651712015-11-11 11:09:00 +1100150
Chris Smartd30c5902016-03-01 15:00:54 +1100151RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
152RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
153
Chris Smart02651712015-11-11 11:09:00 +1100154USER ${USER}
155ENV HOME ${HOME}
156RUN /bin/bash
157EOF
158)
159fi
160
161# Build the docker container
162docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100163
164# Create the docker run script
165export PROXY_HOST=${http_proxy/#http*:\/\/}
166export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
167export PROXY_PORT=${http_proxy/#http*:\/\/*:}
168
Chris Smart01d2b962015-11-11 18:05:30 +1100169mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100170
Chris Smart01d2b962015-11-11 18:05:30 +1100171cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100172#!/bin/bash
173
Joel Stanley38c9d142016-02-16 12:31:55 +1030174set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100175
Chris Smart01d2b962015-11-11 18:05:30 +1100176cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100177
178# Go into the openbmc directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500179cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100180
181# Set up proxies
182export ftp_proxy=${http_proxy}
183export http_proxy=${http_proxy}
184export https_proxy=${http_proxy}
185
Chris Smart01d2b962015-11-11 18:05:30 +1100186mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100187
188# Configure proxies for bitbake
189if [[ -n "${http_proxy}" ]]; then
190
Chris Smartd30c5902016-03-01 15:00:54 +1100191 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100192#!/bin/bash
193# \$1 = hostname, \$2 = port
194PROXY=${PROXY_HOST}
195PROXY_PORT=${PROXY_PORT}
196exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
197EOF_GIT
198
Chris Smart01d2b962015-11-11 18:05:30 +1100199 chmod a+x ${WORKSPACE}/bin/git-proxy
200 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100201 git config core.gitProxy git-proxy
202
203 mkdir -p ~/.subversion
204
205 cat > ~/.subversion/servers << EOF_SVN
206[global]
207http-proxy-host = ${PROXY_HOST}
208http-proxy-port = ${PROXY_PORT}
209EOF_SVN
210fi
211
212# Source our build env
213${BITBAKE_CMD}
214
215# Custom bitbake config settings
216cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100217BB_NUMBER_THREADS = "$(nproc)"
218PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100219INHERIT += "rm_work"
220BB_GENERATE_MIRROR_TARBALLS = "1"
221DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500222SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100223USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500224INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100225EOF_CONF
226
227# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500228bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100229
230EOF_SCRIPT
231
232chmod a+x ${WORKSPACE}/build.sh
233
234# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100235docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
236 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100237
238# Create link to images for archiving
239ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
240
241# Timestamp for build
242echo "Build completed, $(date)"
243