blob: 89c2d2f862141d6ac2750a3d6f88c02fb0e3a2cf [file] [log] [blame]
Joel Stanley0d3597f2015-11-18 14:09:54 +10301#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4#
5# It expects a variable as part of Jenkins build job matrix:
6# distro = fedora|ubuntu
7# WORKSPACE =
8
9# Trace bash processing
10set -x
11
12# Default variables
13distro=${distro:-ubuntu}
14WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
15http_proxy=${http_proxy:-}
16
17# Timestamp for job
18echo "Build started, $(date)"
19
20# Configure docker build
21if [[ "${distro}" == fedora ]];then
22
23 if [[ -n "${http_proxy}" ]]; then
24 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
25 fi
26
27 Dockerfile=$(cat << EOF
28FROM fedora:latest
29
30${PROXY}
31
Chris Smartfc730ff2016-03-09 20:17:19 +110032RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110033 bc \
34 findutils \
35 git \
36 gcc \
37 gcc-arm-linux-gnu \
38 hostname \
39 make \
40 uboot-tools xz
41
42RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
43RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley0d3597f2015-11-18 14:09:54 +103044
45USER ${USER}
46ENV HOME ${HOME}
47RUN /bin/bash
48EOF
49)
50
51elif [[ "${distro}" == ubuntu ]]; then
52 if [[ -n "${http_proxy}" ]]; then
53 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
54 fi
55
56 Dockerfile=$(cat << EOF
57FROM ubuntu:latest
58
59${PROXY}
60
Chris Smart4593d4f2016-03-09 15:50:59 +110061ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110062RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110063 bc \
64 build-essential \
65 git \
66 gcc-arm-none-eabi \
67 u-boot-tools
68
69RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
70RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley0d3597f2015-11-18 14:09:54 +103071
72USER ${USER}
73ENV HOME ${HOME}
74RUN /bin/bash
75EOF
76)
77fi
78
79# Build the docker container
80docker build -t linux-aspeed/${distro} - <<< "${Dockerfile}"
81if [[ "$?" -ne 0 ]]; then
82 echo "Failed to build docker container."
83 exit 1
84fi
85
86# Create the docker run script
87export PROXY_HOST=${http_proxy/#http*:\/\/}
88export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
89export PROXY_PORT=${http_proxy/#http*:\/\/*:}
90
91mkdir -p ${WORKSPACE}
92
93cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
94#!/bin/bash
95
96set -x
97
98cd ${WORKSPACE}
99
100# Go into the linux-aspeed directory (the script will put us in a build subdir)
101cd linux-aspeed
102
103# Configure a build
Chris Smart72ed8022015-11-18 17:06:47 +1100104if [ "${distro}" == "fedora" ]; then
105 CROSS_COMPILER="arm-linux-gnu-"
106else
107 CROSS_COMPILER="arm-none-eabi-"
108fi
109
Joel Stanley50ab01d2015-11-19 09:53:25 +1030110# Record the version in the logs
Joel Stanleyb97b5302015-11-19 09:57:58 +1030111$\{CROSS_COMPILER}gcc --version
Joel Stanley50ab01d2015-11-19 09:53:25 +1030112
Chris Smart72ed8022015-11-18 17:06:47 +1100113ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig
114ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4))
Joel Stanley0d3597f2015-11-18 14:09:54 +1030115
116# Build barreleye image
Chris Smart72ed8022015-11-18 17:06:47 +1100117ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-barreleye.dtb
Joel Stanley0d3597f2015-11-18 14:09:54 +1030118cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-barreleye.dtb > barreleye-zimage
Chris Smart72ed8022015-11-18 17:06:47 +1100119./scripts/mkuboot.sh -A arm -O linux -C none -T kernel -a 0x40008000 -e 0x40008000 -d-e 0x40008000 -n obmc-beye-\$(date +%Y%m%d%H%M) -d barreleye-zimage uImage.barreleye
Joel Stanley0d3597f2015-11-18 14:09:54 +1030120
121# build palmetto image
Chris Smart72ed8022015-11-18 17:06:47 +1100122ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb
Joel Stanley0d3597f2015-11-18 14:09:54 +1030123cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb > palmetto-zimage
Chris Smart72ed8022015-11-18 17:06:47 +1100124./scripts/mkuboot.sh -A arm -O linux -C none -T kernel -a 0x40008000 -e 0x40008000 -d-e 0x40008000 -n obmc-palm-\$(date +%Y%m%d%H%M) -d palmetto-zimage uImage.palmetto
Joel Stanley0d3597f2015-11-18 14:09:54 +1030125
126EOF_SCRIPT
127
128chmod a+x ${WORKSPACE}/build.sh
129
130# Run the docker container, execute the build script we just built
131docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
132 -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-aspeed/${distro} ${WORKSPACE}/build.sh
133
134# Timestamp for build
135echo "Build completed, $(date)"
136