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 | |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 6 | # Debug |
| 7 | if grep -q debug <<< $@; then |
| 8 | set -x |
| 9 | fi |
| 10 | set -o errexit |
| 11 | set -o pipefail |
| 12 | set -o nounset |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 13 | |
| 14 | # Default variables |
| 15 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 16 | http_proxy=${http_proxy:-} |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 17 | ENDIANESS=${ENDIANESS:-le} |
| 18 | |
| 19 | usage(){ |
| 20 | cat << EOF_USAGE |
| 21 | Usage: $0 [options] |
| 22 | |
| 23 | Options: |
| 24 | --endianess <le|be> build an LE or BE initramfs |
| 25 | |
| 26 | Short Options: |
| 27 | -e same as --endianess |
| 28 | |
| 29 | EOF_USAGE |
| 30 | exit 1 |
| 31 | } |
| 32 | |
| 33 | # Arguments |
| 34 | CMD_LINE=$(getopt -o d,e: --longoptions debug,endianess: -n "$0" -- "$@") |
| 35 | eval set -- "${CMD_LINE}" |
| 36 | |
| 37 | while true ; do |
| 38 | case "${1}" in |
| 39 | -e|--endianess) |
| 40 | if [[ "${2,,}" == "be" ]]; then |
| 41 | ENDIANESS="" |
| 42 | fi |
| 43 | shift 2 |
| 44 | ;; |
| 45 | -d|--debug) |
| 46 | set -x |
| 47 | shift |
| 48 | ;; |
| 49 | --) |
| 50 | shift |
| 51 | break |
| 52 | ;; |
| 53 | *) |
| 54 | usage |
| 55 | ;; |
| 56 | esac |
| 57 | done |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 58 | |
| 59 | # Timestamp for job |
| 60 | echo "Build started, $(date)" |
| 61 | |
| 62 | # Configure docker build |
| 63 | if [[ -n "${http_proxy}" ]]; then |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 64 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 65 | fi |
| 66 | |
| 67 | Dockerfile=$(cat << EOF |
| 68 | FROM ubuntu:15.10 |
| 69 | |
| 70 | ${PROXY} |
| 71 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 72 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 73 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 74 | bc \ |
| 75 | build-essential \ |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 76 | ccache \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 77 | cpio \ |
| 78 | git \ |
| 79 | python \ |
| 80 | unzip \ |
| 81 | wget |
| 82 | |
| 83 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 84 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 85 | |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 86 | RUN locale-gen en_AU.utf8 |
| 87 | |
| 88 | USER ${USER} |
| 89 | ENV HOME ${HOME} |
| 90 | RUN /bin/bash |
| 91 | EOF |
| 92 | ) |
| 93 | |
| 94 | # Build the docker container |
| 95 | docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}" |
| 96 | if [[ "$?" -ne 0 ]]; then |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 97 | echo "Failed to build docker container." |
| 98 | exit 1 |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 99 | fi |
| 100 | |
| 101 | # Create the docker run script |
| 102 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 103 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 104 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 105 | |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 106 | mkdir -p "${WORKSPACE}" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 107 | |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 108 | cat > "${WORKSPACE}/build.sh" << EOF_SCRIPT |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 109 | #!/bin/bash |
| 110 | |
| 111 | set -x |
| 112 | |
Chris Smart | 0c2bc22 | 2016-03-16 14:39:14 +1100 | [diff] [blame] | 113 | export http_proxy=${http_proxy} |
| 114 | export https_proxy=${http_proxy} |
| 115 | export ftp_proxy=${http_proxy} |
| 116 | |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 117 | cd "${WORKSPACE}" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 118 | |
| 119 | # Go into the linux directory (the script will put us in a build subdir) |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 120 | cd buildroot && make clean |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 121 | |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 122 | # Build PPC64 defconfig |
| 123 | cat >> configs/powerpc64${ENDIANESS}_openpower_defconfig << EOF_BUILDROOT |
| 124 | BR2_powerpc64${ENDIANESS}=y |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 125 | BR2_TARGET_ROOTFS_CPIO=y |
| 126 | BR2_TARGET_ROOTFS_CPIO_XZ=y |
Chris Smart | 01d1b38 | 2016-01-14 12:05:33 +1100 | [diff] [blame] | 127 | BR2_TARGET_GENERIC_GETTY_PORT="hvc0" |
Chris Smart | f540dac | 2016-03-16 12:58:15 +1100 | [diff] [blame] | 128 | BR2_GLIBC_VERSION_2_22=y |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 129 | BR2_TARGET_ROOTFS_TAR=n |
| 130 | BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y |
| 131 | BR2_SYSTEM_BIN_SH_BASH=y |
| 132 | BR2_CCACHE=y |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 133 | EOF_BUILDROOT |
| 134 | |
| 135 | # Build buildroot |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 136 | export BR2_DL_DIR="${HOME}/buildroot_downloads" |
| 137 | make powerpc64${ENDIANESS}_openpower_defconfig |
| 138 | make |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 139 | |
| 140 | EOF_SCRIPT |
| 141 | |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 142 | chmod a+x "${WORKSPACE}/build.sh" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 143 | |
| 144 | # Run the docker container, execute the build script we just built |
Chris Smart | dd287bb | 2016-03-17 10:43:56 +1100 | [diff] [blame] | 145 | docker run \ |
| 146 | --cap-add=sys_admin \ |
| 147 | --net=host \ |
| 148 | --rm=true \ |
| 149 | -e WORKSPACE="${WORKSPACE}" \ |
| 150 | --user="${USER}" \ |
| 151 | -w "${HOME}" \ |
| 152 | -v "${HOME}":"${HOME}":Z \ |
| 153 | -t initramfs-build/ubuntu \ |
| 154 | "${WORKSPACE}/build.sh" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 155 | |
| 156 | # Timestamp for build |
| 157 | echo "Build completed, $(date)" |
| 158 | |