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