blob: f092f45a2dcb88db787eae379ce977917e1eed55 [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 ;;
Chris Smart02651712015-11-11 11:09:00 +110065 qemu)
66 BITBAKE_CMD="source openbmc-env"
67 ;;
68 *)
69 exit 1
70 ;;
71esac
72
73# Configure docker build
74if [[ "${distro}" == fedora ]];then
75
76 if [[ -n "${http_proxy}" ]]; then
77 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
78 fi
79
80 Dockerfile=$(cat << EOF
Andrew Geissler11abbbe2016-08-14 19:39:47 -050081FROM ${DOCKER_BASE}fedora:latest
Chris Smart02651712015-11-11 11:09:00 +110082
83${PROXY}
84
Chris Smartfc730ff2016-03-09 20:17:19 +110085RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110086 bzip2 \
87 chrpath \
88 cpio \
89 diffstat \
90 findutils \
91 gcc \
92 gcc-c++ \
93 git \
94 make \
95 patch \
96 perl-bignum \
97 perl-Data-Dumper \
98 perl-Thread-Queue \
99 python-devel \
100 SDL-devel \
101 socat \
102 subversion \
103 tar \
104 texinfo \
105 wget \
106 which
Chris Smart02651712015-11-11 11:09:00 +1100107
Chris Smartd30c5902016-03-01 15:00:54 +1100108RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
109RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100110
111USER ${USER}
112ENV HOME ${HOME}
113RUN /bin/bash
114EOF
115)
116
Andrew Geisslerc16868c2016-08-23 21:55:13 -0500117elif [[ "${distro}" == "ubuntu"* ]]; then
Chris Smart02651712015-11-11 11:09:00 +1100118 if [[ -n "${http_proxy}" ]]; then
119 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
120 fi
121
122 Dockerfile=$(cat << EOF
Andrew Geisslerc16868c2016-08-23 21:55:13 -0500123FROM ${DOCKER_BASE}${distro}
Chris Smart02651712015-11-11 11:09:00 +1100124
125${PROXY}
126
Chris Smart4593d4f2016-03-09 15:50:59 +1100127ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100128RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100129 build-essential \
130 chrpath \
131 debianutils \
132 diffstat \
133 gawk \
134 git \
135 libdata-dumper-simple-perl \
136 libsdl1.2-dev \
137 libthread-queue-any-perl \
138 python \
139 socat \
140 subversion \
141 texinfo \
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500142 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100143 wget
Chris Smart02651712015-11-11 11:09:00 +1100144
Chris Smartd30c5902016-03-01 15:00:54 +1100145RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
146RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
147
Chris Smart02651712015-11-11 11:09:00 +1100148USER ${USER}
149ENV HOME ${HOME}
150RUN /bin/bash
151EOF
152)
153fi
154
155# Build the docker container
156docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100157
158# Create the docker run script
159export PROXY_HOST=${http_proxy/#http*:\/\/}
160export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
161export PROXY_PORT=${http_proxy/#http*:\/\/*:}
162
Chris Smart01d2b962015-11-11 18:05:30 +1100163mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100164
Chris Smart01d2b962015-11-11 18:05:30 +1100165cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100166#!/bin/bash
167
Joel Stanley38c9d142016-02-16 12:31:55 +1030168set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100169
Chris Smart01d2b962015-11-11 18:05:30 +1100170cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100171
172# Go into the openbmc directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500173cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100174
175# Set up proxies
176export ftp_proxy=${http_proxy}
177export http_proxy=${http_proxy}
178export https_proxy=${http_proxy}
179
Chris Smart01d2b962015-11-11 18:05:30 +1100180mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100181
182# Configure proxies for bitbake
183if [[ -n "${http_proxy}" ]]; then
184
Chris Smartd30c5902016-03-01 15:00:54 +1100185 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100186#!/bin/bash
187# \$1 = hostname, \$2 = port
188PROXY=${PROXY_HOST}
189PROXY_PORT=${PROXY_PORT}
190exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
191EOF_GIT
192
Chris Smart01d2b962015-11-11 18:05:30 +1100193 chmod a+x ${WORKSPACE}/bin/git-proxy
194 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100195 git config core.gitProxy git-proxy
196
197 mkdir -p ~/.subversion
198
199 cat > ~/.subversion/servers << EOF_SVN
200[global]
201http-proxy-host = ${PROXY_HOST}
202http-proxy-port = ${PROXY_PORT}
203EOF_SVN
204fi
205
206# Source our build env
207${BITBAKE_CMD}
208
209# Custom bitbake config settings
210cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100211BB_NUMBER_THREADS = "$(nproc)"
212PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100213INHERIT += "rm_work"
214BB_GENERATE_MIRROR_TARBALLS = "1"
215DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500216SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100217USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500218INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100219EOF_CONF
220
221# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500222bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100223
224EOF_SCRIPT
225
226chmod a+x ${WORKSPACE}/build.sh
227
228# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100229docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
230 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100231
232# Create link to images for archiving
233ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
234
235# Timestamp for build
236echo "Build completed, $(date)"
237