1#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4
5# Trace bash processing
6set -x
7
8# Default variables
9WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
10BOARD_DEFCONFIG=${BOARD_DEFCONFIG:-ast_g5_defconfig}
11http_proxy=${http_proxy:-}
12
13# Timestamp for job
14echo "Build started, $(date)"
15
16# Configure docker build
17if [[ -n "${http_proxy}" ]]; then
18    PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
19fi
20
21Dockerfile=$(cat << EOF
22FROM ubuntu:16.04
23
24${PROXY}
25
26ENV DEBIAN_FRONTEND noninteractive
27RUN apt-get update && apt-get install -yy \
28	make bc gcc gcc-arm-linux-gnueabi
29
30RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
31RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
32
33USER ${USER}
34ENV HOME ${HOME}
35RUN /bin/bash
36EOF
37)
38
39# Build the docker container
40if ! docker build -t u-boot-build/ubuntu - <<< "${Dockerfile}" ; then
41    echo "Failed to build docker container."
42    exit 1
43fi
44
45# Create the docker run script
46export PROXY_HOST=${http_proxy/#http*:\/\/}
47export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
48export PROXY_PORT=${http_proxy/#http*:\/\/*:}
49
50mkdir -p "${WORKSPACE}"
51
52cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
53#!/bin/bash
54
55set -x
56
57cd "${WORKSPACE}"
58
59gcc --version
60arm-linux-gnueabi-gcc --version
61
62# Go into the source directory (the script will put us in a build subdir)
63cd u-boot
64CROSS_COMPILE=arm-linux-gnueabi- make ${BOARD_DEFCONFIG}
65CROSS_COMPILE=arm-linux-gnueabi- make
66
67EOF_SCRIPT
68
69chmod a+x "${WORKSPACE}"/build.sh
70
71# Run the docker container, execute the build script we just built
72docker run --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \
73    -w "${HOME}" -v "${HOME}":"${HOME}" -t u-boot-build/ubuntu \
74    "${WORKSPACE}"/build.sh
75