blob: 500911469d3e5f70c95e4756b73dc61717e1754c [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
51RUN dnf --refresh upgrade -y
52RUN dnf install -y git subversion gcc gcc-c++ make perl-Thread-Queue perl-Data-Dumper diffstat texinfo \
53chrpath wget SDL-devel patch bzip2 tar cpio findutils socat which python-devel perl-bignum
54
55RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
56
57USER ${USER}
58ENV HOME ${HOME}
59RUN /bin/bash
60EOF
61)
62
63elif [[ "${distro}" == ubuntu ]]; then
64 if [[ -n "${http_proxy}" ]]; then
65 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
66 fi
67
68 Dockerfile=$(cat << EOF
69FROM ubuntu:latest
70
71${PROXY}
72
Chris Smart1a0dda42016-01-07 17:32:49 +110073#RUN echo $(date +%s) && apt-get update
74RUN apt-get update
Chris Smart72682352015-11-11 18:53:03 +110075RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
Chris Smart02651712015-11-11 11:09:00 +110076RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential git subversion diffstat texinfo \
77 chrpath wget libthread-queue-any-perl libdata-dumper-simple-perl python libsdl1.2-dev gawk socat debianutils
78
79RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
80
81USER ${USER}
82ENV HOME ${HOME}
83RUN /bin/bash
84EOF
85)
86fi
87
88# Build the docker container
89docker build -t openbmc/${distro} - <<< "${Dockerfile}"
Chris Smart02651712015-11-11 11:09:00 +110090
91# Create the docker run script
92export PROXY_HOST=${http_proxy/#http*:\/\/}
93export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
94export PROXY_PORT=${http_proxy/#http*:\/\/*:}
95
Chris Smart01d2b962015-11-11 18:05:30 +110096mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +110097
Chris Smart01d2b962015-11-11 18:05:30 +110098cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +110099#!/bin/bash
100
Joel Stanley38c9d142016-02-16 12:31:55 +1030101set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100102
Chris Smart01d2b962015-11-11 18:05:30 +1100103cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100104
105# Go into the openbmc directory (the openbmc script will put us in a build subdir)
106cd openbmc
107
108# Set up proxies
109export ftp_proxy=${http_proxy}
110export http_proxy=${http_proxy}
111export https_proxy=${http_proxy}
112
Chris Smart01d2b962015-11-11 18:05:30 +1100113mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100114
115# Configure proxies for bitbake
116if [[ -n "${http_proxy}" ]]; then
117
Chris Smart01d2b962015-11-11 18:05:30 +1100118 cat > ${WORKSPACE}/bin/git-proxy << EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100119#!/bin/bash
120# \$1 = hostname, \$2 = port
121PROXY=${PROXY_HOST}
122PROXY_PORT=${PROXY_PORT}
123exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
124EOF_GIT
125
Chris Smart01d2b962015-11-11 18:05:30 +1100126 chmod a+x ${WORKSPACE}/bin/git-proxy
127 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100128 git config core.gitProxy git-proxy
129
130 mkdir -p ~/.subversion
131
132 cat > ~/.subversion/servers << EOF_SVN
133[global]
134http-proxy-host = ${PROXY_HOST}
135http-proxy-port = ${PROXY_PORT}
136EOF_SVN
137fi
138
139# Source our build env
140${BITBAKE_CMD}
141
142# Custom bitbake config settings
143cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100144BB_NUMBER_THREADS = "$(nproc)"
145PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100146INHERIT += "rm_work"
147BB_GENERATE_MIRROR_TARBALLS = "1"
148DL_DIR="${HOME}/bitbake_downloads"
Chris Smart02651712015-11-11 11:09:00 +1100149USER_CLASSES += "buildstats"
150EOF_CONF
151
152# Kick off a build
153bitbake obmc-phosphor-image
154
155EOF_SCRIPT
156
157chmod a+x ${WORKSPACE}/build.sh
158
159# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100160docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
161 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100162
163# Create link to images for archiving
164ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
165
166# Timestamp for build
167echo "Build completed, $(date)"
168