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	bison \
36	flex
37
38RUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
39	dwarves \
40	sparse
41
42RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
43RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
44
45USER ${USER}
46ENV HOME ${HOME}
47RUN /bin/bash
48EOF
49)
50
51# Build the docker container
52docker build -t trace-linux-build/ubuntu - <<< "${Dockerfile}"
53if [[ "$?" -ne 0 ]]; then
54  echo "Failed to build docker container."
55  exit 1
56fi
57
58# Create the docker run script
59export PROXY_HOST=${http_proxy/#http*:\/\/}
60export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
61export PROXY_PORT=${http_proxy/#http*:\/\/*:}
62
63mkdir -p ${WORKSPACE}
64
65cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
66#!/bin/bash
67
68set -xe
69
70cd ${WORKSPACE}
71
72# Go into the linux directory (the script will put us in a build subdir)
73cd linux
74
75# Record the version in the logs
76powerpc64le-linux-gnu-gcc --version
77
78# Build kernel prep
79ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper
80
81# Generate the config
82echo "CONFIG_PPC_PSERIES=y" >> fragment.config
83echo "CONFIG_PPC_POWERNV=y" >> fragment.config
84echo "CONFIG_MTD=y" >> fragment.config
85echo "CONFIG_MTD_BLOCK=y" >> fragment.config
86echo "CONFIG_MTD_POWERNV_FLASH=y" >> fragment.config
87ARCH=powerpc scripts/kconfig/merge_config.sh \
88    arch/powerpc/configs/ppc64_defconfig \
89    arch/powerpc/configs/le.config \
90    fragment.config
91
92# Ensure config is up to date and no questions will be asked
93yes "" | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make oldconfig
94
95# Build kernel
96ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) vmlinux
97
98EOF_SCRIPT
99
100chmod a+x ${WORKSPACE}/build.sh
101
102# Run the docker container, execute the build script we just built
103docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
104  -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" -t trace-linux-build/ubuntu ${WORKSPACE}/build.sh
105
106result=${?}
107
108# Timestamp for build
109echo "Build completed, $(date)"
110
111exit ${result}
112