blob: 972f477354ed29929af3977da6ff072583ff1ad9 [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
Patrick Williams384d7412020-11-06 16:15:41 -060042RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
43RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${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 \
Joel Stanley0c6ca412018-11-15 09:11:47 +103066 gcc-arm-linux-gnueabi \
67 binutils-arm-linux-gnueabi \
68 libssl-dev \
69 bison \
70 flex \
Chris Smart4593d4f2016-03-09 15:50:59 +110071 u-boot-tools
72
Patrick Williams384d7412020-11-06 16:15:41 -060073RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
74RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Joel Stanley0d3597f2015-11-18 14:09:54 +103075
76USER ${USER}
77ENV HOME ${HOME}
78RUN /bin/bash
79EOF
80)
81fi
82
83# Build the docker container
Patrick Williams384d7412020-11-06 16:15:41 -060084if ! docker build -t "linux-aspeed/${distro}" - <<< "${Dockerfile}" ; then
Joel Stanley0d3597f2015-11-18 14:09:54 +103085 echo "Failed to build docker container."
86 exit 1
87fi
88
89# Create the docker run script
90export PROXY_HOST=${http_proxy/#http*:\/\/}
91export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
92export PROXY_PORT=${http_proxy/#http*:\/\/*:}
93
Patrick Williams384d7412020-11-06 16:15:41 -060094mkdir -p "${WORKSPACE}"
Joel Stanley0d3597f2015-11-18 14:09:54 +103095
96cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
97#!/bin/bash
98
99set -x
100
101cd ${WORKSPACE}
102
103# Go into the linux-aspeed directory (the script will put us in a build subdir)
104cd linux-aspeed
105
106# Configure a build
Chris Smart72ed8022015-11-18 17:06:47 +1100107if [ "${distro}" == "fedora" ]; then
108 CROSS_COMPILER="arm-linux-gnu-"
109else
Joel Stanleyc822ed42019-04-04 13:15:23 +1030110 CROSS_COMPILER="arm-linux-gnueabi-"
Chris Smart72ed8022015-11-18 17:06:47 +1100111fi
112
Joel Stanley50ab01d2015-11-19 09:53:25 +1030113# Record the version in the logs
Joel Stanleyb97b5302015-11-19 09:57:58 +1030114$\{CROSS_COMPILER}gcc --version
Joel Stanley50ab01d2015-11-19 09:53:25 +1030115
Chris Smart72ed8022015-11-18 17:06:47 +1100116ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig
117ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4))
Joel Stanley0d3597f2015-11-18 14:09:54 +1030118
Joel Stanley0d3597f2015-11-18 14:09:54 +1030119# build palmetto image
Chris Smart72ed8022015-11-18 17:06:47 +1100120ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb
Joel Stanley0d3597f2015-11-18 14:09:54 +1030121cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb > palmetto-zimage
Chris Smart72ed8022015-11-18 17:06:47 +1100122./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 +1030123
124EOF_SCRIPT
125
Patrick Williams384d7412020-11-06 16:15:41 -0600126chmod a+x "${WORKSPACE}"/build.sh
Joel Stanley0d3597f2015-11-18 14:09:54 +1030127
128# Run the docker container, execute the build script we just built
Patrick Williams384d7412020-11-06 16:15:41 -0600129docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \
130 -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-aspeed/"${distro}" "${WORKSPACE}"/build.sh
Joel Stanley0d3597f2015-11-18 14:09:54 +1030131
132# Timestamp for build
133echo "Build completed, $(date)"
134