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