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