Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [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:15.10 |
| 23 | |
| 24 | ${PROXY} |
| 25 | |
| 26 | RUN echo $(date +%s) && apt-get update |
| 27 | RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -yy |
| 28 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -yy bc build-essential git gcc-powerpc64le-linux-gnu |
| 29 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 30 | |
| 31 | USER ${USER} |
| 32 | ENV HOME ${HOME} |
| 33 | RUN /bin/bash |
| 34 | EOF |
| 35 | ) |
| 36 | |
| 37 | # Build the docker container |
| 38 | docker build -t linux-build/ubuntu - <<< "${Dockerfile}" |
| 39 | if [[ "$?" -ne 0 ]]; then |
| 40 | echo "Failed to build docker container." |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | # Create the docker run script |
| 45 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 46 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 47 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 48 | |
| 49 | mkdir -p ${WORKSPACE} |
| 50 | |
| 51 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 52 | #!/bin/bash |
| 53 | |
| 54 | set -x |
| 55 | |
| 56 | cd ${WORKSPACE} |
| 57 | |
| 58 | # Go into the linux directory (the script will put us in a build subdir) |
| 59 | cd linux |
| 60 | |
| 61 | # Record the version in the logs |
| 62 | powerpc64le-linux-gnu-gcc --version || exit 1 |
| 63 | |
| 64 | # Build kernel |
| 65 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean || exit 1 |
| 66 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper || exit 1 |
| 67 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1 |
| 68 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) || exit 1 |
| 69 | |
| 70 | EOF_SCRIPT |
| 71 | |
| 72 | chmod a+x ${WORKSPACE}/build.sh |
| 73 | |
| 74 | # Run the docker container, execute the build script we just built |
| 75 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 76 | -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh |
| 77 | |
| 78 | # Timestamp for build |
| 79 | echo "Build completed, $(date)" |
| 80 | |