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