blob: 1c771aa130428fc9cc272978d3946984d06e6ce8 [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 \
Joel Stanleyc4c6d432015-12-11 17:27:15 +103049 libxml-sax-perl libxml2-dev libxml2-utils xsltproc wget cpio bc \
50 vim-common
Joel Stanley2ed389f2015-12-11 15:07:07 +103051RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
52
53USER ${USER}
54ENV HOME ${HOME}
55RUN /bin/bash
56EOF
57)
58fi
59
60# Build the docker container
61docker build -t op-build/${distro} - <<< "${Dockerfile}"
62if [[ "$?" -ne 0 ]]; then
63 echo "Failed to build docker container."
64 exit 1
65fi
66
67mkdir -p ${WORKSPACE}
68
69cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
70#!/bin/bash
71
72set -x
73
Joel Stanley21e65232015-12-11 15:40:54 +103074# This ensures that the alias set in op-build-env is
75# avalaible in this script
76shopt -s expand_aliases
77
Joel Stanley2ed389f2015-12-11 15:07:07 +103078cd ${WORKSPACE}/op-build
79
80# Source our build env
81. op-build-env
82
83# Configure
Joel Stanleyf00719d2015-12-11 15:16:32 +103084op-build ${target}_defconfig
Joel Stanley2ed389f2015-12-11 15:07:07 +103085
86# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +103087op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +103088
89EOF_SCRIPT
90
91chmod a+x ${WORKSPACE}/build.sh
92
93# Run the docker container, execute the build script we just built
94docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
95 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
96
97# Create link to images for archiving
98ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
99
100# Timestamp for build
101echo "Build completed, $(date)"