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