blob: fa79635d751e07907091d6490aac393c8e66f5b8 [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 \
Chris Smart4593d4f2016-03-09 15:50:59 +110064 patch \
Chris Smartfc730ff2016-03-09 20:17:19 +110065 perl \
66 perl-bignum \
67 "perl(Digest::SHA1)" \
Chris Smart905777e2016-03-11 15:01:48 +110068 "perl(Env)" \
Chris Smartfc730ff2016-03-09 20:17:19 +110069 "perl(Fatal)" \
70 "perl(Thread::Queue)" \
71 "perl(XML::SAX)" \
72 "perl(XML::Simple)" \
73 "perl(YAML)" \
74 "perl(XML::LibXML)" \
75 python \
Saqib Khan362ca852017-03-21 10:48:46 -050076 python3 \
Chris Smartfc730ff2016-03-09 20:17:19 +110077 tar \
78 unzip \
79 vim \
80 wget \
81 which \
Chris Smart4593d4f2016-03-09 15:50:59 +110082 zlib-devel \
Chris Smartfc730ff2016-03-09 20:17:19 +110083 zlib-static
Chris Smart4593d4f2016-03-09 15:50:59 +110084
85RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
86RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +103087
88USER ${USER}
89ENV HOME ${HOME}
90RUN /bin/bash
91EOF
92)
93
94elif [[ "${distro}" == ubuntu ]]; then
95
96 Dockerfile=$(cat << EOF
AlannyLopez266312e2017-02-17 10:37:28 -060097FROM ${DOCKER_BASE}ubuntu:latest
Joel Stanley2ed389f2015-12-11 15:07:07 +103098
99ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100100RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100101 bc \
102 bison \
103 build-essential \
104 cscope \
AlannyLopez266312e2017-02-17 10:37:28 -0600105 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100106 ctags \
107 flex \
108 g++ \
109 git \
110 libexpat-dev \
111 libz-dev \
112 libxml-sax-perl \
113 libxml-simple-perl \
114 libxml2-dev \
115 libxml2-utils \
116 language-pack-en \
117 python \
Saqib Khan362ca852017-03-21 10:48:46 -0500118 python3 \
Chris Smart4593d4f2016-03-09 15:50:59 +1100119 texinfo \
120 unzip \
121 vim-common \
122 wget\
Rahul Maheshwarid6b829e2017-03-20 13:34:35 -0500123 xsltproc \
124 libssl-dev
Chris Smart4593d4f2016-03-09 15:50:59 +1100125
126RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
127RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +1030128
129USER ${USER}
130ENV HOME ${HOME}
131RUN /bin/bash
132EOF
133)
134fi
135
136# Build the docker container
137docker build -t op-build/${distro} - <<< "${Dockerfile}"
138if [[ "$?" -ne 0 ]]; then
139 echo "Failed to build docker container."
140 exit 1
141fi
142
143mkdir -p ${WORKSPACE}
144
145cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
146#!/bin/bash
147
148set -x
149
Joel Stanley21e65232015-12-11 15:40:54 +1030150# This ensures that the alias set in op-build-env is
151# avalaible in this script
152shopt -s expand_aliases
153
Joel Stanley2ed389f2015-12-11 15:07:07 +1030154cd ${WORKSPACE}/op-build
155
156# Source our build env
157. op-build-env
158
159# Configure
Joel Stanleyf00719d2015-12-11 15:16:32 +1030160op-build ${target}_defconfig
Joel Stanley2ed389f2015-12-11 15:07:07 +1030161
162# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +1030163op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +1030164
165EOF_SCRIPT
166
167chmod a+x ${WORKSPACE}/build.sh
168
169# Run the docker container, execute the build script we just built
170docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
171 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
172
173# Create link to images for archiving
174ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
175
176# Timestamp for build
177echo "Build completed, $(date)"