blob: 3d8bc7323c8a2188241729b688fcbbb7d551752c [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
Patrick Williams384d7412020-11-06 16:15:41 -060022if [ ! -e "${WORKSPACE}"/op-build ]; then
AlannyLopez266312e2017-02-17 10:37:28 -060023 echo "Clone in openpower master to ${WORKSPACE}/op-build"
Patrick Williams384d7412020-11-06 16:15:41 -060024 git clone --recursive https://github.com/open-power/op-build "${WORKSPACE}"/op-build
AlannyLopez266312e2017-02-17 10:37:28 -060025fi
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 ;;
Thang Q. Nguyen051b05b2021-12-10 08:30:35 +000038 "aarch64")
Thang Q. Nguyenf98f1a82021-12-22 01:59:19 +000039 DOCKER_BASE="arm64v8/"
Thang Q. Nguyen051b05b2021-12-10 08:30:35 +000040 ;;
AlannyLopez266312e2017-02-17 10:37:28 -060041 *)
42 echo "Unsupported system architecture(${ARCH}) found for docker image"
43 exit 1
44esac
45
46
Joel Stanley2ed389f2015-12-11 15:07:07 +103047# Configure docker build
48if [[ "${distro}" == fedora ]];then
49
50 Dockerfile=$(cat << EOF
AlannyLopez266312e2017-02-17 10:37:28 -060051FROM ${DOCKER_BASE}fedora:latest
Joel Stanley2ed389f2015-12-11 15:07:07 +103052
Chris Smartfc730ff2016-03-09 20:17:19 +110053RUN dnf --refresh repolist && dnf install -y \
54 bc \
Chris Smart4593d4f2016-03-09 15:50:59 +110055 bison \
Chris Smartfc730ff2016-03-09 20:17:19 +110056 bzip2 \
57 cpio \
AlannyLopez266312e2017-02-17 10:37:28 -060058 cscope \
Chris Smartfc730ff2016-03-09 20:17:19 +110059 ctags \
Chris Smart4593d4f2016-03-09 15:50:59 +110060 expat-devel \
Chris Smartfc730ff2016-03-09 20:17:19 +110061 findutils \
62 flex \
63 gcc-c++ \
64 git \
65 libxml2-devel \
66 ncurses-devel \
Joel Stanley2ab9a212017-03-23 10:56:27 +103067 openssl-devel \
Chris Smart4593d4f2016-03-09 15:50:59 +110068 patch \
Chris Smartfc730ff2016-03-09 20:17:19 +110069 perl \
70 perl-bignum \
71 "perl(Digest::SHA1)" \
Chris Smart905777e2016-03-11 15:01:48 +110072 "perl(Env)" \
Chris Smartfc730ff2016-03-09 20:17:19 +110073 "perl(Fatal)" \
74 "perl(Thread::Queue)" \
75 "perl(XML::SAX)" \
76 "perl(XML::Simple)" \
77 "perl(YAML)" \
78 "perl(XML::LibXML)" \
79 python \
Saqib Khan362ca852017-03-21 10:48:46 -050080 python3 \
Chris Smartfc730ff2016-03-09 20:17:19 +110081 tar \
82 unzip \
83 vim \
84 wget \
85 which \
Chris Smart4593d4f2016-03-09 15:50:59 +110086 zlib-devel \
Saqib Khan5158a322017-10-23 11:31:24 -050087 zlib-static \
88 iputils-ping
Chris Smart4593d4f2016-03-09 15:50:59 +110089
Patrick Williams384d7412020-11-06 16:15:41 -060090RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
91RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +103092
93USER ${USER}
94ENV HOME ${HOME}
95RUN /bin/bash
96EOF
97)
98
99elif [[ "${distro}" == ubuntu ]]; then
100
101 Dockerfile=$(cat << EOF
AlannyLopez266312e2017-02-17 10:37:28 -0600102FROM ${DOCKER_BASE}ubuntu:latest
Joel Stanley2ed389f2015-12-11 15:07:07 +1030103
104ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +1100105RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +1100106 bc \
107 bison \
108 build-essential \
109 cscope \
AlannyLopez266312e2017-02-17 10:37:28 -0600110 cpio \
Chris Smart4593d4f2016-03-09 15:50:59 +1100111 ctags \
112 flex \
113 g++ \
114 git \
Joel Stanley2ab9a212017-03-23 10:56:27 +1030115 libssl-dev \
Chris Smart4593d4f2016-03-09 15:50:59 +1100116 libexpat-dev \
117 libz-dev \
118 libxml-sax-perl \
119 libxml-simple-perl \
120 libxml2-dev \
121 libxml2-utils \
122 language-pack-en \
123 python \
Saqib Khan362ca852017-03-21 10:48:46 -0500124 python3 \
Chris Smart4593d4f2016-03-09 15:50:59 +1100125 texinfo \
126 unzip \
127 vim-common \
128 wget\
Rahul Maheshwarid6b829e2017-03-20 13:34:35 -0500129 xsltproc \
Saqib Khan5158a322017-10-23 11:31:24 -0500130 libssl-dev \
131 iputils-ping
Chris Smart4593d4f2016-03-09 15:50:59 +1100132
Patrick Williams384d7412020-11-06 16:15:41 -0600133RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
134RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Joel Stanley2ed389f2015-12-11 15:07:07 +1030135
136USER ${USER}
137ENV HOME ${HOME}
138RUN /bin/bash
139EOF
140)
141fi
142
143# Build the docker container
Patrick Williams384d7412020-11-06 16:15:41 -0600144if ! docker build -t op-build/"${distro}" - <<< "${Dockerfile}" ; then
Joel Stanley2ed389f2015-12-11 15:07:07 +1030145 echo "Failed to build docker container."
146 exit 1
147fi
148
Patrick Williams384d7412020-11-06 16:15:41 -0600149mkdir -p "${WORKSPACE}"
Joel Stanley2ed389f2015-12-11 15:07:07 +1030150
151cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
152#!/bin/bash
153
154set -x
155
Joel Stanley21e65232015-12-11 15:40:54 +1030156# This ensures that the alias set in op-build-env is
157# avalaible in this script
158shopt -s expand_aliases
159
Patrick Williams384d7412020-11-06 16:15:41 -0600160cd "${WORKSPACE}"/op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +1030161
162# Source our build env
163. op-build-env
164
165# Configure
Patrick Williams384d7412020-11-06 16:15:41 -0600166op-build "${target}_defconfig"
Joel Stanley2ed389f2015-12-11 15:07:07 +1030167
168# Kick off a build
Joel Stanleyf00719d2015-12-11 15:16:32 +1030169op-build
Joel Stanley2ed389f2015-12-11 15:07:07 +1030170
171EOF_SCRIPT
172
Patrick Williams384d7412020-11-06 16:15:41 -0600173chmod a+x "${WORKSPACE}"/build.sh
Joel Stanley2ed389f2015-12-11 15:07:07 +1030174
175# Run the docker container, execute the build script we just built
Patrick Williams384d7412020-11-06 16:15:41 -0600176docker run --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \
177 -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/"${distro}" "${WORKSPACE}"/build.sh
Joel Stanley2ed389f2015-12-11 15:07:07 +1030178
179# Create link to images for archiving
Patrick Williams384d7412020-11-06 16:15:41 -0600180ln -sf "${WORKSPACE}"/op-build/output/images "${WORKSPACE}"/images
Joel Stanley2ed389f2015-12-11 15:07:07 +1030181
182# Timestamp for build
183echo "Build completed, $(date)"