1#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4
5# Trace bash processing
6set -x
7
8# Default variables
9WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
10http_proxy=${http_proxy:-}
11
12# Timestamp for job
13echo "Build started, $(date)"
14
15# Configure docker build
16if [[ -n "${http_proxy}" ]]; then
17PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
18fi
19
20Dockerfile=$(cat << EOF
21FROM ubuntu:16.04
22
23${PROXY}
24
25ENV DEBIAN_FRONTEND noninteractive
26RUN apt-get update && apt-get install -yy --no-install-recommends \
27    bison \
28    flex \
29    gcc \
30    git \
31    libc6-dev \
32    libfdt-dev \
33    libglib2.0-dev \
34    libpixman-1-dev \
35    make \
36    python-yaml \
37    python3-yaml
38
39RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
40RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
41
42USER ${USER}
43ENV HOME ${HOME}
44RUN /bin/bash
45EOF
46)
47
48# Build the docker container
49docker build -t qemu-build/ubuntu - <<< "${Dockerfile}"
50if [[ "$?" -ne 0 ]]; then
51  echo "Failed to build docker container."
52  exit 1
53fi
54
55# Create the docker run script
56export PROXY_HOST=${http_proxy/#http*:\/\/}
57export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
58export PROXY_PORT=${http_proxy/#http*:\/\/*:}
59
60mkdir -p ${WORKSPACE}
61
62cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
63#!/bin/bash
64
65set -x
66
67cd ${WORKSPACE}
68
69gcc --version
70
71# Go into the source directory (the script will put us in a build subdir)
72cd qemu
73# disable anything that requires us to pull in X
74./configure --target-list=arm-softmmu \
75	--disable-spice --disable-docs --disable-gtk --disable-smartcard \
76	--disable-usb-redir --disable-libusb --disable-sdl --disable-gnutls \
77	--disable-vte --disable-vnc --disable-vnc-png
78make -j4
79
80EOF_SCRIPT
81
82chmod a+x ${WORKSPACE}/build.sh
83
84# Run the docker container, execute the build script we just built
85docker run --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
86  -w "${HOME}" -v "${HOME}":"${HOME}" -t qemu-build/ubuntu ${WORKSPACE}/build.sh
87