blob: 5cc47239a50bbb3c850e359995da56156ed5d004 [file] [log] [blame]
Chris Smartf9ad3f92016-01-11 14:59:28 +11001#!/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
Joel Stanley5f4de952017-12-06 18:53:16 +103022FROM ubuntu:latest
Chris Smartf9ad3f92016-01-11 14:59:28 +110023
24${PROXY}
25
Chris Smart4593d4f2016-03-09 15:50:59 +110026ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110027RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110028 bc \
29 build-essential \
30 git \
31 gcc-powerpc64le-linux-gnu \
Saqib Khan5158a322017-10-23 11:31:24 -050032 software-properties-common \
Joel Stanley15a77ae2017-12-12 00:17:14 +103033 libssl-dev \
Saqib Khan5158a322017-10-23 11:31:24 -050034 iputils-ping
Chris Smart4593d4f2016-03-09 15:50:59 +110035
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}
Chris Smartf9ad3f92016-01-11 14:59:28 +110042
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
67
68cd ${WORKSPACE}
69
70# Go into the linux directory (the script will put us in a build subdir)
71cd linux
72
73# Record the version in the logs
74powerpc64le-linux-gnu-gcc --version || exit 1
75
Chris Smart78646622016-03-03 16:49:59 +110076# Build kernel prep
Chris Smartf9ad3f92016-01-11 14:59:28 +110077ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean || exit 1
78ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper || exit 1
Chris Smart78646622016-03-03 16:49:59 +110079
80# Build kernel with debug
81ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
82echo "CONFIG_DEBUG_INFO=y" >> .config
83ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig || exit 1
84ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
85pahole vmlinux 2>&1 | gzip > structs.dump.gz
86
87# Build kernel
Chris Smartf9ad3f92016-01-11 14:59:28 +110088ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
89ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) || exit 1
90
91EOF_SCRIPT
92
93chmod a+x ${WORKSPACE}/build.sh
94
95# Run the docker container, execute the build script we just built
96docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
Michael Ellerman3225cfc2017-12-12 13:35:00 +110097 -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
Chris Smartf9ad3f92016-01-11 14:59:28 +110098
Michael Ellerman6c69b7e2017-12-12 13:15:04 +110099result=${?}
100
Chris Smartf9ad3f92016-01-11 14:59:28 +1100101# Timestamp for build
102echo "Build completed, $(date)"
103
Michael Ellerman6c69b7e2017-12-12 13:15:04 +1100104exit ${result}