Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This build script is for running the Jenkins builds using docker. |
| 4 | # |
| 5 | # It expects a variable as part of Jenkins build job matrix: |
| 6 | # distro = fedora|ubuntu |
| 7 | # WORKSPACE = |
| 8 | |
| 9 | # Trace bash processing |
| 10 | set -x |
| 11 | |
| 12 | # Default variables |
| 13 | distro=${distro:-ubuntu} |
| 14 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 15 | http_proxy=${http_proxy:-} |
| 16 | |
| 17 | # Timestamp for job |
| 18 | echo "Build started, $(date)" |
| 19 | |
| 20 | # Configure docker build |
| 21 | if [[ "${distro}" == fedora ]];then |
| 22 | |
| 23 | if [[ -n "${http_proxy}" ]]; then |
| 24 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 25 | fi |
| 26 | |
| 27 | Dockerfile=$(cat << EOF |
| 28 | FROM fedora:latest |
| 29 | |
| 30 | ${PROXY} |
| 31 | |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 32 | RUN dnf --refresh install -y \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 33 | bc \ |
| 34 | findutils \ |
| 35 | git \ |
| 36 | gcc \ |
| 37 | gcc-arm-linux-gnu \ |
| 38 | hostname \ |
| 39 | make \ |
| 40 | uboot-tools xz |
| 41 | |
| 42 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 43 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 44 | |
| 45 | USER ${USER} |
| 46 | ENV HOME ${HOME} |
| 47 | RUN /bin/bash |
| 48 | EOF |
| 49 | ) |
| 50 | |
| 51 | elif [[ "${distro}" == ubuntu ]]; then |
| 52 | if [[ -n "${http_proxy}" ]]; then |
| 53 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 54 | fi |
| 55 | |
| 56 | Dockerfile=$(cat << EOF |
| 57 | FROM ubuntu:latest |
| 58 | |
| 59 | ${PROXY} |
| 60 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 61 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 62 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 63 | bc \ |
| 64 | build-essential \ |
| 65 | git \ |
| 66 | gcc-arm-none-eabi \ |
| 67 | u-boot-tools |
| 68 | |
| 69 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 70 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 71 | |
| 72 | USER ${USER} |
| 73 | ENV HOME ${HOME} |
| 74 | RUN /bin/bash |
| 75 | EOF |
| 76 | ) |
| 77 | fi |
| 78 | |
| 79 | # Build the docker container |
| 80 | docker build -t linux-aspeed/${distro} - <<< "${Dockerfile}" |
| 81 | if [[ "$?" -ne 0 ]]; then |
| 82 | echo "Failed to build docker container." |
| 83 | exit 1 |
| 84 | fi |
| 85 | |
| 86 | # Create the docker run script |
| 87 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 88 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 89 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 90 | |
| 91 | mkdir -p ${WORKSPACE} |
| 92 | |
| 93 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 94 | #!/bin/bash |
| 95 | |
| 96 | set -x |
| 97 | |
| 98 | cd ${WORKSPACE} |
| 99 | |
| 100 | # Go into the linux-aspeed directory (the script will put us in a build subdir) |
| 101 | cd linux-aspeed |
| 102 | |
| 103 | # Configure a build |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 104 | if [ "${distro}" == "fedora" ]; then |
| 105 | CROSS_COMPILER="arm-linux-gnu-" |
| 106 | else |
| 107 | CROSS_COMPILER="arm-none-eabi-" |
| 108 | fi |
| 109 | |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 110 | # Record the version in the logs |
Joel Stanley | b97b530 | 2015-11-19 09:57:58 +1030 | [diff] [blame] | 111 | $\{CROSS_COMPILER}gcc --version |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 112 | |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 113 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig |
| 114 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4)) |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 115 | |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 116 | # build palmetto image |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 117 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 118 | cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb > palmetto-zimage |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 119 | ./scripts/mkuboot.sh -A arm -O linux -C none -T kernel -a 0x40008000 -e 0x40008000 -d-e 0x40008000 -n obmc-palm-\$(date +%Y%m%d%H%M) -d palmetto-zimage uImage.palmetto |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 120 | |
| 121 | EOF_SCRIPT |
| 122 | |
| 123 | chmod a+x ${WORKSPACE}/build.sh |
| 124 | |
| 125 | # Run the docker container, execute the build script we just built |
| 126 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 127 | -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-aspeed/${distro} ${WORKSPACE}/build.sh |
| 128 | |
| 129 | # Timestamp for build |
| 130 | echo "Build completed, $(date)" |
| 131 | |