blob: 1722f4a1ca3a2f8fe5ebc9c02b93ee047d4d846e [file] [log] [blame]
Alanny Lopez56fc36a2017-07-27 13:55:44 -05001#!/bin/bash
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05002###############################################################################
Chris Smart02651712015-11-11 11:09:00 +11003#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05004# This build script is for running the OpenBMC builds as containers with the
5# option of launching the containers with Docker or Kubernetes.
Alanny Lopez3fbaa512017-04-24 15:46:52 -05006#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05007###############################################################################
8#
9# Variables used for Jenkins build job matrix:
10# target = barreleye|palmetto|witherspoon|firestone|garrison|evb-ast2500
11# zaius|romulus|qemu
12# distro = fedora|ubuntu
13# imgtag = Varies by distro. latest|16.04|14.04|trusty|xenial; 23|24|25
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050014# obmcext = Path of the OpenBMC repo directory used in creating a copy
15# inside the container that is not mounted to external storage
16# default directory location "${WORKSPACE}/openbmc"
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050017# obmcdir = Path of the OpenBMC directory, where the build occurs inside
18# the container cannot be placed on external storage default
19# directory location "/tmp/openbmc"
20# sscdir = Path of the BitBake shared-state cache directoy, will default
21# to directory "/home/${USER}", used to speed up builds.
22# WORKSPACE = Path of the workspace directory where some intermediate files
23# and the images will be saved to.
24#
25# Optional Variables:
26# launch = job|pod
27# Can be left blank to launch via Docker if not using
28# Kubernetes to launch the container.
29# Job lets you keep a copy of job and container logs on the
30# api, can be useful if not using Jenkins as you can run the
31# job again via the api without needing this script.
32# Pod launches a container which runs to completion without
33# saving anything to the api when it completes.
34# imgname = Defaults to a relatively long but descriptive name, can be
35# changed or passed to give a specific name to created image.
36# http_proxy = The HTTP address for the proxy server you wish to connect to.
37# BITBAKE_OPTS = Set to "-c populate_sdk" or whatever other bitbake options
38# you'd like to pass into the build.
39#
40###############################################################################
Chris Smart02651712015-11-11 11:09:00 +110041
Joel Stanley4b8b2392016-02-12 15:44:57 +103042# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103043set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110044
45# Default variables
46target=${target:-qemu}
47distro=${distro:-ubuntu}
Alanny Lopezccc650e2017-04-24 15:14:20 -050048imgtag=${imgtag:-latest}
Alanny Lopeze6870192017-04-24 15:25:59 -050049obmcdir=${obmcdir:-/tmp/openbmc}
Alanny Lopez97a79502017-04-24 16:19:25 -050050sscdir=${sscdir:-${HOME}}
Chris Smart02651712015-11-11 11:09:00 +110051WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050052obmcext=${obmcext:-${WORKSPACE}/openbmc}
Alanny Lopez3fbaa512017-04-24 15:46:52 -050053launch=${launch:-}
Chris Smart02651712015-11-11 11:09:00 +110054http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110055PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110056
Alanny Lopezccc650e2017-04-24 15:14:20 -050057# Determine the architecture
58ARCH=$(uname -m)
59
60# Determine the prefix of the Dockerfile's base image
61case ${ARCH} in
62 "ppc64le")
63 DOCKER_BASE="ppc64le/"
64 ;;
65 "x86_64")
66 DOCKER_BASE=""
67 ;;
68 *)
69 echo "Unsupported system architecture(${ARCH}) found for docker image"
70 exit 1
71esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050072
Chris Smart02651712015-11-11 11:09:00 +110073# Timestamp for job
74echo "Build started, $(date)"
75
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -050076# If the obmcext directory doesn't exist clone it in
77if [ ! -d ${obmcext} ]; then
78 echo "Clone in openbmc master to ${obmcext}"
79 git clone https://github.com/openbmc/openbmc ${obmcext}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050080fi
81
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050082# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +110083case ${target} in
84 barreleye)
85 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
86 ;;
87 palmetto)
88 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
89 ;;
Joel Stanley0e077202016-06-28 16:42:45 +093090 witherspoon)
91 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
92 ;;
93 firestone)
94 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
95 ;;
96 garrison)
97 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
98 ;;
99 evb-ast2500)
100 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
101 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030102 zaius)
103 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env"
104 ;;
105 romulus)
106 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env"
107 ;;
Chris Smart02651712015-11-11 11:09:00 +1100108 qemu)
109 BITBAKE_CMD="source openbmc-env"
110 ;;
111 *)
112 exit 1
113 ;;
114esac
115
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500116# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100117if [[ "${distro}" == fedora ]];then
118
119 if [[ -n "${http_proxy}" ]]; then
120 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
121 fi
122
123 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500124 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100125
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500126 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100127
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500128 # Set the locale
129 RUN locale-gen en_US.UTF-8
130 ENV LANG en_US.UTF-8
131 ENV LANGUAGE en_US:en
132 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500133
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500134 RUN dnf --refresh install -y \
135 bzip2 \
136 chrpath \
137 cpio \
138 diffstat \
139 findutils \
140 gcc \
141 gcc-c++ \
142 git \
143 make \
144 patch \
145 perl-bignum \
146 perl-Data-Dumper \
147 perl-Thread-Queue \
148 python-devel \
149 python3-devel \
150 SDL-devel \
151 socat \
152 subversion \
153 tar \
154 texinfo \
155 wget \
156 which
Chris Smart02651712015-11-11 11:09:00 +1100157
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500158 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
159 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100160
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500161 USER ${USER}
162 ENV HOME ${HOME}
163 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100164EOF
165)
166
Alanny Lopezccc650e2017-04-24 15:14:20 -0500167elif [[ "${distro}" == ubuntu ]]; then
168
Chris Smart02651712015-11-11 11:09:00 +1100169 if [[ -n "${http_proxy}" ]]; then
170 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
171 fi
172
173 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500174 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100175
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500176 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100177
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500178 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500179
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500180 RUN apt-get update && apt-get install -yy \
181 build-essential \
182 chrpath \
183 debianutils \
184 diffstat \
185 gawk \
186 git \
187 libdata-dumper-simple-perl \
188 libsdl1.2-dev \
189 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500190 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500191 python \
192 python3 \
193 socat \
194 subversion \
195 texinfo \
196 cpio \
197 wget
Chris Smart02651712015-11-11 11:09:00 +1100198
Alanny Lopez27af3a02017-05-26 10:49:06 -0500199 # Set the locale
200 RUN locale-gen en_US.UTF-8
201 ENV LANG en_US.UTF-8
202 ENV LANGUAGE en_US:en
203 ENV LC_ALL en_US.UTF-8
204
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500205 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
206 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100207
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500208 USER ${USER}
209 ENV HOME ${HOME}
210 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100211EOF
212)
213fi
214
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500215# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100216export PROXY_HOST=${http_proxy/#http*:\/\/}
217export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
218export PROXY_PORT=${http_proxy/#http*:\/\/*:}
219
Chris Smart01d2b962015-11-11 18:05:30 +1100220mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100221
Chris Smart01d2b962015-11-11 18:05:30 +1100222cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100223#!/bin/bash
224
Joel Stanley38c9d142016-02-16 12:31:55 +1030225set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100226
Alanny Lopeze6870192017-04-24 15:25:59 -0500227# Use the mounted repo cache to make an internal repo not mounted externally
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500228cp -R ${obmcext} ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100229
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500230# Go into the OpenBMC directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500231cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100232
233# Set up proxies
234export ftp_proxy=${http_proxy}
235export http_proxy=${http_proxy}
236export https_proxy=${http_proxy}
237
Chris Smart01d2b962015-11-11 18:05:30 +1100238mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100239
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500240# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100241if [[ -n "${http_proxy}" ]]; then
242
Chris Smartd30c5902016-03-01 15:00:54 +1100243 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500244 #!/bin/bash
245 # \$1 = hostname, \$2 = port
246 PROXY=${PROXY_HOST}
247 PROXY_PORT=${PROXY_PORT}
248 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100249EOF_GIT
250
Chris Smart01d2b962015-11-11 18:05:30 +1100251 chmod a+x ${WORKSPACE}/bin/git-proxy
252 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100253 git config core.gitProxy git-proxy
254
255 mkdir -p ~/.subversion
256
257 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500258 [global]
259 http-proxy-host = ${PROXY_HOST}
260 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100261EOF_SVN
262fi
263
264# Source our build env
265${BITBAKE_CMD}
266
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500267# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100268cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100269BB_NUMBER_THREADS = "$(nproc)"
270PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100271INHERIT += "rm_work"
272BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez97a79502017-04-24 16:19:25 -0500273DL_DIR="${sscdir}/bitbake_downloads"
274SSTATE_DIR="${sscdir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100275USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500276INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100277EOF_CONF
278
279# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500280bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100281
Alanny Lopezd32d3322017-07-18 15:21:39 -0500282# Copy build directory of internal obmcdir into workspace directory
283cp -a ${obmcdir}/build/. ${WORKSPACE}/build/
Alanny Lopeze6870192017-04-24 15:25:59 -0500284
Chris Smart02651712015-11-11 11:09:00 +1100285EOF_SCRIPT
286
287chmod a+x ${WORKSPACE}/build.sh
288
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500289# Determine if the build container will be launched with Docker or Kubernetes
290if [[ "${launch}" == "" ]]; then
291
292 # Give the Docker image a name based on the distro,tag,arch,and target
293 imgname=${imgname:-openbmc/${distro}:${imgtag}-${target}-${ARCH}}
294
295 # Build the Docker image
296 docker build -t ${imgname} - <<< "${Dockerfile}"
297
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500298 # If obmcext or sscdir are ${HOME} or a subdirectory they will not be mounted
299 mountobmcext="-v ""${obmcext}"":""${obmcext}"" "
Alanny Lopez97a79502017-04-24 16:19:25 -0500300 mountsscdir="-v ""${sscdir}"":""${sscdir}"" "
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500301 if [[ "${obmcext}" = "${HOME}/"* || "${obmcext}" = "${HOME}" ]];then
302 mountobmcext=""
Alanny Lopez97a79502017-04-24 16:19:25 -0500303 fi
304 if [[ "${sscdir}" = "${HOME}/"* || "${sscdir}" = "${HOME}" ]];then
305 mountsscdir=""
306 fi
307
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500308 # Run the Docker container, execute the build.sh script
309 docker run \
310 --cap-add=sys_admin \
311 --net=host \
312 --rm=true \
313 -e WORKSPACE=${WORKSPACE} \
314 -w "${HOME}" \
315 -v "${HOME}":"${HOME}" \
Alanny Lopez7ec6d4d2017-06-09 09:43:01 -0500316 ${mountobmcext} \
Alanny Lopez97a79502017-04-24 16:19:25 -0500317 ${mountsscdir} \
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500318 -t ${imgname} \
319 ${WORKSPACE}/build.sh
320
321elif [[ "${launch}" == "job" || "${launch}" == "pod" ]]; then
322
323 # Source and run the helper script to launch the pod or job
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500324 . ./kubernetes/kubernetes-launch.sh OpenBMC-build true true
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500325
326else
327 echo "Launch Parameter is invalid"
328fi
Chris Smart02651712015-11-11 11:09:00 +1100329
Alanny Lopezd32d3322017-07-18 15:21:39 -0500330# To maintain function of resources that used an older path, add a link
331ln -sf ${WORKSPACE}/build/tmp/deploy ${WORKSPACE}/deploy
332
Chris Smart02651712015-11-11 11:09:00 +1100333# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500334echo "Build completed, $(date)"