blob: 4af4ec08890221c3b2b454ed5f01d1def702903c [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
6# Trace bash processing
7#set -x
8
9# Default variables
10WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
11http_proxy=${http_proxy:-}
12
13# Timestamp for job
14echo "Build started, $(date)"
15
16# Configure docker build
17if [[ -n "${http_proxy}" ]]; then
18PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
19fi
20
21Dockerfile=$(cat << EOF
Joel Stanley5f4de952017-12-06 18:53:16 +103022FROM ubuntu:latest
Chris Smartb23265d2016-01-11 16:48:57 +110023
24${PROXY}
25
Chris Smart4593d4f2016-03-09 15:50:59 +110026ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110027RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110028 bc \
29 build-essential \
30 cpio \
31 git \
32 python \
33 unzip \
Saqib Khan5158a322017-10-23 11:31:24 -050034 wget \
Joel Stanleyb29fc8b2017-12-06 20:39:32 +103035 iputils-ping \
36 locales
Chris Smart4593d4f2016-03-09 15:50:59 +110037
38RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
39RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
40
Chris Smartb23265d2016-01-11 16:48:57 +110041RUN locale-gen en_AU.utf8
42
43USER ${USER}
44ENV HOME ${HOME}
45RUN /bin/bash
46EOF
47)
48
49# Build the docker container
50docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}"
51if [[ "$?" -ne 0 ]]; then
52 echo "Failed to build docker container."
53 exit 1
54fi
55
56# Create the docker run script
57export PROXY_HOST=${http_proxy/#http*:\/\/}
58export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
59export PROXY_PORT=${http_proxy/#http*:\/\/*:}
60
61mkdir -p ${WORKSPACE}
62
63cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
64#!/bin/bash
65
66set -x
67
68cd ${WORKSPACE}
69
70# Go into the linux directory (the script will put us in a build subdir)
71cd buildroot
72
73cat > configs/powerpc64_openpower_defconfig << EOF_BUILDROOT
74BR2_powerpc64le=y
75BR2_TARGET_ROOTFS_CPIO=y
76BR2_TARGET_ROOTFS_CPIO_XZ=y
Chris Smart01d1b382016-01-14 12:05:33 +110077BR2_TARGET_GENERIC_GETTY_PORT="hvc0"
Joel Stanleyf4ac46a2017-12-06 20:43:17 +103078BR2_SYSTEM_DHCP="eth0"
Chris Smartb23265d2016-01-11 16:48:57 +110079EOF_BUILDROOT
80
81# Build buildroot
82export BR2_DL_DIR=${HOME}/buildroot_downloads
83make powerpc64_openpower_defconfig || exit 1
84make || exit 1
85
86EOF_SCRIPT
87
88chmod a+x ${WORKSPACE}/build.sh
89
90# Run the docker container, execute the build script we just built
91docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
92 -w "${HOME}" -v "${HOME}":"${HOME}" -t initramfs-build/ubuntu ${WORKSPACE}/build.sh
93
94# Timestamp for build
95echo "Build completed, $(date)"
96