blob: 1ad63ec3753fd2ee8fb93ba89774794d3916d2e5 [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
10# Trace bash processing
11set -x
12
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 Smart72682352015-11-11 18:53:03 +110072RUN echo $(date +%s) && apt-get update
73RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
Chris Smart02651712015-11-11 11:09:00 +110074RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential git subversion diffstat texinfo \
75 chrpath wget libthread-queue-any-perl libdata-dumper-simple-perl python libsdl1.2-dev gawk socat debianutils
76
77RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
78
79USER ${USER}
80ENV HOME ${HOME}
81RUN /bin/bash
82EOF
83)
84fi
85
86# Build the docker container
87docker build -t openbmc/${distro} - <<< "${Dockerfile}"
88if [[ "$?" -ne 0 ]]; then
89 echo "Failed to build docker container."
90 exit 1
91fi
92
93# Create the docker run script
94export PROXY_HOST=${http_proxy/#http*:\/\/}
95export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
96export PROXY_PORT=${http_proxy/#http*:\/\/*:}
97
Chris Smart01d2b962015-11-11 18:05:30 +110098mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +110099
Chris Smart01d2b962015-11-11 18:05:30 +1100100cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100101#!/bin/bash
102
103set -x
104
Chris Smart01d2b962015-11-11 18:05:30 +1100105cd ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100106
107# Go into the openbmc directory (the openbmc script will put us in a build subdir)
108cd openbmc
109
110# Set up proxies
111export ftp_proxy=${http_proxy}
112export http_proxy=${http_proxy}
113export https_proxy=${http_proxy}
114
Chris Smart01d2b962015-11-11 18:05:30 +1100115mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100116
117# Configure proxies for bitbake
118if [[ -n "${http_proxy}" ]]; then
119
Chris Smart01d2b962015-11-11 18:05:30 +1100120 cat > ${WORKSPACE}/bin/git-proxy << EOF_GIT
Chris Smart02651712015-11-11 11:09:00 +1100121#!/bin/bash
122# \$1 = hostname, \$2 = port
123PROXY=${PROXY_HOST}
124PROXY_PORT=${PROXY_PORT}
125exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
126EOF_GIT
127
Chris Smart01d2b962015-11-11 18:05:30 +1100128 chmod a+x ${WORKSPACE}/bin/git-proxy
129 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100130 git config core.gitProxy git-proxy
131
132 mkdir -p ~/.subversion
133
134 cat > ~/.subversion/servers << EOF_SVN
135[global]
136http-proxy-host = ${PROXY_HOST}
137http-proxy-port = ${PROXY_PORT}
138EOF_SVN
139fi
140
141# Source our build env
142${BITBAKE_CMD}
143
144# Custom bitbake config settings
145cat >> conf/local.conf << EOF_CONF
146BB_NUMBER_THREADS = "$(($(nproc) / 4))"
147PARALLEL_MAKE = "-j$(($(nproc) / 4))"
148INHERIT += "rm_work"
149BB_GENERATE_MIRROR_TARBALLS = "1"
150DL_DIR="${HOME}/bitbake_downloads"
151SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
152USER_CLASSES += "buildstats"
153EOF_CONF
154
155# Kick off a build
156bitbake obmc-phosphor-image
157
158EOF_SCRIPT
159
160chmod a+x ${WORKSPACE}/build.sh
161
162# Run the docker container, execute the build script we just built
Chris Smart01d2b962015-11-11 18:05:30 +1100163docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
164 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100165
166# Create link to images for archiving
167ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images
168
169# Timestamp for build
170echo "Build completed, $(date)"
171