blob: 7920df6e4b092bf339e47e0a92cf264dcfe57254 [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 \
Saqib Khan5158a322017-10-23 11:31:24 -050084 zlib-static \
85 iputils-ping
Chris Smart4593d4f2016-03-09 15:50:59 +110086
87RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
88RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +103089
90USER ${USER}
91ENV HOME ${HOME}
92RUN /bin/bash
93EOF
94)
95
96elif [[ "${distro}" == ubuntu ]]; then
97
98 Dockerfile=$(cat << EOF
AlannyLopez266312e2017-02-17 10:37:28 -060099FROM ${DOCKER_BASE}ubuntu:latest
Joel Stanley2ed389f2015-12-11 15:07:07 +1030100
101ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100102RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100103 bc \
104 bison \
105 build-essential \
106 cscope \
AlannyLopez266312e2017-02-17 10:37:28 -0600107 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100108 ctags \
109 flex \
110 g++ \
111 git \
Joel Stanley2ab9a212017-03-23 10:56:27 +1030112 libssl-dev \
Chris Smart4593d4f2016-03-09 15:50:59 +1100113 libexpat-dev \
114 libz-dev \
115 libxml-sax-perl \
116 libxml-simple-perl \
117 libxml2-dev \
118 libxml2-utils \
119 language-pack-en \
120 python \
Saqib Khan362ca852017-03-21 10:48:46 -0500121 python3 \
Chris Smart4593d4f2016-03-09 15:50:59 +1100122 texinfo \
123 unzip \
124 vim-common \
125 wget\
Rahul Maheshwarid6b829e2017-03-20 13:34:35 -0500126 xsltproc \
Saqib Khan5158a322017-10-23 11:31:24 -0500127 libssl-dev \
128 iputils-ping
Chris Smart4593d4f2016-03-09 15:50:59 +1100129
130RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
131RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +1030132
133USER ${USER}
134ENV HOME ${HOME}
135RUN /bin/bash
136EOF
137)
138fi
139
140# Build the docker container
141docker build -t op-build/${distro} - <<< "${Dockerfile}"
142if [[ "$?" -ne 0 ]]; then
143 echo "Failed to build docker container."
144 exit 1
145fi
146
147mkdir -p ${WORKSPACE}
148
149cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
150#!/bin/bash
151
152set -x
153
Joel Stanley21e65232015-12-11 15:40:54 +1030154# This ensures that the alias set in op-build-env is
155# avalaible in this script
156shopt -s expand_aliases
157
Joel Stanley2ed389f2015-12-11 15:07:07 +1030158cd ${WORKSPACE}/op-build
159
160# Source our build env
161. op-build-env
162
163# Configure
Joel Stanleyf00719d2015-12-11 15:16:32 +1030164op-build ${target}_defconfig
Joel Stanley2ed389f2015-12-11 15:07:07 +1030165
166# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +1030167op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +1030168
169EOF_SCRIPT
170
171chmod a+x ${WORKSPACE}/build.sh
172
173# Run the docker container, execute the build script we just built
174docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
175 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh
176
177# Create link to images for archiving
178ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images
179
180# Timestamp for build
181echo "Build completed, $(date)"