blob: bc43919ae5b470e680a3d83ef98134d1b74e2a41 [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 \
76 tar \
77 unzip \
78 vim \
79 wget \
80 which \
Chris Smart4593d4f2016-03-09 15:50:59 +110081 zlib-devel \
Chris Smartfc730ff2016-03-09 20:17:19 +110082 zlib-static
Chris Smart4593d4f2016-03-09 15:50:59 +110083
84RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
85RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +103086
87USER ${USER}
88ENV HOME ${HOME}
89RUN /bin/bash
90EOF
91)
92
93elif [[ "${distro}" == ubuntu ]]; then
94
95 Dockerfile=$(cat << EOF
AlannyLopez266312e2017-02-17 10:37:28 -060096FROM ${DOCKER_BASE}ubuntu:latest
Joel Stanley2ed389f2015-12-11 15:07:07 +103097
98ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110099RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100100 bc \
101 bison \
102 build-essential \
103 cscope \
AlannyLopez266312e2017-02-17 10:37:28 -0600104 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100105 ctags \
106 flex \
107 g++ \
108 git \
109 libexpat-dev \
110 libz-dev \
111 libxml-sax-perl \
112 libxml-simple-perl \
113 libxml2-dev \
114 libxml2-utils \
115 language-pack-en \
116 python \
117 texinfo \
118 unzip \
119 vim-common \
120 wget\
121 xsltproc
122
123RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
124RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +1030125
126USER ${USER}
127ENV HOME ${HOME}
128RUN /bin/bash
129EOF
130)
131fi
132
133# Build the docker container
134docker build -t op-build/${distro} - <<< "${Dockerfile}"
135if [[ "$?" -ne 0 ]]; then
136 echo "Failed to build docker container."
137 exit 1
138fi
139
140mkdir -p ${WORKSPACE}
141
142cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
143#!/bin/bash
144
145set -x
146
Joel Stanley21e65232015-12-11 15:40:54 +1030147# This ensures that the alias set in op-build-env is
148# avalaible in this script
149shopt -s expand_aliases
150
Joel Stanley2ed389f2015-12-11 15:07:07 +1030151cd ${WORKSPACE}/op-build
152
153# Source our build env
154. op-build-env
155
156# Configure
Joel Stanleyf00719d2015-12-11 15:16:32 +1030157op-build ${target}_defconfig
Joel Stanley2ed389f2015-12-11 15:07:07 +1030158
159# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +1030160op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +1030161
162EOF_SCRIPT
163
164chmod a+x ${WORKSPACE}/build.sh
165
166# Run the docker container, execute the build script we just built
167docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
168 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
169
170# Create link to images for archiving
171ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
172
173# Timestamp for build
174echo "Build completed, $(date)"