blob: 04c8cd62a817e1f60534d891130272149f3fb825 [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
AlannyLopez266312e2017-02-17 10:37:28 -06007# distro = ubuntu|fedora
8# WORKSPACE = Random Number by Default
Joel Stanley2ed389f2015-12-11 15:07:07 +10309
10# Trace bash processing
11set -x
12
13# Default variables
14target=${target:-palmetto}
15distro=${distro:-ubuntu}
16WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Joel Stanley2ed389f2015-12-11 15:07:07 +103017
18# Timestamp for job
19echo "Build started, $(date)"
20
AlannyLopez266312e2017-02-17 10:37:28 -060021# if there is no open-power directory clone in master into workspace
22if [ ! -e ${WORKSPACE}/op-build ]; then
23 echo "Clone in openpower master to ${WORKSPACE}/op-build"
24 git clone --recursive https://github.com/open-power/op-build ${WORKSPACE}/op-build
25fi
26
27# Determine the architecture
28ARCH=$(uname -m)
29
30# Determine the prefix of the Dockerfile's base image
31case ${ARCH} in
32 "ppc64le")
33 DOCKER_BASE="ppc64le/"
34 ;;
35 "x86_64")
36 DOCKER_BASE=""
37 ;;
38 *)
39 echo "Unsupported system architecture(${ARCH}) found for docker image"
40 exit 1
41esac
42
43
Joel Stanley2ed389f2015-12-11 15:07:07 +103044# Configure docker build
45if [[ "${distro}" == fedora ]];then
46
47 Dockerfile=$(cat << EOF
AlannyLopez266312e2017-02-17 10:37:28 -060048FROM ${DOCKER_BASE}fedora:latest
Joel Stanley2ed389f2015-12-11 15:07:07 +103049
Chris Smartfc730ff2016-03-09 20:17:19 +110050RUN dnf --refresh repolist && dnf install -y \
51 bc \
Chris Smart4593d4f2016-03-09 15:50:59 +110052 bison \
Chris Smartfc730ff2016-03-09 20:17:19 +110053 bzip2 \
54 cpio \
AlannyLopez266312e2017-02-17 10:37:28 -060055 cscope \
Chris Smartfc730ff2016-03-09 20:17:19 +110056 ctags \
Chris Smart4593d4f2016-03-09 15:50:59 +110057 expat-devel \
Chris Smartfc730ff2016-03-09 20:17:19 +110058 findutils \
59 flex \
60 gcc-c++ \
61 git \
62 libxml2-devel \
63 ncurses-devel \
Joel Stanley2ab9a212017-03-23 10:56:27 +103064 openssl-devel \
Chris Smart4593d4f2016-03-09 15:50:59 +110065 patch \
Chris Smartfc730ff2016-03-09 20:17:19 +110066 perl \
67 perl-bignum \
68 "perl(Digest::SHA1)" \
Chris Smart905777e2016-03-11 15:01:48 +110069 "perl(Env)" \
Chris Smartfc730ff2016-03-09 20:17:19 +110070 "perl(Fatal)" \
71 "perl(Thread::Queue)" \
72 "perl(XML::SAX)" \
73 "perl(XML::Simple)" \
74 "perl(YAML)" \
75 "perl(XML::LibXML)" \
76 python \
Saqib Khan362ca852017-03-21 10:48:46 -050077 python3 \
Chris Smartfc730ff2016-03-09 20:17:19 +110078 tar \
79 unzip \
80 vim \
81 wget \
82 which \
Chris Smart4593d4f2016-03-09 15:50:59 +110083 zlib-devel \
Chris Smartfc730ff2016-03-09 20:17:19 +110084 zlib-static
Chris Smart4593d4f2016-03-09 15:50:59 +110085
86RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
87RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +103088
89USER ${USER}
90ENV HOME ${HOME}
91RUN /bin/bash
92EOF
93)
94
95elif [[ "${distro}" == ubuntu ]]; then
96
97 Dockerfile=$(cat << EOF
AlannyLopez266312e2017-02-17 10:37:28 -060098FROM ${DOCKER_BASE}ubuntu:latest
Joel Stanley2ed389f2015-12-11 15:07:07 +103099
100ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100101RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100102 bc \
103 bison \
104 build-essential \
105 cscope \
AlannyLopez266312e2017-02-17 10:37:28 -0600106 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100107 ctags \
108 flex \
109 g++ \
110 git \
Joel Stanley2ab9a212017-03-23 10:56:27 +1030111 libssl-dev \
Chris Smart4593d4f2016-03-09 15:50:59 +1100112 libexpat-dev \
113 libz-dev \
114 libxml-sax-perl \
115 libxml-simple-perl \
116 libxml2-dev \
117 libxml2-utils \
118 language-pack-en \
119 python \
Saqib Khan362ca852017-03-21 10:48:46 -0500120 python3 \
Chris Smart4593d4f2016-03-09 15:50:59 +1100121 texinfo \
122 unzip \
123 vim-common \
124 wget\
Rahul Maheshwarid6b829e2017-03-20 13:34:35 -0500125 xsltproc \
126 libssl-dev
Chris Smart4593d4f2016-03-09 15:50:59 +1100127
128RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
129RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +1030130
131USER ${USER}
132ENV HOME ${HOME}
133RUN /bin/bash
134EOF
135)
136fi
137
138# Build the docker container
139docker build -t op-build/${distro} - <<< "${Dockerfile}"
140if [[ "$?" -ne 0 ]]; then
141 echo "Failed to build docker container."
142 exit 1
143fi
144
145mkdir -p ${WORKSPACE}
146
147cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
148#!/bin/bash
149
150set -x
151
Joel Stanley21e65232015-12-11 15:40:54 +1030152# This ensures that the alias set in op-build-env is
153# avalaible in this script
154shopt -s expand_aliases
155
Joel Stanley2ed389f2015-12-11 15:07:07 +1030156cd ${WORKSPACE}/op-build
157
158# Source our build env
159. op-build-env
160
161# Configure
Joel Stanleyf00719d2015-12-11 15:16:32 +1030162op-build ${target}_defconfig
Joel Stanley2ed389f2015-12-11 15:07:07 +1030163
164# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +1030165op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +1030166
167EOF_SCRIPT
168
169chmod a+x ${WORKSPACE}/build.sh
170
171# Run the docker container, execute the build script we just built
172docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
173 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
174
175# Create link to images for archiving
176ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
177
178# Timestamp for build
179echo "Build completed, $(date)"