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