blob: 6b5d6f4de07a619ba6f33f9c7335c15758a9f774 [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
Patrick Williams476a7e92022-12-06 09:52:53 -060023 if [[ -n "${http_proxy}" ]]; then
24 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
25 fi
Joel Stanley0d3597f2015-11-18 14:09:54 +103026
Patrick Williams476a7e92022-12-06 09:52:53 -060027 Dockerfile=$(cat << EOF
Joel Stanley0d3597f2015-11-18 14:09:54 +103028FROM 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
Patrick Williams476a7e92022-12-06 09:52:53 -060049 )
Joel Stanley0d3597f2015-11-18 14:09:54 +103050
51elif [[ "${distro}" == ubuntu ]]; then
Patrick Williams476a7e92022-12-06 09:52:53 -060052 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
Joel Stanley0d3597f2015-11-18 14:09:54 +103055
Patrick Williams476a7e92022-12-06 09:52:53 -060056 Dockerfile=$(cat << EOF
Joel Stanley0d3597f2015-11-18 14:09:54 +103057FROM 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
Patrick Williams476a7e92022-12-06 09:52:53 -060080 )
Joel Stanley0d3597f2015-11-18 14:09:54 +103081fi
82
83# Build the docker container
Patrick Williams384d7412020-11-06 16:15:41 -060084if ! docker build -t "linux-aspeed/${distro}" - <<< "${Dockerfile}" ; then
Patrick Williams476a7e92022-12-06 09:52:53 -060085 echo "Failed to build docker container."
86 exit 1
Joel Stanley0d3597f2015-11-18 14:09:54 +103087fi
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}" \
Patrick Williams476a7e92022-12-06 09:52:53 -0600130 -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