blob: d0a6fc2355a9206eab71f832a206a45e33cf7dfc [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
11set -xeuo 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:-}
18
19# Timestamp for job
20echo "Build started, $(date)"
21
22# Work out what build target we should be running and set bitbake command
23case ${target} in
24 barreleye)
25 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env"
26 ;;
27 palmetto)
28 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env"
29 ;;
30 qemu)
31 BITBAKE_CMD="source openbmc-env"
32 ;;
33 *)
34 exit 1
35 ;;
36esac
37
38# Configure docker build
39if [[ "${distro}" == fedora ]];then
40
41 if [[ -n "${http_proxy}" ]]; then
42 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
43 fi
44
45 Dockerfile=$(cat << EOF
46FROM fedora:latest
47
48${PROXY}
49
50RUN dnf --refresh upgrade -y
51RUN dnf install -y git subversion gcc gcc-c++ make perl-Thread-Queue perl-Data-Dumper diffstat texinfo \
52chrpath wget SDL-devel patch bzip2 tar cpio findutils socat which python-devel perl-bignum
53
54RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
55
56USER ${USER}
57ENV HOME ${HOME}
58RUN /bin/bash
59EOF
60)
61
62elif [[ "${distro}" == ubuntu ]]; then
63 if [[ -n "${http_proxy}" ]]; then
64 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
65 fi
66
67 Dockerfile=$(cat << EOF
68FROM ubuntu:latest
69
70${PROXY}
71
Chris Smart1a0dda42016-01-07 17:32:49 +110072#RUN echo $(date +%s) && apt-get update
73RUN apt-get update
Chris Smart72682352015-11-11 18:53:03 +110074RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
Chris Smart02651712015-11-11 11:09:00 +110075RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential git subversion diffstat texinfo \
76 chrpath wget libthread-queue-any-perl libdata-dumper-simple-perl python libsdl1.2-dev gawk socat debianutils
77
78RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
79
80USER ${USER}
81ENV HOME ${HOME}
82RUN /bin/bash
83EOF
84)
85fi
86
87# Build the docker container
88docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +110089
90# Create the docker run script
91export PROXY_HOST=${http_proxy/#http*:\/\/}
92export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
93export PROXY_PORT=${http_proxy/#http*:\/\/*:}
94
Chris Smart01d2b962015-11-11 18:05:30 +110095mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +110096
Chris Smart01d2b962015-11-11 18:05:30 +110097cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +110098#!/bin/bash
99
Joel Stanley4b8b2392016-02-12 15:44:57 +1030100set -xeuo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100101
Chris Smart01d2b962015-11-11 18:05:30 +1100102cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100103
104# Go into the openbmc directory (the openbmc script will put us in a build subdir)
105cd openbmc
106
107# Set up proxies
108export ftp_proxy=${http_proxy}
109export http_proxy=${http_proxy}
110export https_proxy=${http_proxy}
111
Chris Smart01d2b962015-11-11 18:05:30 +1100112mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100113
114# Configure proxies for bitbake
115if [[ -n "${http_proxy}" ]]; then
116
Chris Smart01d2b962015-11-11 18:05:30 +1100117 cat > ${WORKSPACE}/bin/git-proxy << EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100118#!/bin/bash
119# \$1 = hostname, \$2 = port
120PROXY=${PROXY_HOST}
121PROXY_PORT=${PROXY_PORT}
122exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
123EOF_GIT
124
Chris Smart01d2b962015-11-11 18:05:30 +1100125 chmod a+x ${WORKSPACE}/bin/git-proxy
126 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100127 git config core.gitProxy git-proxy
128
129 mkdir -p ~/.subversion
130
131 cat > ~/.subversion/servers << EOF_SVN
132[global]
133http-proxy-host = ${PROXY_HOST}
134http-proxy-port = ${PROXY_PORT}
135EOF_SVN
136fi
137
138# Source our build env
139${BITBAKE_CMD}
140
141# Custom bitbake config settings
142cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100143BB_NUMBER_THREADS = "$(nproc)"
144PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100145INHERIT += "rm_work"
146BB_GENERATE_MIRROR_TARBALLS = "1"
147DL_DIR="${HOME}/bitbake_downloads"
Chris Smart02651712015-11-11 11:09:00 +1100148USER_CLASSES += "buildstats"
149EOF_CONF
150
151# Kick off a build
152bitbake obmc-phosphor-image
153
154EOF_SCRIPT
155
156chmod a+x ${WORKSPACE}/build.sh
157
158# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100159docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
160 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100161
162# Create link to images for archiving
163ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
164
165# Timestamp for build
166echo "Build completed, $(date)"
167