Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This build script is for running the Jenkins builds using docker. |
| 4 | # |
| 5 | |
| 6 | # Trace bash processing |
| 7 | #set -x |
| 8 | |
| 9 | # Default variables |
| 10 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 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:15.10 |
| 23 | |
| 24 | ${PROXY} |
| 25 | |
| 26 | #RUN echo $(date +%s) && apt-get update |
| 27 | RUN apt-get update |
| 28 | RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -yy |
| 29 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -yy bc build-essential cpio git python unzip wget |
| 30 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 31 | RUN locale-gen en_AU.utf8 |
| 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 initramfs-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 | # Go into the linux directory (the script will put us in a build subdir) |
| 61 | cd buildroot |
| 62 | |
| 63 | cat > configs/powerpc64_openpower_defconfig << EOF_BUILDROOT |
| 64 | BR2_powerpc64le=y |
| 65 | BR2_TARGET_ROOTFS_CPIO=y |
| 66 | BR2_TARGET_ROOTFS_CPIO_XZ=y |
Chris Smart | 01d1b38 | 2016-01-14 12:05:33 +1100 | [diff] [blame] | 67 | BR2_TARGET_GENERIC_GETTY_PORT="hvc0" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 68 | EOF_BUILDROOT |
| 69 | |
| 70 | # Build buildroot |
| 71 | export BR2_DL_DIR=${HOME}/buildroot_downloads |
| 72 | make powerpc64_openpower_defconfig || exit 1 |
| 73 | make || exit 1 |
| 74 | |
| 75 | EOF_SCRIPT |
| 76 | |
| 77 | chmod a+x ${WORKSPACE}/build.sh |
| 78 | |
| 79 | # Run the docker container, execute the build script we just built |
| 80 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 81 | -w "${HOME}" -v "${HOME}":"${HOME}" -t initramfs-build/ubuntu ${WORKSPACE}/build.sh |
| 82 | |
| 83 | # Timestamp for build |
| 84 | echo "Build completed, $(date)" |
| 85 | |