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