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