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 |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 27 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 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 | f540dac | 2016-03-16 12:58:15 +1100 | [diff] [blame^] | 76 | BR2_GLIBC_VERSION_2_22=y |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 77 | EOF_BUILDROOT |
| 78 | |
| 79 | # Build buildroot |
| 80 | export BR2_DL_DIR=${HOME}/buildroot_downloads |
| 81 | make powerpc64_openpower_defconfig || exit 1 |
| 82 | make || exit 1 |
| 83 | |
| 84 | EOF_SCRIPT |
| 85 | |
| 86 | chmod a+x ${WORKSPACE}/build.sh |
| 87 | |
| 88 | # Run the docker container, execute the build script we just built |
| 89 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 90 | -w "${HOME}" -v "${HOME}":"${HOME}" -t initramfs-build/ubuntu ${WORKSPACE}/build.sh |
| 91 | |
| 92 | # Timestamp for build |
| 93 | echo "Build completed, $(date)" |
| 94 | |