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 |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 7 | if grep -q debug <<< "$@"; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 8 | set -x |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 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:-} | ||||
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 17 | ENDIANNESS=${ENDIANNESS:-le} |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 18 | PROXY="" |
19 | |||||
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 20 | function usage() { |
21 | cat << EOF_USAGE | ||||
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 22 | Usage: $0 [options] |
23 | |||||
24 | Options: | ||||
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 25 | --endianness <le|be> build an LE or BE initramfs |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 26 | |
27 | Short Options: | ||||
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 28 | -e same as --endianness |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 29 | |
30 | EOF_USAGE | ||||
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 31 | exit 1 |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 32 | } |
33 | |||||
34 | # Arguments | ||||
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 35 | CMD_LINE=$(getopt -o d,e: --longoptions debug,endianness: -n "$0" -- "$@") |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 36 | eval set -- "${CMD_LINE}" |
37 | |||||
38 | while true ; do | ||||
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 39 | case "${1}" in |
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 40 | -e|--endianness) |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 41 | if [[ "${2,,}" == "be" ]]; then |
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 42 | ENDIANNESS="" |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 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 | ||||
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 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 | ||||
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [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 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 87 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
88 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} | ||||
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 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 | ||||
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 99 | if ! docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}" ; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [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 |
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 126 | cat >> configs/powerpc64${ENDIANNESS}_openpower_defconfig << EOF_BUILDROOT |
127 | BR2_powerpc64${ENDIANNESS}=y | ||||
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 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 | 2dab4d9 | 2019-03-04 14:17:09 +1030 | [diff] [blame] | 134 | BR2_PACKAGE_IPMITOOL=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" |
Manojkiran Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 140 | make powerpc64${ENDIANNESS}_openpower_defconfig |
Joel Stanley | 93b959d | 2018-10-24 09:37:54 +1030 | [diff] [blame] | 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 \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 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 |