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