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 | b29fc8b | 2017-12-06 20:39:32 +1030 | [diff] [blame] | 83 | iputils-ping \ |
| 84 | locales |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 85 | |
| 86 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 87 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 88 | |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 89 | RUN locale-gen en_AU.utf8 |
| 90 | |
| 91 | USER ${USER} |
| 92 | ENV HOME ${HOME} |
| 93 | RUN /bin/bash |
| 94 | EOF |
| 95 | ) |
| 96 | |
| 97 | # Build the docker container |
| 98 | docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}" |
| 99 | if [[ "$?" -ne 0 ]]; then |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 100 | echo "Failed to build docker container." |
| 101 | exit 1 |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 102 | fi |
| 103 | |
| 104 | # Create the docker run script |
| 105 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 106 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 107 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 108 | |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 109 | mkdir -p "${WORKSPACE}" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 110 | |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 111 | cat > "${WORKSPACE}/build.sh" << EOF_SCRIPT |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 112 | #!/bin/bash |
| 113 | |
| 114 | set -x |
| 115 | |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 116 | export http_proxy=${http_proxy} |
| 117 | export https_proxy=${http_proxy} |
| 118 | export ftp_proxy=${http_proxy} |
| 119 | |
| 120 | cd "${WORKSPACE}" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 121 | |
| 122 | # 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^] | 123 | cd buildroot && make clean |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 124 | |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 125 | # Build PPC64 defconfig |
| 126 | cat >> configs/powerpc64${ENDIANESS}_openpower_defconfig << EOF_BUILDROOT |
| 127 | BR2_powerpc64${ENDIANESS}=y |
| 128 | BR2_CCACHE=y |
| 129 | BR2_SYSTEM_BIN_SH_BASH=y |
| 130 | BR2_TARGET_GENERIC_GETTY_PORT="hvc0" |
| 131 | BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 132 | BR2_TARGET_ROOTFS_CPIO=y |
| 133 | BR2_TARGET_ROOTFS_CPIO_XZ=y |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 134 | # BR2_TARGET_ROOTFS_TAR is not set |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 135 | EOF_BUILDROOT |
| 136 | |
| 137 | # Build buildroot |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 138 | export BR2_DL_DIR="${HOME}/buildroot_downloads" |
| 139 | make powerpc64${ENDIANESS}_openpower_defconfig |
| 140 | make |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 141 | |
| 142 | EOF_SCRIPT |
| 143 | |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 144 | chmod a+x "${WORKSPACE}/build.sh" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 145 | |
| 146 | # Run the docker container, execute the build script we just built |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame^] | 147 | docker run \ |
| 148 | --cap-add=sys_admin \ |
| 149 | --net=host \ |
| 150 | --rm=true \ |
| 151 | -e WORKSPACE="${WORKSPACE}" \ |
| 152 | --user="${USER}" \ |
| 153 | -w "${HOME}" \ |
| 154 | -v "${HOME}":"${HOME}" \ |
| 155 | -t initramfs-build/ubuntu \ |
| 156 | "${WORKSPACE}/build.sh" |
Chris Smart | b23265d | 2016-01-11 16:48:57 +1100 | [diff] [blame] | 157 | |
| 158 | # Timestamp for build |
| 159 | echo "Build completed, $(date)" |
| 160 | |