1*f9ad3f9eSChris Smart#!/bin/bash 2*f9ad3f9eSChris Smart 3*f9ad3f9eSChris Smart# This build script is for running the Jenkins builds using docker. 4*f9ad3f9eSChris Smart# 5*f9ad3f9eSChris Smart 6*f9ad3f9eSChris Smart# Trace bash processing 7*f9ad3f9eSChris Smart#set -x 8*f9ad3f9eSChris Smart 9*f9ad3f9eSChris Smart# Default variables 10*f9ad3f9eSChris SmartWORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} 11*f9ad3f9eSChris Smarthttp_proxy=${http_proxy:-} 12*f9ad3f9eSChris Smart 13*f9ad3f9eSChris Smart# Timestamp for job 14*f9ad3f9eSChris Smartecho "Build started, $(date)" 15*f9ad3f9eSChris Smart 16*f9ad3f9eSChris Smart# Configure docker build 17*f9ad3f9eSChris Smartif [[ -n "${http_proxy}" ]]; then 18*f9ad3f9eSChris SmartPROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 19*f9ad3f9eSChris Smartfi 20*f9ad3f9eSChris Smart 21*f9ad3f9eSChris SmartDockerfile=$(cat << EOF 22*f9ad3f9eSChris SmartFROM ubuntu:15.10 23*f9ad3f9eSChris Smart 24*f9ad3f9eSChris Smart${PROXY} 25*f9ad3f9eSChris Smart 26*f9ad3f9eSChris SmartRUN echo $(date +%s) && apt-get update 27*f9ad3f9eSChris SmartRUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -yy 28*f9ad3f9eSChris SmartRUN DEBIAN_FRONTEND=noninteractive apt-get install -yy bc build-essential git gcc-powerpc64le-linux-gnu 29*f9ad3f9eSChris SmartRUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} 30*f9ad3f9eSChris Smart 31*f9ad3f9eSChris SmartUSER ${USER} 32*f9ad3f9eSChris SmartENV HOME ${HOME} 33*f9ad3f9eSChris SmartRUN /bin/bash 34*f9ad3f9eSChris SmartEOF 35*f9ad3f9eSChris Smart) 36*f9ad3f9eSChris Smart 37*f9ad3f9eSChris Smart# Build the docker container 38*f9ad3f9eSChris Smartdocker build -t linux-build/ubuntu - <<< "${Dockerfile}" 39*f9ad3f9eSChris Smartif [[ "$?" -ne 0 ]]; then 40*f9ad3f9eSChris Smart echo "Failed to build docker container." 41*f9ad3f9eSChris Smart exit 1 42*f9ad3f9eSChris Smartfi 43*f9ad3f9eSChris Smart 44*f9ad3f9eSChris Smart# Create the docker run script 45*f9ad3f9eSChris Smartexport PROXY_HOST=${http_proxy/#http*:\/\/} 46*f9ad3f9eSChris Smartexport PROXY_HOST=${PROXY_HOST/%:[0-9]*} 47*f9ad3f9eSChris Smartexport PROXY_PORT=${http_proxy/#http*:\/\/*:} 48*f9ad3f9eSChris Smart 49*f9ad3f9eSChris Smartmkdir -p ${WORKSPACE} 50*f9ad3f9eSChris Smart 51*f9ad3f9eSChris Smartcat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 52*f9ad3f9eSChris Smart#!/bin/bash 53*f9ad3f9eSChris Smart 54*f9ad3f9eSChris Smartset -x 55*f9ad3f9eSChris Smart 56*f9ad3f9eSChris Smartcd ${WORKSPACE} 57*f9ad3f9eSChris Smart 58*f9ad3f9eSChris Smart# Go into the linux directory (the script will put us in a build subdir) 59*f9ad3f9eSChris Smartcd linux 60*f9ad3f9eSChris Smart 61*f9ad3f9eSChris Smart# Record the version in the logs 62*f9ad3f9eSChris Smartpowerpc64le-linux-gnu-gcc --version || exit 1 63*f9ad3f9eSChris Smart 64*f9ad3f9eSChris Smart# Build kernel 65*f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean || exit 1 66*f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper || exit 1 67*f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1 68*f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) || exit 1 69*f9ad3f9eSChris Smart 70*f9ad3f9eSChris SmartEOF_SCRIPT 71*f9ad3f9eSChris Smart 72*f9ad3f9eSChris Smartchmod a+x ${WORKSPACE}/build.sh 73*f9ad3f9eSChris Smart 74*f9ad3f9eSChris Smart# Run the docker container, execute the build script we just built 75*f9ad3f9eSChris Smartdocker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ 76*f9ad3f9eSChris Smart -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh 77*f9ad3f9eSChris Smart 78*f9ad3f9eSChris Smart# Timestamp for build 79*f9ad3f9eSChris Smartecho "Build completed, $(date)" 80*f9ad3f9eSChris Smart 81