1#!/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 18 PROXY="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[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} 35RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} 36 37USER ${USER} 38ENV HOME ${HOME} 39RUN /bin/bash 40EOF 41) 42 43# Build the docker container 44if ! docker build -t linux-build/ubuntu - <<< "${Dockerfile}" ; then 45 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 54mkdir -p "${WORKSPACE}" 55 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 70chmod a+x "${WORKSPACE}/build.sh" 71 72# Run the docker container, execute the build script we just built 73docker 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" 75