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 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame^] | 26 | ENV DEBIAN_FRONTEND noninteractive |
| 27 | RUN apt-get update && apt-get upgrade -yy && apt-get install -yy \ |
| 28 | bc \ |
| 29 | build-essential \ |
| 30 | cpio \ |
| 31 | git \ |
| 32 | python \ |
| 33 | unzip \ |
| 34 | wget |
| 35 | |
| 36 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 37 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 38 | |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 39 | RUN locale-gen en_AU.utf8 |
| 40 | |
| 41 | USER ${USER} |
| 42 | ENV HOME ${HOME} |
| 43 | RUN /bin/bash |
| 44 | EOF |
| 45 | ) |
| 46 | |
| 47 | # Build the docker container |
| 48 | docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}" |
| 49 | if [[ "$?" -ne 0 ]]; then |
| 50 | echo "Failed to build docker container." |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
| 54 | # Create the docker run script |
| 55 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 56 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 57 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 58 | |
| 59 | mkdir -p ${WORKSPACE} |
| 60 | |
| 61 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 62 | #!/bin/bash |
| 63 | |
| 64 | set -x |
| 65 | |
| 66 | cd ${WORKSPACE} |
| 67 | |
| 68 | # Go into the linux directory (the script will put us in a build subdir) |
| 69 | cd buildroot |
| 70 | |
| 71 | cat > configs/powerpc64_openpower_defconfig << EOF_BUILDROOT |
| 72 | BR2_powerpc64le=y |
| 73 | BR2_TARGET_ROOTFS_CPIO=y |
| 74 | BR2_TARGET_ROOTFS_CPIO_XZ=y |
Chris Smart | 01d1b38 | 2016-01-14 12:05:33 +1100 | [diff] [blame] | 75 | BR2_TARGET_GENERIC_GETTY_PORT="hvc0" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 76 | EOF_BUILDROOT |
| 77 | |
| 78 | # Build buildroot |
| 79 | export BR2_DL_DIR=${HOME}/buildroot_downloads |
| 80 | make powerpc64_openpower_defconfig || exit 1 |
| 81 | make || exit 1 |
| 82 | |
| 83 | EOF_SCRIPT |
| 84 | |
| 85 | chmod a+x ${WORKSPACE}/build.sh |
| 86 | |
| 87 | # Run the docker container, execute the build script we just built |
| 88 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 89 | -w "${HOME}" -v "${HOME}":"${HOME}" -t initramfs-build/ubuntu ${WORKSPACE}/build.sh |
| 90 | |
| 91 | # Timestamp for build |
| 92 | echo "Build completed, $(date)" |
| 93 | |