blob: 80a8a83553d4a0ea4eff595c5e8fcc4c1bc91015 [file] [log] [blame]
Joel Stanley2ed389f2015-12-11 15:07:07 +10301#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4#
5# It expects a few variables which are part of Jenkins build job matrix:
6# target = palmetto|qemu|habanero|firestone|garrison
7# distro = ubuntu
8# WORKSPACE =
9
10# Trace bash processing
11set -x
12
13# Default variables
14target=${target:-palmetto}
15distro=${distro:-ubuntu}
16WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
17http_proxy=${http_proxy:-}
18
19# Timestamp for job
20echo "Build started, $(date)"
21
22# Configure docker build
23if [[ "${distro}" == fedora ]];then
24
25 Dockerfile=$(cat << EOF
26FROM fedora:latest
27
28RUN dnf --refresh upgrade -y && \
29 dnf install -y vim gcc-c++ flex bison git ctags cscope expat-devel \
30 patch zlib-devel zlib-static perl
31RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
32
33USER ${USER}
34ENV HOME ${HOME}
35RUN /bin/bash
36EOF
37)
38
39elif [[ "${distro}" == ubuntu ]]; then
40
41 Dockerfile=$(cat << EOF
42FROM ubuntu:15.10
43
44ENV DEBIAN_FRONTEND noninteractive
45RUN echo $(date +%s) && apt-get update && \
46 apt-get install -y \
47 cscope ctags libz-dev libexpat-dev python language-pack-en texinfo \
48 build-essential g++ git bison flex unzip libxml-simple-perl \
49 libxml-sax-perl libxml2-dev libxml2-utils xsltproc
50RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
51
52USER ${USER}
53ENV HOME ${HOME}
54RUN /bin/bash
55EOF
56)
57fi
58
59# Build the docker container
60docker build -t op-build/${distro} - <<< "${Dockerfile}"
61if [[ "$?" -ne 0 ]]; then
62 echo "Failed to build docker container."
63 exit 1
64fi
65
66mkdir -p ${WORKSPACE}
67
68cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
69#!/bin/bash
70
71set -x
72
73cd ${WORKSPACE}/op-build
74
75# Source our build env
76. op-build-env
77
78# Configure
79make ${target}_defconfig
80
81# Kick off a build
82make
83
84EOF_SCRIPT
85
86chmod a+x ${WORKSPACE}/build.sh
87
88# Run the docker container, execute the build script we just built
89docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
90 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
91
92# Create link to images for archiving
93ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
94
95# Timestamp for build
96echo "Build completed, $(date)"