blob: de735883148fcfa52a63a94491259012ac93c719 [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
Joel Stanley21e65232015-12-11 15:40:54 +103073# This ensures that the alias set in op-build-env is
74# avalaible in this script
75shopt -s expand_aliases
76
Joel Stanley2ed389f2015-12-11 15:07:07 +103077cd ${WORKSPACE}/op-build
78
79# Source our build env
80. op-build-env
81
82# Configure
Joel Stanleyf00719d2015-12-11 15:16:32 +103083op-build ${target}_defconfig
Joel Stanley2ed389f2015-12-11 15:07:07 +103084
85# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +103086op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +103087
88EOF_SCRIPT
89
90chmod a+x ${WORKSPACE}/build.sh
91
92# Run the docker container, execute the build script we just built
93docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
94 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
95
96# Create link to images for archiving
97ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
98
99# Timestamp for build
100echo "Build completed, $(date)"