blob: 745fe68f1f0bd3571af447a5d8994686939d9e33 [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
7# distro = fedora|ubuntu
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>
Chris Smart02651712015-11-11 11:09:00 +110010
Joel Stanley4b8b2392016-02-12 15:44:57 +103011# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103012set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110013
14# Default variables
15target=${target:-qemu}
16distro=${distro:-ubuntu}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050017obmcdir=${obmcdir:-openbmc}
Chris Smart02651712015-11-11 11:09:00 +110018WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
19http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110020PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110021
Andrew Geissler11abbbe2016-08-14 19:39:47 -050022# Determine our architecture, ppc64le or the other one
23if [ $(uname -m) == "ppc64le" ]; then
24 DOCKER_BASE="ppc64le/"
25else
26 DOCKER_BASE=""
27fi
28
Chris Smart02651712015-11-11 11:09:00 +110029# Timestamp for job
30echo "Build started, $(date)"
31
Andrew Geisslerc3c35202016-08-16 08:47:50 -050032# If there's no openbmc dir in WORKSPACE then just clone in master
33if [ ! -d ${WORKSPACE}/${obmcdir} ]; then
34 echo "Clone in openbmc master to ${WORKSPACE}/${obmcdir}"
35 git clone https://github.com/openbmc/openbmc ${WORKSPACE}/${obmcdir}
36fi
37
Chris Smart02651712015-11-11 11:09:00 +110038# Work out what build target we should be running and set bitbake command
39case ${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 Stanley0e077202016-06-28 16:42:45 +093046 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 Smart02651712015-11-11 11:09:00 +110058 qemu)
59 BITBAKE_CMD="source openbmc-env"
60 ;;
61 *)
62 exit 1
63 ;;
64esac
65
66# Configure docker build
67if [[ "${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 Geissler11abbbe2016-08-14 19:39:47 -050074FROM ${DOCKER_BASE}fedora:latest
Chris Smart02651712015-11-11 11:09:00 +110075
76${PROXY}
77
Chris Smartfc730ff2016-03-09 20:17:19 +110078RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110079 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 Smart02651712015-11-11 11:09:00 +1100100
Chris Smartd30c5902016-03-01 15:00:54 +1100101RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
102RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100103
104USER ${USER}
105ENV HOME ${HOME}
106RUN /bin/bash
107EOF
108)
109
110elif [[ "${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 Geissler11abbbe2016-08-14 19:39:47 -0500116FROM ${DOCKER_BASE}ubuntu:latest
Chris Smart02651712015-11-11 11:09:00 +1100117
118${PROXY}
119
Chris Smart4593d4f2016-03-09 15:50:59 +1100120ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100121RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100122 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 Geissler11abbbe2016-08-14 19:39:47 -0500135 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100136 wget
Chris Smart02651712015-11-11 11:09:00 +1100137
Chris Smartd30c5902016-03-01 15:00:54 +1100138RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
139RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
140
Chris Smart02651712015-11-11 11:09:00 +1100141USER ${USER}
142ENV HOME ${HOME}
143RUN /bin/bash
144EOF
145)
146fi
147
148# Build the docker container
149docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100150
151# Create the docker run script
152export PROXY_HOST=${http_proxy/#http*:\/\/}
153export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
154export PROXY_PORT=${http_proxy/#http*:\/\/*:}
155
Chris Smart01d2b962015-11-11 18:05:30 +1100156mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100157
Chris Smart01d2b962015-11-11 18:05:30 +1100158cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100159#!/bin/bash
160
Joel Stanley38c9d142016-02-16 12:31:55 +1030161set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100162
Chris Smart01d2b962015-11-11 18:05:30 +1100163cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100164
165# Go into the openbmc directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500166cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100167
168# Set up proxies
169export ftp_proxy=${http_proxy}
170export http_proxy=${http_proxy}
171export https_proxy=${http_proxy}
172
Chris Smart01d2b962015-11-11 18:05:30 +1100173mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100174
175# Configure proxies for bitbake
176if [[ -n "${http_proxy}" ]]; then
177
Chris Smartd30c5902016-03-01 15:00:54 +1100178 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100179#!/bin/bash
180# \$1 = hostname, \$2 = port
181PROXY=${PROXY_HOST}
182PROXY_PORT=${PROXY_PORT}
183exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
184EOF_GIT
185
Chris Smart01d2b962015-11-11 18:05:30 +1100186 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 Smart02651712015-11-11 11:09:00 +1100188 git config core.gitProxy git-proxy
189
190 mkdir -p ~/.subversion
191
192 cat > ~/.subversion/servers << EOF_SVN
193[global]
194http-proxy-host = ${PROXY_HOST}
195http-proxy-port = ${PROXY_PORT}
196EOF_SVN
197fi
198
199# Source our build env
200${BITBAKE_CMD}
201
202# Custom bitbake config settings
203cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100204BB_NUMBER_THREADS = "$(nproc)"
205PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100206INHERIT += "rm_work"
207BB_GENERATE_MIRROR_TARBALLS = "1"
208DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500209SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100210USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500211INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100212EOF_CONF
213
214# Kick off a build
215bitbake obmc-phosphor-image
216
217EOF_SCRIPT
218
219chmod a+x ${WORKSPACE}/build.sh
220
221# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100222docker 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 Smart02651712015-11-11 11:09:00 +1100224
225# Create link to images for archiving
226ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
227
228# Timestamp for build
229echo "Build completed, $(date)"
230