blob: 47dfa32e789896fb9fc578c5d5223fa397a41e03 [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
Chris Smart4593d4f2016-03-09 15:50:59 +110028RUN dnf --refresh upgrade -y && dnf install -y \
29 vim \
30 gcc-c++ \
31 flex \
32 bison \
33 git \
34 ctags \
35 cscope \
36 expat-devel \
37 patch \
38 zlib-devel \
39 zlib-static perl
40
41RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
42RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +103043
44USER ${USER}
45ENV HOME ${HOME}
46RUN /bin/bash
47EOF
48)
49
50elif [[ "${distro}" == ubuntu ]]; then
51
52 Dockerfile=$(cat << EOF
53FROM ubuntu:15.10
54
55ENV DEBIAN_FRONTEND noninteractive
Chris Smart4593d4f2016-03-09 15:50:59 +110056RUN apt-get update && apt-get upgrade -yy && apt-get install -yy \
57 bc \
58 bison \
59 build-essential \
60 cscope \
61 cpio \
62 ctags \
63 flex \
64 g++ \
65 git \
66 libexpat-dev \
67 libz-dev \
68 libxml-sax-perl \
69 libxml-simple-perl \
70 libxml2-dev \
71 libxml2-utils \
72 language-pack-en \
73 python \
74 texinfo \
75 unzip \
76 vim-common \
77 wget\
78 xsltproc
79
80RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
81RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +103082
83USER ${USER}
84ENV HOME ${HOME}
85RUN /bin/bash
86EOF
87)
88fi
89
90# Build the docker container
91docker build -t op-build/${distro} - <<< "${Dockerfile}"
92if [[ "$?" -ne 0 ]]; then
93 echo "Failed to build docker container."
94 exit 1
95fi
96
97mkdir -p ${WORKSPACE}
98
99cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
100#!/bin/bash
101
102set -x
103
Joel Stanley21e65232015-12-11 15:40:54 +1030104# This ensures that the alias set in op-build-env is
105# avalaible in this script
106shopt -s expand_aliases
107
Joel Stanley2ed389f2015-12-11 15:07:07 +1030108cd ${WORKSPACE}/op-build
109
110# Source our build env
111. op-build-env
112
113# Configure
Joel Stanleyf00719d2015-12-11 15:16:32 +1030114op-build ${target}_defconfig
Joel Stanley2ed389f2015-12-11 15:07:07 +1030115
116# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +1030117op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +1030118
119EOF_SCRIPT
120
121chmod a+x ${WORKSPACE}/build.sh
122
123# Run the docker container, execute the build script we just built
124docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
125 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
126
127# Create link to images for archiving
128ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
129
130# Timestamp for build
131echo "Build completed, $(date)"