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