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 | |
| 32 | RUN dnf --refresh upgrade -y |
| 33 | RUN dnf install -y git gcc make uboot-tools gcc-arm-linux-gnu |
| 34 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 35 | |
| 36 | USER ${USER} |
| 37 | ENV HOME ${HOME} |
| 38 | RUN /bin/bash |
| 39 | EOF |
| 40 | ) |
| 41 | |
| 42 | elif [[ "${distro}" == ubuntu ]]; then |
| 43 | if [[ -n "${http_proxy}" ]]; then |
| 44 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 45 | fi |
| 46 | |
| 47 | Dockerfile=$(cat << EOF |
| 48 | FROM ubuntu:latest |
| 49 | |
| 50 | ${PROXY} |
| 51 | |
| 52 | RUN echo $(date +%s) && apt-get update |
| 53 | RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -yy |
| 54 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -yy build-essential git gcc-arm-none-eabi u-boot-tools |
| 55 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 56 | |
| 57 | USER ${USER} |
| 58 | ENV HOME ${HOME} |
| 59 | RUN /bin/bash |
| 60 | EOF |
| 61 | ) |
| 62 | fi |
| 63 | |
| 64 | # Build the docker container |
| 65 | docker build -t linux-aspeed/${distro} - <<< "${Dockerfile}" |
| 66 | if [[ "$?" -ne 0 ]]; then |
| 67 | echo "Failed to build docker container." |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | # Create the docker run script |
| 72 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 73 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 74 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 75 | |
| 76 | mkdir -p ${WORKSPACE} |
| 77 | |
| 78 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 79 | #!/bin/bash |
| 80 | |
| 81 | set -x |
| 82 | |
| 83 | cd ${WORKSPACE} |
| 84 | |
| 85 | # Go into the linux-aspeed directory (the script will put us in a build subdir) |
| 86 | cd linux-aspeed |
| 87 | |
| 88 | # Configure a build |
| 89 | make aspeed_defconfig |
| 90 | make -j 8 |
| 91 | |
| 92 | # Build barreleye image |
| 93 | make aspeed-bmc-opp-barreleye.dtb |
| 94 | cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-barreleye.dtb > barreleye-zimage |
| 95 | ./scripts/mkuboot.sh -A arm -O linux -C none -T kernel -a 0x40008000 -e 0x40008000 -d-e 0x40008000 -n obmc-beye-`date +%Y%m%d%H%M` -d aspeed-zimage uImage.barreleye |
| 96 | |
| 97 | # build palmetto image |
| 98 | make aspeed-bmc-opp-palmetto.dtb |
| 99 | cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb > palmetto-zimage |
| 100 | ./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 aspeed-zimage uImage.palmetto |
| 101 | |
| 102 | EOF_SCRIPT |
| 103 | |
| 104 | chmod a+x ${WORKSPACE}/build.sh |
| 105 | |
| 106 | # Run the docker container, execute the build script we just built |
| 107 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 108 | -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-aspeed/${distro} ${WORKSPACE}/build.sh |
| 109 | |
| 110 | # Timestamp for build |
| 111 | echo "Build completed, $(date)" |
| 112 | |