blob: 4ae3d9f31754f667ed40d8370996a3fc6426b79c [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
7if grep -q debug <<< $@; then
8 set -x
9fi
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
20usage(){
21 cat << EOF_USAGE
22Usage: $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
31 exit 1
32}
33
34# Arguments
35CMD_LINE=$(getopt -o d,e: --longoptions debug,endianess: -n "$0" -- "$@")
36eval set -- "${CMD_LINE}"
37
38while 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
58done
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
Joel Stanley93b959d2018-10-24 09:37:54 +103065 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 Stanleyb29fc8b2017-12-06 20:39:32 +103083 iputils-ping \
84 locales
Chris Smart4593d4f2016-03-09 15:50:59 +110085
86RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
87RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
88
Chris Smartb23265d2016-01-11 16:48:57 +110089RUN locale-gen en_AU.utf8
90
91USER ${USER}
92ENV HOME ${HOME}
93RUN /bin/bash
94EOF
95)
96
97# Build the docker container
98docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}"
99if [[ "$?" -ne 0 ]]; then
Joel Stanley93b959d2018-10-24 09:37:54 +1030100 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 Stanley93b959d2018-10-24 09:37:54 +1030134# BR2_TARGET_ROOTFS_TAR is not set
Chris Smartb23265d2016-01-11 16:48:57 +1100135EOF_BUILDROOT
136
137# Build buildroot
Joel Stanley93b959d2018-10-24 09:37:54 +1030138export BR2_DL_DIR="${HOME}/buildroot_downloads"
139make powerpc64${ENDIANESS}_openpower_defconfig
140make
Chris Smartb23265d2016-01-11 16:48:57 +1100141
142EOF_SCRIPT
143
Joel Stanley93b959d2018-10-24 09:37:54 +1030144chmod a+x "${WORKSPACE}/build.sh"
Chris Smartb23265d2016-01-11 16:48:57 +1100145
146# Run the docker container, execute the build script we just built
Joel Stanley93b959d2018-10-24 09:37:54 +1030147docker 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 Smartb23265d2016-01-11 16:48:57 +1100157
158# Timestamp for build
159echo "Build completed, $(date)"
160