blob: 2230f66e786dc5e55f0ab797937d5b19ab957251 [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
7# distro = fedora|ubuntu
Andrew Geisslerc3c35202016-08-16 08:47:50 -05008# obmcdir = <name of openbmc src dir> (default openbmc)
9# WORKSPACE =
Chris Smart02651712015-11-11 11:09:00 +110010
Joel Stanley4b8b2392016-02-12 15:44:57 +103011# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103012set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110013
14# Default variables
15target=${target:-qemu}
16distro=${distro:-ubuntu}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050017obmcdir=${obmcdir:-openbmc}
Chris Smart02651712015-11-11 11:09:00 +110018WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
19http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110020PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110021
22# Timestamp for job
23echo "Build started, $(date)"
24
Andrew Geisslerc3c35202016-08-16 08:47:50 -050025# If there's no openbmc dir in WORKSPACE then just clone in master
26if [ ! -d ${WORKSPACE}/${obmcdir} ]; then
27 echo "Clone in openbmc master to ${WORKSPACE}/${obmcdir}"
28 git clone https://github.com/openbmc/openbmc ${WORKSPACE}/${obmcdir}
29fi
30
Chris Smart02651712015-11-11 11:09:00 +110031# Work out what build target we should be running and set bitbake command
32case ${target} in
33 barreleye)
34 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
35 ;;
36 palmetto)
37 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
38 ;;
Joel Stanley0e077202016-06-28 16:42:45 +093039 witherspoon)
40 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env"
41 ;;
42 firestone)
43 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env"
44 ;;
45 garrison)
46 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env"
47 ;;
48 evb-ast2500)
49 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env"
50 ;;
Chris Smart02651712015-11-11 11:09:00 +110051 qemu)
52 BITBAKE_CMD="source openbmc-env"
53 ;;
54 *)
55 exit 1
56 ;;
57esac
58
59# Configure docker build
60if [[ "${distro}" == fedora ]];then
61
62 if [[ -n "${http_proxy}" ]]; then
63 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
64 fi
65
66 Dockerfile=$(cat << EOF
67FROM fedora:latest
68
69${PROXY}
70
Chris Smartfc730ff2016-03-09 20:17:19 +110071RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110072 bzip2 \
73 chrpath \
74 cpio \
75 diffstat \
76 findutils \
77 gcc \
78 gcc-c++ \
79 git \
80 make \
81 patch \
82 perl-bignum \
83 perl-Data-Dumper \
84 perl-Thread-Queue \
85 python-devel \
86 SDL-devel \
87 socat \
88 subversion \
89 tar \
90 texinfo \
91 wget \
92 which
Chris Smart02651712015-11-11 11:09:00 +110093
Chris Smartd30c5902016-03-01 15:00:54 +110094RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
95RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +110096
97USER ${USER}
98ENV HOME ${HOME}
99RUN /bin/bash
100EOF
101)
102
103elif [[ "${distro}" == ubuntu ]]; then
104 if [[ -n "${http_proxy}" ]]; then
105 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
106 fi
107
108 Dockerfile=$(cat << EOF
109FROM ubuntu:latest
110
111${PROXY}
112
Chris Smart4593d4f2016-03-09 15:50:59 +1100113ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100114RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100115 build-essential \
116 chrpath \
117 debianutils \
118 diffstat \
119 gawk \
120 git \
121 libdata-dumper-simple-perl \
122 libsdl1.2-dev \
123 libthread-queue-any-perl \
124 python \
125 socat \
126 subversion \
127 texinfo \
128 wget
Chris Smart02651712015-11-11 11:09:00 +1100129
Chris Smartd30c5902016-03-01 15:00:54 +1100130RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
131RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
132
Chris Smart02651712015-11-11 11:09:00 +1100133USER ${USER}
134ENV HOME ${HOME}
135RUN /bin/bash
136EOF
137)
138fi
139
140# Build the docker container
141docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100142
143# Create the docker run script
144export PROXY_HOST=${http_proxy/#http*:\/\/}
145export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
146export PROXY_PORT=${http_proxy/#http*:\/\/*:}
147
Chris Smart01d2b962015-11-11 18:05:30 +1100148mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100149
Chris Smart01d2b962015-11-11 18:05:30 +1100150cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100151#!/bin/bash
152
Joel Stanley38c9d142016-02-16 12:31:55 +1030153set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100154
Chris Smart01d2b962015-11-11 18:05:30 +1100155cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100156
157# Go into the openbmc directory (the openbmc script will put us in a build subdir)
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500158cd ${obmcdir}
Chris Smart02651712015-11-11 11:09:00 +1100159
160# Set up proxies
161export ftp_proxy=${http_proxy}
162export http_proxy=${http_proxy}
163export https_proxy=${http_proxy}
164
Chris Smart01d2b962015-11-11 18:05:30 +1100165mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100166
167# Configure proxies for bitbake
168if [[ -n "${http_proxy}" ]]; then
169
Chris Smartd30c5902016-03-01 15:00:54 +1100170 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100171#!/bin/bash
172# \$1 = hostname, \$2 = port
173PROXY=${PROXY_HOST}
174PROXY_PORT=${PROXY_PORT}
175exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
176EOF_GIT
177
Chris Smart01d2b962015-11-11 18:05:30 +1100178 chmod a+x ${WORKSPACE}/bin/git-proxy
179 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100180 git config core.gitProxy git-proxy
181
182 mkdir -p ~/.subversion
183
184 cat > ~/.subversion/servers << EOF_SVN
185[global]
186http-proxy-host = ${PROXY_HOST}
187http-proxy-port = ${PROXY_PORT}
188EOF_SVN
189fi
190
191# Source our build env
192${BITBAKE_CMD}
193
194# Custom bitbake config settings
195cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100196BB_NUMBER_THREADS = "$(nproc)"
197PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100198INHERIT += "rm_work"
199BB_GENERATE_MIRROR_TARBALLS = "1"
200DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500201SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100202USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500203INHERIT_remove = "uninative"
Chris Smart02651712015-11-11 11:09:00 +1100204EOF_CONF
205
206# Kick off a build
207bitbake obmc-phosphor-image
208
209EOF_SCRIPT
210
211chmod a+x ${WORKSPACE}/build.sh
212
213# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100214docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
215 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100216
217# Create link to images for archiving
218ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
219
220# Timestamp for build
221echo "Build completed, $(date)"
222