blob: fc2b1a0e14627a1475abe4fc3a4756ff19372cb7 [file] [log] [blame]
Chris Smart02651712015-11-11 11:09:00 +11001#!/bin/bash
2
Alanny Lopez3fbaa512017-04-24 15:46:52 -05003# This build script is for running the Jenkins builds using Docker or Kubernetes.
Chris Smart02651712015-11-11 11:09:00 +11004#
5# It expects a few variables which are part of Jenkins build job matrix:
6# target = barreleye|palmetto|qemu
Alanny Lopezccc650e2017-04-24 15:14:20 -05007# distro = fedora|ubuntu
8# imgtag = tag of the Ubuntu or Fedora image to use (default latest)
Alanny Lopez3fbaa512017-04-24 15:46:52 -05009# obmcdir = <name of OpenBMC src dir> (default /tmp/openbmc)
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050010# WORKSPACE = <location of base OpenBMC/OpenBMC repo>
Andrew Geissler496a6b02016-10-03 10:04:49 -050011# BITBAKE_OPTS = <optional, set to "-c populate_sdk" or whatever other
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050012# BitBake options you'd like to pass into the build>
Alanny Lopez3fbaa512017-04-24 15:46:52 -050013#
14# There are some optional variables that are related to launching the build
15# launch = job|pod, what way the build container will be launched. If left
16# blank launches user docker run, job or pod will launch the
17# appropriate kind to kubernetes via kubernetes-launch.sh
18# imgname = defaults to a relatively long but descriptive name, can be
19# changed or passed to give a specific name to created image
Chris Smart02651712015-11-11 11:09:00 +110020
Joel Stanley4b8b2392016-02-12 15:44:57 +103021# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103022set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110023
24# Default variables
25target=${target:-qemu}
26distro=${distro:-ubuntu}
Alanny Lopezccc650e2017-04-24 15:14:20 -050027imgtag=${imgtag:-latest}
Alanny Lopeze6870192017-04-24 15:25:59 -050028ocache=${ocache:-/home/openbmc}
29obmcdir=${obmcdir:-/tmp/openbmc}
Chris Smart02651712015-11-11 11:09:00 +110030WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopez3fbaa512017-04-24 15:46:52 -050031launch=${launch:-}
Chris Smart02651712015-11-11 11:09:00 +110032http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110033PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110034
Alanny Lopezccc650e2017-04-24 15:14:20 -050035# Determine the architecture
36ARCH=$(uname -m)
37
38# Determine the prefix of the Dockerfile's base image
39case ${ARCH} in
40 "ppc64le")
41 DOCKER_BASE="ppc64le/"
42 ;;
43 "x86_64")
44 DOCKER_BASE=""
45 ;;
46 *)
47 echo "Unsupported system architecture(${ARCH}) found for docker image"
48 exit 1
49esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050050
Chris Smart02651712015-11-11 11:09:00 +110051# Timestamp for job
52echo "Build started, $(date)"
53
Alanny Lopeze6870192017-04-24 15:25:59 -050054# If the ocache directory doesn't exist clone it in, ocache will be used as a cache for git clones
55if [ ! -d ${ocache} ]; then
56 echo "Clone in openbmc master to ${ocache} to act as cache for future builds"
57 git clone https://github.com/openbmc/openbmc ${ocache}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050058fi
59
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050060# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +110061case ${target} in
62 barreleye)
63 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
64 ;;
65 palmetto)
66 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
67 ;;
Joel Stanley0e077202016-06-28 16:42:45 +093068 witherspoon)
69 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
70 ;;
71 firestone)
72 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
73 ;;
74 garrison)
75 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
76 ;;
77 evb-ast2500)
78 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
79 ;;
Joel Stanley915381f2016-11-01 16:58:59 +103080 zaius)
81 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env"
82 ;;
83 romulus)
84 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env"
85 ;;
Chris Smart02651712015-11-11 11:09:00 +110086 qemu)
87 BITBAKE_CMD="source openbmc-env"
88 ;;
89 *)
90 exit 1
91 ;;
92esac
93
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050094# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +110095if [[ "${distro}" == fedora ]];then
96
97 if [[ -n "${http_proxy}" ]]; then
98 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
99 fi
100
101 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500102 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100103
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500104 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100105
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500106 # Set the locale
107 RUN locale-gen en_US.UTF-8
108 ENV LANG en_US.UTF-8
109 ENV LANGUAGE en_US:en
110 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500111
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500112 RUN dnf --refresh install -y \
113 bzip2 \
114 chrpath \
115 cpio \
116 diffstat \
117 findutils \
118 gcc \
119 gcc-c++ \
120 git \
121 make \
122 patch \
123 perl-bignum \
124 perl-Data-Dumper \
125 perl-Thread-Queue \
126 python-devel \
127 python3-devel \
128 SDL-devel \
129 socat \
130 subversion \
131 tar \
132 texinfo \
133 wget \
134 which
Chris Smart02651712015-11-11 11:09:00 +1100135
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500136 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
137 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100138
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500139 USER ${USER}
140 ENV HOME ${HOME}
141 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100142EOF
143)
144
Alanny Lopezccc650e2017-04-24 15:14:20 -0500145elif [[ "${distro}" == ubuntu ]]; then
146
Chris Smart02651712015-11-11 11:09:00 +1100147 if [[ -n "${http_proxy}" ]]; then
148 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
149 fi
150
151 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500152 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100153
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500154 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100155
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500156 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500157
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500158 # Set the locale
159 RUN locale-gen en_US.UTF-8
160 ENV LANG en_US.UTF-8
161 ENV LANGUAGE en_US:en
162 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500163
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500164 RUN apt-get update && apt-get install -yy \
165 build-essential \
166 chrpath \
167 debianutils \
168 diffstat \
169 gawk \
170 git \
171 libdata-dumper-simple-perl \
172 libsdl1.2-dev \
173 libthread-queue-any-perl \
174 python \
175 python3 \
176 socat \
177 subversion \
178 texinfo \
179 cpio \
180 wget
Chris Smart02651712015-11-11 11:09:00 +1100181
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500182 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
183 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100184
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500185 USER ${USER}
186 ENV HOME ${HOME}
187 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100188EOF
189)
190fi
191
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500192# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100193export PROXY_HOST=${http_proxy/#http*:\/\/}
194export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
195export PROXY_PORT=${http_proxy/#http*:\/\/*:}
196
Chris Smart01d2b962015-11-11 18:05:30 +1100197mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100198
Chris Smart01d2b962015-11-11 18:05:30 +1100199cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100200#!/bin/bash
201
Joel Stanley38c9d142016-02-16 12:31:55 +1030202set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100203
Alanny Lopeze6870192017-04-24 15:25:59 -0500204# Use the mounted repo cache to make an internal repo not mounted externally
205git clone --reference ${ocache} --dissociate https://github.com/openbmc/openbmc ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100206
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500207# Go into the OpenBMC directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500208cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100209
210# Set up proxies
211export ftp_proxy=${http_proxy}
212export http_proxy=${http_proxy}
213export https_proxy=${http_proxy}
214
Chris Smart01d2b962015-11-11 18:05:30 +1100215mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100216
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500217# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100218if [[ -n "${http_proxy}" ]]; then
219
Chris Smartd30c5902016-03-01 15:00:54 +1100220 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500221 #!/bin/bash
222 # \$1 = hostname, \$2 = port
223 PROXY=${PROXY_HOST}
224 PROXY_PORT=${PROXY_PORT}
225 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100226EOF_GIT
227
Chris Smart01d2b962015-11-11 18:05:30 +1100228 chmod a+x ${WORKSPACE}/bin/git-proxy
229 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100230 git config core.gitProxy git-proxy
231
232 mkdir -p ~/.subversion
233
234 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500235 [global]
236 http-proxy-host = ${PROXY_HOST}
237 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100238EOF_SVN
239fi
240
241# Source our build env
242${BITBAKE_CMD}
243
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500244# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100245cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100246BB_NUMBER_THREADS = "$(nproc)"
247PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100248INHERIT += "rm_work"
249BB_GENERATE_MIRROR_TARBALLS = "1"
250DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500251SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100252USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500253INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100254EOF_CONF
255
256# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500257bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100258
Alanny Lopeze6870192017-04-24 15:25:59 -0500259# Copy images out of internal obmcdir into workspace directory
260cp -R ${obmcdir}/build/tmp/deploy/images ${WORKSPACE}/images/
261
Chris Smart02651712015-11-11 11:09:00 +1100262EOF_SCRIPT
263
264chmod a+x ${WORKSPACE}/build.sh
265
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500266# Determine if the build container will be launched with Docker or Kubernetes
267if [[ "${launch}" == "" ]]; then
268
269 # Give the Docker image a name based on the distro,tag,arch,and target
270 imgname=${imgname:-openbmc/${distro}:${imgtag}-${target}-${ARCH}}
271
272 # Build the Docker image
273 docker build -t ${imgname} - <<< "${Dockerfile}"
274
275 # Run the Docker container, execute the build.sh script
276 docker run \
277 --cap-add=sys_admin \
278 --net=host \
279 --rm=true \
280 -e WORKSPACE=${WORKSPACE} \
281 -w "${HOME}" \
282 -v "${HOME}":"${HOME}" \
283 -v "${ocache}":"${ocache}" \
284 -t ${imgname} \
285 ${WORKSPACE}/build.sh
286
287elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
288
289 # Source and run the helper script to launch the pod or job
290 . kubernetes/kubernetes-launch.sh
291
292else
293 echo "Launch Parameter is invalid"
294fi
Chris Smart02651712015-11-11 11:09:00 +1100295
296# Timestamp for build
Alanny Lopeze6870192017-04-24 15:25:59 -0500297echo "Build completed, $(date)"