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 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:15.10 23 24${PROXY} 25 26# If we need to fetch new apt repo data, update the timestamp 27RUN echo 201603031716 && apt-get update 28RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -yy 29RUN DEBIAN_FRONTEND=noninteractive apt-get install -yy bc build-essential git gcc-powerpc64le-linux-gnu 30RUN DEBIAN_FRONTEND=noninteractive apt-get install -yy software-properties-common 31RUN apt-add-repository -y multiverse 32# If we need to fetch new apt repo data, update the timestamp 33RUN echo 201603031716 && apt-get update 34RUN apt-get update 35RUN DEBIAN_FRONTEND=noninteractive apt-get install -yy dwarves sparse 36RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} 37 38USER ${USER} 39ENV HOME ${HOME} 40RUN /bin/bash 41EOF 42) 43 44# Build the docker container 45docker build -t linux-build/ubuntu - <<< "${Dockerfile}" 46if [[ "$?" -ne 0 ]]; then 47 echo "Failed to build docker container." 48 exit 1 49fi 50 51# Create the docker run script 52export PROXY_HOST=${http_proxy/#http*:\/\/} 53export PROXY_HOST=${PROXY_HOST/%:[0-9]*} 54export PROXY_PORT=${http_proxy/#http*:\/\/*:} 55 56mkdir -p ${WORKSPACE} 57 58cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 59#!/bin/bash 60 61set -x 62 63cd ${WORKSPACE} 64 65# Go into the linux directory (the script will put us in a build subdir) 66cd linux 67 68# Record the version in the logs 69powerpc64le-linux-gnu-gcc --version || exit 1 70 71# Build kernel prep 72ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean || exit 1 73ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper || exit 1 74 75# Build kernel with debug 76ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1 77echo "CONFIG_DEBUG_INFO=y" >> .config 78ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig || exit 1 79ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz 80pahole vmlinux 2>&1 | gzip > structs.dump.gz 81 82# Build kernel 83ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1 84ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) || exit 1 85 86EOF_SCRIPT 87 88chmod a+x ${WORKSPACE}/build.sh 89 90# Run the docker container, execute the build script we just built 91docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ 92 -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh 93 94# Timestamp for build 95echo "Build completed, $(date)" 96 97