blob: 4b1b9194d0197667dbb74657991477ea8d65d3c6 [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
8# WORKSPACE =
9
Joel Stanley4b8b2392016-02-12 15:44:57 +103010# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103011set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110012
13# Default variables
14target=${target:-qemu}
15distro=${distro:-ubuntu}
16WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
17http_proxy=${http_proxy:-}
Chris Smartc3522542016-02-16 11:59:36 +110018PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110019
20# Timestamp for job
21echo "Build started, $(date)"
22
23# Work out what build target we should be running and set bitbake command
24case ${target} in
25 barreleye)
26 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
27 ;;
28 palmetto)
29 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
30 ;;
31 qemu)
32 BITBAKE_CMD="source openbmc-env"
33 ;;
34 *)
35 exit 1
36 ;;
37esac
38
39# Configure docker build
40if [[ "${distro}" == fedora ]];then
41
42 if [[ -n "${http_proxy}" ]]; then
43 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
44 fi
45
46 Dockerfile=$(cat << EOF
47FROM fedora:latest
48
49${PROXY}
50
Chris Smartfc730ff2016-03-09 20:17:19 +110051RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110052 bzip2 \
53 chrpath \
54 cpio \
55 diffstat \
56 findutils \
57 gcc \
58 gcc-c++ \
59 git \
60 make \
61 patch \
62 perl-bignum \
63 perl-Data-Dumper \
64 perl-Thread-Queue \
65 python-devel \
66 SDL-devel \
67 socat \
68 subversion \
69 tar \
70 texinfo \
71 wget \
72 which
Chris Smart02651712015-11-11 11:09:00 +110073
Chris Smartd30c5902016-03-01 15:00:54 +110074RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
75RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +110076
77USER ${USER}
78ENV HOME ${HOME}
79RUN /bin/bash
80EOF
81)
82
83elif [[ "${distro}" == ubuntu ]]; then
84 if [[ -n "${http_proxy}" ]]; then
85 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
86 fi
87
88 Dockerfile=$(cat << EOF
89FROM ubuntu:latest
90
91${PROXY}
92
Chris Smart4593d4f2016-03-09 15:50:59 +110093ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110094RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110095 build-essential \
96 chrpath \
97 debianutils \
98 diffstat \
99 gawk \
100 git \
101 libdata-dumper-simple-perl \
102 libsdl1.2-dev \
103 libthread-queue-any-perl \
104 python \
105 socat \
106 subversion \
107 texinfo \
108 wget
Chris Smart02651712015-11-11 11:09:00 +1100109
Chris Smartd30c5902016-03-01 15:00:54 +1100110RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
111RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
112
Chris Smart02651712015-11-11 11:09:00 +1100113USER ${USER}
114ENV HOME ${HOME}
115RUN /bin/bash
116EOF
117)
118fi
119
120# Build the docker container
121docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +1100122
123# Create the docker run script
124export PROXY_HOST=${http_proxy/#http*:\/\/}
125export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
126export PROXY_PORT=${http_proxy/#http*:\/\/*:}
127
Chris Smart01d2b962015-11-11 18:05:30 +1100128mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100129
Chris Smart01d2b962015-11-11 18:05:30 +1100130cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100131#!/bin/bash
132
Joel Stanley38c9d142016-02-16 12:31:55 +1030133set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100134
Chris Smart01d2b962015-11-11 18:05:30 +1100135cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100136
137# Go into the openbmc directory (the openbmc script will put us in a build subdir)
138cd openbmc
139
140# Set up proxies
141export ftp_proxy=${http_proxy}
142export http_proxy=${http_proxy}
143export https_proxy=${http_proxy}
144
Chris Smart01d2b962015-11-11 18:05:30 +1100145mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100146
147# Configure proxies for bitbake
148if [[ -n "${http_proxy}" ]]; then
149
Chris Smartd30c5902016-03-01 15:00:54 +1100150 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100151#!/bin/bash
152# \$1 = hostname, \$2 = port
153PROXY=${PROXY_HOST}
154PROXY_PORT=${PROXY_PORT}
155exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
156EOF_GIT
157
Chris Smart01d2b962015-11-11 18:05:30 +1100158 chmod a+x ${WORKSPACE}/bin/git-proxy
159 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100160 git config core.gitProxy git-proxy
161
162 mkdir -p ~/.subversion
163
164 cat > ~/.subversion/servers << EOF_SVN
165[global]
166http-proxy-host = ${PROXY_HOST}
167http-proxy-port = ${PROXY_PORT}
168EOF_SVN
169fi
170
171# Source our build env
172${BITBAKE_CMD}
173
174# Custom bitbake config settings
175cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100176BB_NUMBER_THREADS = "$(nproc)"
177PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100178INHERIT += "rm_work"
179BB_GENERATE_MIRROR_TARBALLS = "1"
180DL_DIR="${HOME}/bitbake_downloads"
Joel Stanley1dda0892016-06-06 16:09:56 -0500181SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100182USER_CLASSES += "buildstats"
183EOF_CONF
184
185# Kick off a build
186bitbake obmc-phosphor-image
187
188EOF_SCRIPT
189
190chmod a+x ${WORKSPACE}/build.sh
191
192# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100193docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
194 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100195
196# Create link to images for archiving
197ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
198
199# Timestamp for build
200echo "Build completed, $(date)"
201