blob: bcffc8d4d8f7b2843935883893dc41d2f4d7b623 [file] [log] [blame]
Chris Smart02651712015-11-11 11:09:00 +11001#!/bin/bash
2
Alanny Lopezeaa2eae2017-04-24 14:55:07 -05003# This build script is for running the Jenkins builds using Docker.
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 Lopezeaa2eae2017-04-24 14:55:07 -05009# obmcdir = <name of OpenBMC src dir> (default openbmc)
10# 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>
Chris Smart02651712015-11-11 11:09:00 +110013
Joel Stanley4b8b2392016-02-12 15:44:57 +103014# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103015set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110016
17# Default variables
18target=${target:-qemu}
19distro=${distro:-ubuntu}
Alanny Lopezccc650e2017-04-24 15:14:20 -050020imgtag=${imgtag:-latest}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050021obmcdir=${obmcdir:-openbmc}
Chris Smart02651712015-11-11 11:09:00 +110022WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
23http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110024PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110025
Alanny Lopezccc650e2017-04-24 15:14:20 -050026# Determine the architecture
27ARCH=$(uname -m)
28
29# Determine the prefix of the Dockerfile's base image
30case ${ARCH} in
31 "ppc64le")
32 DOCKER_BASE="ppc64le/"
33 ;;
34 "x86_64")
35 DOCKER_BASE=""
36 ;;
37 *)
38 echo "Unsupported system architecture(${ARCH}) found for docker image"
39 exit 1
40esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050041
Chris Smart02651712015-11-11 11:09:00 +110042# Timestamp for job
43echo "Build started, $(date)"
44
Andrew Geisslerc3c35202016-08-16 08:47:50 -050045# If there's no openbmc dir in WORKSPACE then just clone in master
46if [ ! -d ${WORKSPACE}/${obmcdir} ]; then
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050047 echo "Clone in openbmc master to ${WORKSPACE}/${obmcdir}"
48 git clone https://github.com/openbmc/openbmc ${WORKSPACE}/${obmcdir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050049fi
50
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050051# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +110052case ${target} in
53 barreleye)
54 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
55 ;;
56 palmetto)
57 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
58 ;;
Joel Stanley0e077202016-06-28 16:42:45 +093059 witherspoon)
60 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
61 ;;
62 firestone)
63 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
64 ;;
65 garrison)
66 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
67 ;;
68 evb-ast2500)
69 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
70 ;;
Joel Stanley915381f2016-11-01 16:58:59 +103071 zaius)
72 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/conf source oe-init-build-env"
73 ;;
74 romulus)
75 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-romulus/conf source oe-init-build-env"
76 ;;
Chris Smart02651712015-11-11 11:09:00 +110077 qemu)
78 BITBAKE_CMD="source openbmc-env"
79 ;;
80 *)
81 exit 1
82 ;;
83esac
84
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050085# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +110086if [[ "${distro}" == fedora ]];then
87
88 if [[ -n "${http_proxy}" ]]; then
89 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
90 fi
91
92 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -050093 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +110094
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050095 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +110096
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050097 # Set the locale
98 RUN locale-gen en_US.UTF-8
99 ENV LANG en_US.UTF-8
100 ENV LANGUAGE en_US:en
101 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500102
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500103 RUN dnf --refresh install -y \
104 bzip2 \
105 chrpath \
106 cpio \
107 diffstat \
108 findutils \
109 gcc \
110 gcc-c++ \
111 git \
112 make \
113 patch \
114 perl-bignum \
115 perl-Data-Dumper \
116 perl-Thread-Queue \
117 python-devel \
118 python3-devel \
119 SDL-devel \
120 socat \
121 subversion \
122 tar \
123 texinfo \
124 wget \
125 which
Chris Smart02651712015-11-11 11:09:00 +1100126
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500127 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
128 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100129
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500130 USER ${USER}
131 ENV HOME ${HOME}
132 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100133EOF
134)
135
Alanny Lopezccc650e2017-04-24 15:14:20 -0500136elif [[ "${distro}" == ubuntu ]]; then
137
Chris Smart02651712015-11-11 11:09:00 +1100138 if [[ -n "${http_proxy}" ]]; then
139 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
140 fi
141
142 Dockerfile=$(cat << EOF
Alanny Lopezccc650e2017-04-24 15:14:20 -0500143 FROM ${DOCKER_BASE}${distro}:${imgtag}
Chris Smart02651712015-11-11 11:09:00 +1100144
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500145 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100146
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500147 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500148
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500149 # Set the locale
150 RUN locale-gen en_US.UTF-8
151 ENV LANG en_US.UTF-8
152 ENV LANGUAGE en_US:en
153 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500154
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500155 RUN apt-get update && apt-get install -yy \
156 build-essential \
157 chrpath \
158 debianutils \
159 diffstat \
160 gawk \
161 git \
162 libdata-dumper-simple-perl \
163 libsdl1.2-dev \
164 libthread-queue-any-perl \
165 python \
166 python3 \
167 socat \
168 subversion \
169 texinfo \
170 cpio \
171 wget
Chris Smart02651712015-11-11 11:09:00 +1100172
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500173 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
174 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100175
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500176 USER ${USER}
177 ENV HOME ${HOME}
178 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100179EOF
180)
181fi
182
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500183# Build the Docker container
Alanny Lopezccc650e2017-04-24 15:14:20 -0500184docker build -t openbmc/${distro}:${imgtag}-${ARCH} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100185
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500186# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100187export PROXY_HOST=${http_proxy/#http*:\/\/}
188export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
189export PROXY_PORT=${http_proxy/#http*:\/\/*:}
190
Chris Smart01d2b962015-11-11 18:05:30 +1100191mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100192
Chris Smart01d2b962015-11-11 18:05:30 +1100193cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100194#!/bin/bash
195
Joel Stanley38c9d142016-02-16 12:31:55 +1030196set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100197
Chris Smart01d2b962015-11-11 18:05:30 +1100198cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100199
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500200# Go into the OpenBMC directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500201cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100202
203# Set up proxies
204export ftp_proxy=${http_proxy}
205export http_proxy=${http_proxy}
206export https_proxy=${http_proxy}
207
Chris Smart01d2b962015-11-11 18:05:30 +1100208mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100209
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500210# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100211if [[ -n "${http_proxy}" ]]; then
212
Chris Smartd30c5902016-03-01 15:00:54 +1100213 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500214 #!/bin/bash
215 # \$1 = hostname, \$2 = port
216 PROXY=${PROXY_HOST}
217 PROXY_PORT=${PROXY_PORT}
218 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100219EOF_GIT
220
Chris Smart01d2b962015-11-11 18:05:30 +1100221 chmod a+x ${WORKSPACE}/bin/git-proxy
222 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100223 git config core.gitProxy git-proxy
224
225 mkdir -p ~/.subversion
226
227 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500228 [global]
229 http-proxy-host = ${PROXY_HOST}
230 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100231EOF_SVN
232fi
233
234# Source our build env
235${BITBAKE_CMD}
236
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500237# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100238cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100239BB_NUMBER_THREADS = "$(nproc)"
240PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100241INHERIT += "rm_work"
242BB_GENERATE_MIRROR_TARBALLS = "1"
243DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500244SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100245USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500246INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100247EOF_CONF
248
249# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500250bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100251
252EOF_SCRIPT
253
254chmod a+x ${WORKSPACE}/build.sh
255
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500256# Run the Docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100257docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
Alanny Lopezccc650e2017-04-24 15:14:20 -0500258 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro}:${imgtag}-${ARCH} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100259
260# Create link to images for archiving
261ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
262
263# Timestamp for build
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500264echo "Build completed, $(date)"