blob: fad2d7bd7378ae7c1f7f6aa2041f8a39b02d3a66 [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
Andrew Geisslerc16868c2016-08-23 21:55:13 -05007# distro = fedora|ubuntu|ubuntu:14.04|ubuntu:16.04
Alanny Lopezeaa2eae2017-04-24 14:55:07 -05008# obmcdir = <name of OpenBMC src dir> (default openbmc)
9# 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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050011# 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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050026 DOCKER_BASE="ppc64le/"
Andrew Geissler11abbbe2016-08-14 19:39:47 -050027else
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050028 DOCKER_BASE=""
Andrew Geissler11abbbe2016-08-14 19:39:47 -050029fi
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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050036 echo "Clone in openbmc master to ${WORKSPACE}/${obmcdir}"
37 git clone https://github.com/openbmc/openbmc ${WORKSPACE}/${obmcdir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050038fi
39
Andrew Geisslerc16868c2016-08-23 21:55:13 -050040# if user just passed in ubuntu then use latest
41if [[ $distro == "ubuntu" ]]; then
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050042 distro="ubuntu:latest"
Andrew Geisslerc16868c2016-08-23 21:55:13 -050043fi
44
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050045# Work out what build target we should be running and set BitBake command
Chris Smart02651712015-11-11 11:09:00 +110046case ${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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050079# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +110080if [[ "${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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050087 FROM ${DOCKER_BASE}fedora:latest
Chris Smart02651712015-11-11 11:09:00 +110088
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050089 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +110090
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050091 # Set the locale
92 RUN locale-gen en_US.UTF-8
93 ENV LANG en_US.UTF-8
94 ENV LANGUAGE en_US:en
95 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -050096
Alanny Lopezeaa2eae2017-04-24 14:55:07 -050097 RUN dnf --refresh install -y \
98 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 \
112 python3-devel \
113 SDL-devel \
114 socat \
115 subversion \
116 tar \
117 texinfo \
118 wget \
119 which
Chris Smart02651712015-11-11 11:09:00 +1100120
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500121 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
122 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100123
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500124 USER ${USER}
125 ENV HOME ${HOME}
126 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100127EOF
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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500136 FROM ${DOCKER_BASE}${distro}
Chris Smart02651712015-11-11 11:09:00 +1100137
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500138 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100139
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500140 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500141
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500142 # Set the locale
143 RUN locale-gen en_US.UTF-8
144 ENV LANG en_US.UTF-8
145 ENV LANGUAGE en_US:en
146 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500147
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500148 RUN apt-get update && apt-get install -yy \
149 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 \
159 python3 \
160 socat \
161 subversion \
162 texinfo \
163 cpio \
164 wget
Chris Smart02651712015-11-11 11:09:00 +1100165
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500166 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
167 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100168
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500169 USER ${USER}
170 ENV HOME ${HOME}
171 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100172EOF
173)
174fi
175
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500176# Build the Docker container
Chris Smart02651712015-11-11 11:09:00 +1100177docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100178
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500179# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100180export 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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500193# 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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500203# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100204if [[ -n "${http_proxy}" ]]; then
205
Chris Smartd30c5902016-03-01 15:00:54 +1100206 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500207 #!/bin/bash
208 # \$1 = hostname, \$2 = port
209 PROXY=${PROXY_HOST}
210 PROXY_PORT=${PROXY_PORT}
211 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100212EOF_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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500221 [global]
222 http-proxy-host = ${PROXY_HOST}
223 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100224EOF_SVN
225fi
226
227# Source our build env
228${BITBAKE_CMD}
229
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500230# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100231cat >> 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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500249# 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
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500257echo "Build completed, $(date)"