blob: 2cc4c28a0c4a3f10c9fb061b0880b811e420d84c [file] [log] [blame]
Chris Smartb23265d2016-01-11 16:48:57 +11001#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4#
5
Joel Stanley93b959d2018-10-24 09:37:54 +10306# Debug
Patrick Williams384d7412020-11-06 16:15:41 -06007if grep -q debug <<< "$@"; then
Patrick Williams476a7e92022-12-06 09:52:53 -06008 set -x
Joel Stanley93b959d2018-10-24 09:37:54 +10309fi
10set -o errexit
11set -o pipefail
12set -o nounset
Chris Smartb23265d2016-01-11 16:48:57 +110013
14# Default variables
15WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
16http_proxy=${http_proxy:-}
Joel Stanley93b959d2018-10-24 09:37:54 +103017ENDIANESS=${ENDIANESS:-le}
18PROXY=""
19
Patrick Williams476a7e92022-12-06 09:52:53 -060020function usage() {
21 cat << EOF_USAGE
Joel Stanley93b959d2018-10-24 09:37:54 +103022Usage: $0 [options]
23
24Options:
25--endianess <le|be> build an LE or BE initramfs
26
27Short Options:
28-e same as --endianess
29
30EOF_USAGE
Patrick Williams476a7e92022-12-06 09:52:53 -060031 exit 1
Joel Stanley93b959d2018-10-24 09:37:54 +103032}
33
34# Arguments
35CMD_LINE=$(getopt -o d,e: --longoptions debug,endianess: -n "$0" -- "$@")
36eval set -- "${CMD_LINE}"
37
38while true ; do
Patrick Williams476a7e92022-12-06 09:52:53 -060039 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
Joel Stanley93b959d2018-10-24 09:37:54 +103058done
Chris Smartb23265d2016-01-11 16:48:57 +110059
60# Timestamp for job
61echo "Build started, $(date)"
62
63# Configure docker build
64if [[ -n "${http_proxy}" ]]; then
Patrick Williams476a7e92022-12-06 09:52:53 -060065 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
Chris Smartb23265d2016-01-11 16:48:57 +110066fi
67
68Dockerfile=$(cat << EOF
Joel Stanley93b959d2018-10-24 09:37:54 +103069FROM ubuntu:18.04
Chris Smartb23265d2016-01-11 16:48:57 +110070
71${PROXY}
72
Chris Smart4593d4f2016-03-09 15:50:59 +110073ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110074RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110075 bc \
76 build-essential \
Joel Stanley93b959d2018-10-24 09:37:54 +103077 ccache \
Chris Smart4593d4f2016-03-09 15:50:59 +110078 cpio \
79 git \
80 python \
81 unzip \
Saqib Khan5158a322017-10-23 11:31:24 -050082 wget \
Joel Stanley13b7b422018-10-24 10:54:08 +103083 rsync \
Joel Stanleyb29fc8b2017-12-06 20:39:32 +103084 iputils-ping \
85 locales
Chris Smart4593d4f2016-03-09 15:50:59 +110086
Patrick Williams384d7412020-11-06 16:15:41 -060087RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
88RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smart4593d4f2016-03-09 15:50:59 +110089
Chris Smartb23265d2016-01-11 16:48:57 +110090RUN locale-gen en_AU.utf8
91
92USER ${USER}
93ENV HOME ${HOME}
94RUN /bin/bash
95EOF
96)
97
98# Build the docker container
Patrick Williams384d7412020-11-06 16:15:41 -060099if ! docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}" ; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600100 echo "Failed to build docker container."
101 exit 1
Chris Smartb23265d2016-01-11 16:48:57 +1100102fi
103
104# Create the docker run script
105export PROXY_HOST=${http_proxy/#http*:\/\/}
106export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
107export PROXY_PORT=${http_proxy/#http*:\/\/*:}
108
Joel Stanley93b959d2018-10-24 09:37:54 +1030109mkdir -p "${WORKSPACE}"
Chris Smartb23265d2016-01-11 16:48:57 +1100110
Joel Stanley93b959d2018-10-24 09:37:54 +1030111cat > "${WORKSPACE}/build.sh" << EOF_SCRIPT
Chris Smartb23265d2016-01-11 16:48:57 +1100112#!/bin/bash
113
114set -x
115
Joel Stanley93b959d2018-10-24 09:37:54 +1030116export http_proxy=${http_proxy}
117export https_proxy=${http_proxy}
118export ftp_proxy=${http_proxy}
119
120cd "${WORKSPACE}"
Chris Smartb23265d2016-01-11 16:48:57 +1100121
122# Go into the linux directory (the script will put us in a build subdir)
Joel Stanley93b959d2018-10-24 09:37:54 +1030123cd buildroot && make clean
Chris Smartb23265d2016-01-11 16:48:57 +1100124
Joel Stanley93b959d2018-10-24 09:37:54 +1030125# Build PPC64 defconfig
126cat >> configs/powerpc64${ENDIANESS}_openpower_defconfig << EOF_BUILDROOT
127BR2_powerpc64${ENDIANESS}=y
128BR2_CCACHE=y
129BR2_SYSTEM_BIN_SH_BASH=y
130BR2_TARGET_GENERIC_GETTY_PORT="hvc0"
131BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
Chris Smartb23265d2016-01-11 16:48:57 +1100132BR2_TARGET_ROOTFS_CPIO=y
133BR2_TARGET_ROOTFS_CPIO_XZ=y
Joel Stanley2dab4d92019-03-04 14:17:09 +1030134BR2_PACKAGE_IPMITOOL=y
Joel Stanley93b959d2018-10-24 09:37:54 +1030135# BR2_TARGET_ROOTFS_TAR is not set
Chris Smartb23265d2016-01-11 16:48:57 +1100136EOF_BUILDROOT
137
138# Build buildroot
Joel Stanley93b959d2018-10-24 09:37:54 +1030139export BR2_DL_DIR="${HOME}/buildroot_downloads"
140make powerpc64${ENDIANESS}_openpower_defconfig
141make
Chris Smartb23265d2016-01-11 16:48:57 +1100142
143EOF_SCRIPT
144
Joel Stanley93b959d2018-10-24 09:37:54 +1030145chmod a+x "${WORKSPACE}/build.sh"
Chris Smartb23265d2016-01-11 16:48:57 +1100146
147# Run the docker container, execute the build script we just built
Joel Stanley93b959d2018-10-24 09:37:54 +1030148docker run \
Patrick Williams476a7e92022-12-06 09:52:53 -0600149 --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 Smartb23265d2016-01-11 16:48:57 +1100158
159# Timestamp for build
160echo "Build completed, $(date)"
161