blob: da8cbc3901b4572343bafc4c05b30f68607b5f2d [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
Saqib Khan75635122017-03-23 10:57:34 -050091# Set the locale
92RUN locale-gen en_US.UTF-8
93ENV LANG en_US.UTF-8
94ENV LANGUAGE en_US:en
95ENV LC_ALL en_US.UTF-8
96
Chris Smartfc730ff2016-03-09 20:17:19 +110097RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110098 bzip2 \
99 chrpath \
100 cpio \
101 diffstat \
102 findutils \
103 gcc \
104 gcc-c++ \
105 git \
106 make \
107 patch \
108 perl-bignum \
109 perl-Data-Dumper \
110 perl-Thread-Queue \
111 python-devel \
Saqib Khan362ca852017-03-21 10:48:46 -0500112 python3-devel \
Chris Smart4593d4f2016-03-09 15:50:59 +1100113 SDL-devel \
114 socat \
115 subversion \
116 tar \
117 texinfo \
118 wget \
119 which
Chris Smart02651712015-11-11 11:09:00 +1100120
Chris Smartd30c5902016-03-01 15:00:54 +1100121RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
122RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100123
124USER ${USER}
125ENV HOME ${HOME}
126RUN /bin/bash
127EOF
128)
129
Andrew Geisslerc16868c2016-08-23 21:55:13 -0500130elif [[ "${distro}" == "ubuntu"* ]]; then
Chris Smart02651712015-11-11 11:09:00 +1100131 if [[ -n "${http_proxy}" ]]; then
132 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
133 fi
134
135 Dockerfile=$(cat << EOF
Andrew Geisslerc16868c2016-08-23 21:55:13 -0500136FROM ${DOCKER_BASE}${distro}
Chris Smart02651712015-11-11 11:09:00 +1100137
138${PROXY}
139
Chris Smart4593d4f2016-03-09 15:50:59 +1100140ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500141
142# Set the locale
143RUN locale-gen en_US.UTF-8
144ENV LANG en_US.UTF-8
145ENV LANGUAGE en_US:en
146ENV LC_ALL en_US.UTF-8
147
Chris Smartfc730ff2016-03-09 20:17:19 +1100148RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100149 build-essential \
150 chrpath \
151 debianutils \
152 diffstat \
153 gawk \
154 git \
155 libdata-dumper-simple-perl \
156 libsdl1.2-dev \
157 libthread-queue-any-perl \
158 python \
Saqib Khan362ca852017-03-21 10:48:46 -0500159 python3 \
Chris Smart4593d4f2016-03-09 15:50:59 +1100160 socat \
161 subversion \
162 texinfo \
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500163 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100164 wget
Chris Smart02651712015-11-11 11:09:00 +1100165
Chris Smartd30c5902016-03-01 15:00:54 +1100166RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
167RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
168
Chris Smart02651712015-11-11 11:09:00 +1100169USER ${USER}
170ENV HOME ${HOME}
171RUN /bin/bash
172EOF
173)
174fi
175
176# Build the docker container
177docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100178
179# Create the docker run script
180export PROXY_HOST=${http_proxy/#http*:\/\/}
181export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
182export PROXY_PORT=${http_proxy/#http*:\/\/*:}
183
Chris Smart01d2b962015-11-11 18:05:30 +1100184mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100185
Chris Smart01d2b962015-11-11 18:05:30 +1100186cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100187#!/bin/bash
188
Joel Stanley38c9d142016-02-16 12:31:55 +1030189set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100190
Chris Smart01d2b962015-11-11 18:05:30 +1100191cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100192
193# Go into the openbmc directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500194cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100195
196# Set up proxies
197export ftp_proxy=${http_proxy}
198export http_proxy=${http_proxy}
199export https_proxy=${http_proxy}
200
Chris Smart01d2b962015-11-11 18:05:30 +1100201mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100202
203# Configure proxies for bitbake
204if [[ -n "${http_proxy}" ]]; then
205
Chris Smartd30c5902016-03-01 15:00:54 +1100206 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100207#!/bin/bash
208# \$1 = hostname, \$2 = port
209PROXY=${PROXY_HOST}
210PROXY_PORT=${PROXY_PORT}
211exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
212EOF_GIT
213
Chris Smart01d2b962015-11-11 18:05:30 +1100214 chmod a+x ${WORKSPACE}/bin/git-proxy
215 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100216 git config core.gitProxy git-proxy
217
218 mkdir -p ~/.subversion
219
220 cat > ~/.subversion/servers << EOF_SVN
221[global]
222http-proxy-host = ${PROXY_HOST}
223http-proxy-port = ${PROXY_PORT}
224EOF_SVN
225fi
226
227# Source our build env
228${BITBAKE_CMD}
229
230# Custom bitbake config settings
231cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100232BB_NUMBER_THREADS = "$(nproc)"
233PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100234INHERIT += "rm_work"
235BB_GENERATE_MIRROR_TARBALLS = "1"
236DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500237SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100238USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500239INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100240EOF_CONF
241
242# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500243bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100244
245EOF_SCRIPT
246
247chmod a+x ${WORKSPACE}/build.sh
248
249# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100250docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
251 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100252
253# Create link to images for archiving
254ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
255
256# Timestamp for build
257echo "Build completed, $(date)"
258