blob: 43e0de886e7790c09211aeed717aa74f48f0cded [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
22FROM ubuntu:15.10
23
24${PROXY}
25
26#RUN echo $(date +%s) && apt-get update
27RUN apt-get update
28RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -yy
29RUN DEBIAN_FRONTEND=noninteractive apt-get install -yy bc build-essential cpio git python unzip wget
30RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
31RUN locale-gen en_AU.utf8
32
33USER ${USER}
34ENV HOME ${HOME}
35RUN /bin/bash
36EOF
37)
38
39# Build the docker container
40docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}"
41if [[ "$?" -ne 0 ]]; then
42 echo "Failed to build docker container."
43 exit 1
44fi
45
46# Create the docker run script
47export PROXY_HOST=${http_proxy/#http*:\/\/}
48export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
49export PROXY_PORT=${http_proxy/#http*:\/\/*:}
50
51mkdir -p ${WORKSPACE}
52
53cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
54#!/bin/bash
55
56set -x
57
58cd ${WORKSPACE}
59
60# Go into the linux directory (the script will put us in a build subdir)
61cd buildroot
62
63cat > configs/powerpc64_openpower_defconfig << EOF_BUILDROOT
64BR2_powerpc64le=y
65BR2_TARGET_ROOTFS_CPIO=y
66BR2_TARGET_ROOTFS_CPIO_XZ=y
Chris Smart01d1b382016-01-14 12:05:33 +110067BR2_TARGET_GENERIC_GETTY_PORT="hvc0"
Chris Smart6baea592016-01-14 13:52:04 +110068BR2_ROOTFS_POST_BUILD_SCRIPT="./fix_inittab.sh"
Chris Smartb23265d2016-01-11 16:48:57 +110069EOF_BUILDROOT
70
Chris Smart6baea592016-01-14 13:52:04 +110071# Create overlay inittab to start tty on boot
72cat > fix_inittab.sh << EOF_INITTAB
73#!/bin/bash
74# The BR2_TARGET_GENERIC_GETTY=y option doesn't seem to be enabling
75# a terminal on boot in /etc/inittab (as it should).
76#
77# We change the setting rather than writing a new file via overlay
78# that way we get any other changes in the future, including if it
79# starts working again
80sed -i 's|^#ttyS0::.*|hvc0::respawn:/sbin/getty -L hvc0 115200 vt100 # GENERIC_SERIAL|' \\\${TARGET_DIR}/etc/inittab
81EOF_INITTAB
82chmod u+x fix_inittab.sh
83
Chris Smartb23265d2016-01-11 16:48:57 +110084# Build buildroot
85export BR2_DL_DIR=${HOME}/buildroot_downloads
86make powerpc64_openpower_defconfig || exit 1
87make || exit 1
88
89EOF_SCRIPT
90
91chmod a+x ${WORKSPACE}/build.sh
92
93# Run the docker container, execute the build script we just built
94docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
95 -w "${HOME}" -v "${HOME}":"${HOME}" -t initramfs-build/ubuntu ${WORKSPACE}/build.sh
96
97# Timestamp for build
98echo "Build completed, $(date)"
99