blob: 590d94c6d9a8a3707a80bafcecf88b03b9cae8fe [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 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
87RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
88RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
89
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
99docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}"
100if [[ "$?" -ne 0 ]]; then
Joel Stanley93b959d2018-10-24 09:37:54 +1030101 echo "Failed to build docker container."
102 exit 1
Chris Smartb23265d2016-01-11 16:48:57 +1100103fi
104
105# Create the docker run script
106export PROXY_HOST=${http_proxy/#http*:\/\/}
107export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
108export PROXY_PORT=${http_proxy/#http*:\/\/*:}
109
Joel Stanley93b959d2018-10-24 09:37:54 +1030110mkdir -p "${WORKSPACE}"
Chris Smartb23265d2016-01-11 16:48:57 +1100111
Joel Stanley93b959d2018-10-24 09:37:54 +1030112cat > "${WORKSPACE}/build.sh" << EOF_SCRIPT
Chris Smartb23265d2016-01-11 16:48:57 +1100113#!/bin/bash
114
115set -x
116
Joel Stanley93b959d2018-10-24 09:37:54 +1030117export http_proxy=${http_proxy}
118export https_proxy=${http_proxy}
119export ftp_proxy=${http_proxy}
120
121cd "${WORKSPACE}"
Chris Smartb23265d2016-01-11 16:48:57 +1100122
123# Go into the linux directory (the script will put us in a build subdir)
Joel Stanley93b959d2018-10-24 09:37:54 +1030124cd buildroot && make clean
Chris Smartb23265d2016-01-11 16:48:57 +1100125
Joel Stanley93b959d2018-10-24 09:37:54 +1030126# Build PPC64 defconfig
127cat >> configs/powerpc64${ENDIANESS}_openpower_defconfig << EOF_BUILDROOT
128BR2_powerpc64${ENDIANESS}=y
129BR2_CCACHE=y
130BR2_SYSTEM_BIN_SH_BASH=y
131BR2_TARGET_GENERIC_GETTY_PORT="hvc0"
132BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
Chris Smartb23265d2016-01-11 16:48:57 +1100133BR2_TARGET_ROOTFS_CPIO=y
134BR2_TARGET_ROOTFS_CPIO_XZ=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 \
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 Smartb23265d2016-01-11 16:48:57 +1100158
159# Timestamp for build
160echo "Build completed, $(date)"
161