1#!/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 = barreleye|palmetto|qemu 7# distro = fedora|ubuntu|ubuntu:14.04|ubuntu:16.04 8# obmcdir = <name of openbmc src dir> (default openbmc) 9# WORKSPACE = <location of base openbmc/openbmc repo> 10 11# Trace bash processing. Set -e so when a step fails, we fail the build 12set -xeo pipefail 13 14# Default variables 15target=${target:-qemu} 16distro=${distro:-ubuntu} 17obmcdir=${obmcdir:-openbmc} 18WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} 19http_proxy=${http_proxy:-} 20PROXY="" 21 22# Determine our architecture, ppc64le or the other one 23if [ $(uname -m) == "ppc64le" ]; then 24 DOCKER_BASE="ppc64le/" 25else 26 DOCKER_BASE="" 27fi 28 29# Timestamp for job 30echo "Build started, $(date)" 31 32# If there's no openbmc dir in WORKSPACE then just clone in master 33if [ ! -d ${WORKSPACE}/${obmcdir} ]; then 34 echo "Clone in openbmc master to ${WORKSPACE}/${obmcdir}" 35 git clone https://github.com/openbmc/openbmc ${WORKSPACE}/${obmcdir} 36fi 37 38# if user just passed in ubuntu then use latest 39if [[ $distro == "ubuntu" ]]; then 40 distro="ubuntu:latest" 41fi 42 43# Work out what build target we should be running and set bitbake command 44case ${target} in 45 barreleye) 46 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf source oe-init-build-env" 47 ;; 48 palmetto) 49 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf source oe-init-build-env" 50 ;; 51 witherspoon) 52 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/conf source oe-init-build-env" 53 ;; 54 firestone) 55 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-firestone/conf source oe-init-build-env" 56 ;; 57 garrison) 58 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-garrison/conf source oe-init-build-env" 59 ;; 60 evb-ast2500) 61 BITBAKE_CMD="TEMPLATECONF=meta-openbmc-machines/meta-evb/meta-evb-aspeed/meta-evb-ast2500/conf source oe-init-build-env" 62 ;; 63 qemu) 64 BITBAKE_CMD="source openbmc-env" 65 ;; 66 *) 67 exit 1 68 ;; 69esac 70 71# Configure docker build 72if [[ "${distro}" == fedora ]];then 73 74 if [[ -n "${http_proxy}" ]]; then 75 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" 76 fi 77 78 Dockerfile=$(cat << EOF 79FROM ${DOCKER_BASE}fedora:latest 80 81${PROXY} 82 83RUN dnf --refresh install -y \ 84 bzip2 \ 85 chrpath \ 86 cpio \ 87 diffstat \ 88 findutils \ 89 gcc \ 90 gcc-c++ \ 91 git \ 92 make \ 93 patch \ 94 perl-bignum \ 95 perl-Data-Dumper \ 96 perl-Thread-Queue \ 97 python-devel \ 98 SDL-devel \ 99 socat \ 100 subversion \ 101 tar \ 102 texinfo \ 103 wget \ 104 which 105 106RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} 107RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} 108 109USER ${USER} 110ENV HOME ${HOME} 111RUN /bin/bash 112EOF 113) 114 115elif [[ "${distro}" == "ubuntu"* ]]; then 116 if [[ -n "${http_proxy}" ]]; then 117 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 118 fi 119 120 Dockerfile=$(cat << EOF 121FROM ${DOCKER_BASE}${distro} 122 123${PROXY} 124 125ENV DEBIAN_FRONTEND noninteractive 126RUN apt-get update && apt-get install -yy \ 127 build-essential \ 128 chrpath \ 129 debianutils \ 130 diffstat \ 131 gawk \ 132 git \ 133 libdata-dumper-simple-perl \ 134 libsdl1.2-dev \ 135 libthread-queue-any-perl \ 136 python \ 137 socat \ 138 subversion \ 139 texinfo \ 140 cpio \ 141 wget 142 143RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} 144RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} 145 146USER ${USER} 147ENV HOME ${HOME} 148RUN /bin/bash 149EOF 150) 151fi 152 153# Build the docker container 154docker build -t openbmc/${distro} - <<< "${Dockerfile}" 155 156# Create the docker run script 157export PROXY_HOST=${http_proxy/#http*:\/\/} 158export PROXY_HOST=${PROXY_HOST/%:[0-9]*} 159export PROXY_PORT=${http_proxy/#http*:\/\/*:} 160 161mkdir -p ${WORKSPACE} 162 163cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 164#!/bin/bash 165 166set -xeo pipefail 167 168cd ${WORKSPACE} 169 170# Go into the openbmc directory (the openbmc script will put us in a build subdir) 171cd ${obmcdir} 172 173# Set up proxies 174export ftp_proxy=${http_proxy} 175export http_proxy=${http_proxy} 176export https_proxy=${http_proxy} 177 178mkdir -p ${WORKSPACE}/bin 179 180# Configure proxies for bitbake 181if [[ -n "${http_proxy}" ]]; then 182 183 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT 184#!/bin/bash 185# \$1 = hostname, \$2 = port 186PROXY=${PROXY_HOST} 187PROXY_PORT=${PROXY_PORT} 188exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT} 189EOF_GIT 190 191 chmod a+x ${WORKSPACE}/bin/git-proxy 192 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH} 193 git config core.gitProxy git-proxy 194 195 mkdir -p ~/.subversion 196 197 cat > ~/.subversion/servers << EOF_SVN 198[global] 199http-proxy-host = ${PROXY_HOST} 200http-proxy-port = ${PROXY_PORT} 201EOF_SVN 202fi 203 204# Source our build env 205${BITBAKE_CMD} 206 207# Custom bitbake config settings 208cat >> conf/local.conf << EOF_CONF 209BB_NUMBER_THREADS = "$(nproc)" 210PARALLEL_MAKE = "-j$(nproc)" 211INHERIT += "rm_work" 212BB_GENERATE_MIRROR_TARBALLS = "1" 213DL_DIR="${HOME}/bitbake_downloads" 214SSTATE_DIR="${HOME}/bitbake_sharedstatecache" 215USER_CLASSES += "buildstats" 216INHERIT_remove = "uninative" 217EOF_CONF 218 219# Kick off a build 220bitbake obmc-phosphor-image 221 222EOF_SCRIPT 223 224chmod a+x ${WORKSPACE}/build.sh 225 226# Run the docker container, execute the build script we just built 227docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ 228 -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh 229 230# Create link to images for archiving 231ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images 232 233# Timestamp for build 234echo "Build completed, $(date)" 235 236