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 |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 18 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
Joel Stanley | be53a68 | 2016-06-21 23:38:56 +0930 | [diff] [blame] | 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 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 30 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 31 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Joel Stanley | be53a68 | 2016-06-21 23:38:56 +0930 | [diff] [blame] | 32 | |
| 33 | USER ${USER} |
| 34 | ENV HOME ${HOME} |
| 35 | RUN /bin/bash |
| 36 | EOF |
| 37 | ) |
| 38 | |
| 39 | # Build the docker container |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 40 | if ! docker build -t u-boot-build/ubuntu - <<< "${Dockerfile}" ; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 41 | echo "Failed to build docker container." |
| 42 | exit 1 |
Joel Stanley | be53a68 | 2016-06-21 23:38:56 +0930 | [diff] [blame] | 43 | fi |
| 44 | |
| 45 | # Create the docker run script |
| 46 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 47 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 48 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 49 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 50 | mkdir -p "${WORKSPACE}" |
Joel Stanley | be53a68 | 2016-06-21 23:38:56 +0930 | [diff] [blame] | 51 | |
| 52 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 53 | #!/bin/bash |
| 54 | |
| 55 | set -x |
| 56 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 57 | cd "${WORKSPACE}" |
Joel Stanley | be53a68 | 2016-06-21 23:38:56 +0930 | [diff] [blame] | 58 | |
| 59 | gcc --version |
| 60 | arm-linux-gnueabi-gcc --version |
| 61 | |
| 62 | # Go into the source directory (the script will put us in a build subdir) |
| 63 | cd u-boot |
| 64 | CROSS_COMPILE=arm-linux-gnueabi- make ${BOARD_DEFCONFIG} |
| 65 | CROSS_COMPILE=arm-linux-gnueabi- make |
| 66 | |
| 67 | EOF_SCRIPT |
| 68 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 69 | chmod a+x "${WORKSPACE}"/build.sh |
Joel Stanley | be53a68 | 2016-06-21 23:38:56 +0930 | [diff] [blame] | 70 | |
| 71 | # Run the docker container, execute the build script we just built |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 72 | docker run --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 73 | -w "${HOME}" -v "${HOME}":"${HOME}" -t u-boot-build/ubuntu \ |
| 74 | "${WORKSPACE}"/build.sh |