blob: a98fd7c6604fbcdfad637401db3af5c655a4a6f3 [file] [log] [blame]
Jeremy Kerr1a163c32016-05-26 11:18:30 +08001#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4#
5
6# Trace bash processing
7set -x
8
9# Default variables
10WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
11http_proxy=${http_proxy:-}
12
13# Timestamp for job
14echo "Build started, $(date)"
15
16# Configure docker build
17if [[ -n "${http_proxy}" ]]; then
18PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
19fi
20
21Dockerfile=$(cat << EOF
22FROM ubuntu:16.04
23
24${PROXY}
25
26ENV DEBIAN_FRONTEND noninteractive
27RUN apt-get update && apt-get install -yy \
28 make \
29 texlive-xetex \
30 pandoc \
31 fonts-inconsolata \
32 fonts-linuxlibertine
33
34RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
35RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
36
37USER ${USER}
38ENV HOME ${HOME}
39RUN /bin/bash
40EOF
41)
42
43# Build the docker container
44docker build -t linux-build/ubuntu - <<< "${Dockerfile}"
45if [[ "$?" -ne 0 ]]; then
46 echo "Failed to build docker container."
47 exit 1
48fi
49
50# Create the docker run script
51export PROXY_HOST=${http_proxy/#http*:\/\/}
52export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
53export PROXY_PORT=${http_proxy/#http*:\/\/*:}
54
55mkdir -p ${WORKSPACE}
56
57cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
58#!/bin/bash
59
60set -x
61
62cd ${WORKSPACE}
63
64# Go into the linux directory (the script will put us in a build subdir)
65cd docs
66
67make
68
69EOF_SCRIPT
70
71chmod a+x ${WORKSPACE}/build.sh
72
73# Run the docker container, execute the build script we just built
74docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
75 -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh