blob: b0f06f8643db009ccbf8b2b541f26f1f5177639d [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
Patrick Williams384d7412020-11-06 16:15:41 -060026ENV DEBIAN_FRONTEND noninteractive
Jeremy Kerr1a163c32016-05-26 11:18:30 +080027RUN apt-get update && apt-get install -yy \
28 make \
29 texlive-xetex \
30 pandoc \
31 fonts-inconsolata \
32 fonts-linuxlibertine
33
Patrick Williams384d7412020-11-06 16:15:41 -060034RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
35RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Jeremy Kerr1a163c32016-05-26 11:18:30 +080036
37USER ${USER}
38ENV HOME ${HOME}
39RUN /bin/bash
40EOF
41)
42
43# Build the docker container
Patrick Williams384d7412020-11-06 16:15:41 -060044if ! docker build -t linux-build/ubuntu - <<< "${Dockerfile}" ; then
Jeremy Kerr1a163c32016-05-26 11:18:30 +080045 echo "Failed to build docker container."
46 exit 1
47fi
48
49# Create the docker run script
50export PROXY_HOST=${http_proxy/#http*:\/\/}
51export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
52export PROXY_PORT=${http_proxy/#http*:\/\/*:}
53
Patrick Williams384d7412020-11-06 16:15:41 -060054mkdir -p "${WORKSPACE}"
Jeremy Kerr1a163c32016-05-26 11:18:30 +080055
56cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
57#!/bin/bash
58
59set -x
60
61cd ${WORKSPACE}
62
63# Go into the linux directory (the script will put us in a build subdir)
64cd docs
65
66make
67
68EOF_SCRIPT
69
Patrick Williams384d7412020-11-06 16:15:41 -060070chmod a+x "${WORKSPACE}/build.sh"
Jeremy Kerr1a163c32016-05-26 11:18:30 +080071
72# Run the docker container, execute the build script we just built
Patrick Williams384d7412020-11-06 16:15:41 -060073docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \
74 -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu "${WORKSPACE}/build.sh"