blob: f48748336b899768fde447d8e99c3423217006f0 [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
Chris Smartdd287bb2016-03-17 10:43:56 +11006# 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:-}
Chris Smartdd287bb2016-03-17 10:43:56 +110017ENDIANESS=${ENDIANESS:-le}
18
19usage(){
20 cat << EOF_USAGE
21Usage: $0 [options]
22
23Options:
24--endianess <le|be> build an LE or BE initramfs
25
26Short Options:
27-e same as --endianess
28
29EOF_USAGE
30 exit 1
31}
32
33# Arguments
34CMD_LINE=$(getopt -o d,e: --longoptions debug,endianess: -n "$0" -- "$@")
35eval set -- "${CMD_LINE}"
36
37while true ; do
38 case "${1}" in
39 -e|--endianess)
40 if [[ "${2,,}" == "be" ]]; then
41 ENDIANESS=""
42 fi
43 shift 2
44 ;;
45 -d|--debug)
46 set -x
47 shift
48 ;;
49 --)
50 shift
51 break
52 ;;
53 *)
54 usage
55 ;;
56 esac
57done
Chris Smartb23265d2016-01-11 16:48:57 +110058
59# Timestamp for job
60echo "Build started, $(date)"
61
62# Configure docker build
63if [[ -n "${http_proxy}" ]]; then
Chris Smartdd287bb2016-03-17 10:43:56 +110064 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
Chris Smartb23265d2016-01-11 16:48:57 +110065fi
66
67Dockerfile=$(cat << EOF
68FROM ubuntu:15.10
69
70${PROXY}
71
Chris Smart4593d4f2016-03-09 15:50:59 +110072ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110073RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110074 bc \
75 build-essential \
Chris Smartdd287bb2016-03-17 10:43:56 +110076 ccache \
Chris Smart4593d4f2016-03-09 15:50:59 +110077 cpio \
78 git \
79 python \
80 unzip \
81 wget
82
83RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
84RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
85
Chris Smartb23265d2016-01-11 16:48:57 +110086RUN locale-gen en_AU.utf8
87
88USER ${USER}
89ENV HOME ${HOME}
90RUN /bin/bash
91EOF
92)
93
94# Build the docker container
95docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}"
96if [[ "$?" -ne 0 ]]; then
Chris Smartdd287bb2016-03-17 10:43:56 +110097 echo "Failed to build docker container."
98 exit 1
Chris Smartb23265d2016-01-11 16:48:57 +110099fi
100
101# Create the docker run script
102export PROXY_HOST=${http_proxy/#http*:\/\/}
103export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
104export PROXY_PORT=${http_proxy/#http*:\/\/*:}
105
Chris Smartdd287bb2016-03-17 10:43:56 +1100106mkdir -p "${WORKSPACE}"
Chris Smartb23265d2016-01-11 16:48:57 +1100107
Chris Smartdd287bb2016-03-17 10:43:56 +1100108cat > "${WORKSPACE}/build.sh" << EOF_SCRIPT
Chris Smartb23265d2016-01-11 16:48:57 +1100109#!/bin/bash
110
111set -x
112
Chris Smart0c2bc222016-03-16 14:39:14 +1100113export http_proxy=${http_proxy}
114export https_proxy=${http_proxy}
115export ftp_proxy=${http_proxy}
116
Chris Smartdd287bb2016-03-17 10:43:56 +1100117cd "${WORKSPACE}"
Chris Smartb23265d2016-01-11 16:48:57 +1100118
119# Go into the linux directory (the script will put us in a build subdir)
Chris Smartdd287bb2016-03-17 10:43:56 +1100120cd buildroot && make clean
Chris Smartb23265d2016-01-11 16:48:57 +1100121
Chris Smartdd287bb2016-03-17 10:43:56 +1100122# Build PPC64 defconfig
123cat >> configs/powerpc64${ENDIANESS}_openpower_defconfig << EOF_BUILDROOT
124BR2_powerpc64${ENDIANESS}=y
Chris Smartb23265d2016-01-11 16:48:57 +1100125BR2_TARGET_ROOTFS_CPIO=y
126BR2_TARGET_ROOTFS_CPIO_XZ=y
Chris Smart01d1b382016-01-14 12:05:33 +1100127BR2_TARGET_GENERIC_GETTY_PORT="hvc0"
Chris Smartf540dac2016-03-16 12:58:15 +1100128BR2_GLIBC_VERSION_2_22=y
Chris Smartdd287bb2016-03-17 10:43:56 +1100129BR2_TARGET_ROOTFS_TAR=n
130BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
131BR2_SYSTEM_BIN_SH_BASH=y
132BR2_CCACHE=y
Chris Smartb23265d2016-01-11 16:48:57 +1100133EOF_BUILDROOT
134
135# Build buildroot
Chris Smartdd287bb2016-03-17 10:43:56 +1100136export BR2_DL_DIR="${HOME}/buildroot_downloads"
137make powerpc64${ENDIANESS}_openpower_defconfig
138make
Chris Smartb23265d2016-01-11 16:48:57 +1100139
140EOF_SCRIPT
141
Chris Smartdd287bb2016-03-17 10:43:56 +1100142chmod a+x "${WORKSPACE}/build.sh"
Chris Smartb23265d2016-01-11 16:48:57 +1100143
144# Run the docker container, execute the build script we just built
Chris Smartdd287bb2016-03-17 10:43:56 +1100145docker run \
146 --cap-add=sys_admin \
147 --net=host \
148 --rm=true \
149 -e WORKSPACE="${WORKSPACE}" \
150 --user="${USER}" \
151 -w "${HOME}" \
152 -v "${HOME}":"${HOME}":Z \
153 -t initramfs-build/ubuntu \
154 "${WORKSPACE}/build.sh"
Chris Smartb23265d2016-01-11 16:48:57 +1100155
156# Timestamp for build
157echo "Build completed, $(date)"
158