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 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame^] | 51 | RUN dnf --refresh upgrade -y && dnf install -y \ |
| 52 | bzip2 \ |
| 53 | chrpath \ |
| 54 | cpio \ |
| 55 | diffstat \ |
| 56 | findutils \ |
| 57 | gcc \ |
| 58 | gcc-c++ \ |
| 59 | git \ |
| 60 | make \ |
| 61 | patch \ |
| 62 | perl-bignum \ |
| 63 | perl-Data-Dumper \ |
| 64 | perl-Thread-Queue \ |
| 65 | python-devel \ |
| 66 | SDL-devel \ |
| 67 | socat \ |
| 68 | subversion \ |
| 69 | tar \ |
| 70 | texinfo \ |
| 71 | wget \ |
| 72 | which |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 73 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 74 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 75 | 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] | 76 | |
| 77 | USER ${USER} |
| 78 | ENV HOME ${HOME} |
| 79 | RUN /bin/bash |
| 80 | EOF |
| 81 | ) |
| 82 | |
| 83 | elif [[ "${distro}" == ubuntu ]]; then |
| 84 | if [[ -n "${http_proxy}" ]]; then |
| 85 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 86 | fi |
| 87 | |
| 88 | Dockerfile=$(cat << EOF |
| 89 | FROM ubuntu:latest |
| 90 | |
| 91 | ${PROXY} |
| 92 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame^] | 93 | ENV DEBIAN_FRONTEND noninteractive |
| 94 | RUN apt-get update && apt-get upgrade -yy && apt-get install -yy \ |
| 95 | build-essential \ |
| 96 | chrpath \ |
| 97 | debianutils \ |
| 98 | diffstat \ |
| 99 | gawk \ |
| 100 | git \ |
| 101 | libdata-dumper-simple-perl \ |
| 102 | libsdl1.2-dev \ |
| 103 | libthread-queue-any-perl \ |
| 104 | python \ |
| 105 | socat \ |
| 106 | subversion \ |
| 107 | texinfo \ |
| 108 | wget |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 109 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 110 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 111 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 112 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 113 | USER ${USER} |
| 114 | ENV HOME ${HOME} |
| 115 | RUN /bin/bash |
| 116 | EOF |
| 117 | ) |
| 118 | fi |
| 119 | |
| 120 | # Build the docker container |
| 121 | docker build -t openbmc/${distro} - <<< "${Dockerfile}" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 122 | |
| 123 | # Create the docker run script |
| 124 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 125 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 126 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 127 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 128 | mkdir -p ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 129 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 130 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 131 | #!/bin/bash |
| 132 | |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 133 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 134 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 135 | cd ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 136 | |
| 137 | # Go into the openbmc directory (the openbmc script will put us in a build subdir) |
| 138 | cd openbmc |
| 139 | |
| 140 | # Set up proxies |
| 141 | export ftp_proxy=${http_proxy} |
| 142 | export http_proxy=${http_proxy} |
| 143 | export https_proxy=${http_proxy} |
| 144 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 145 | mkdir -p ${WORKSPACE}/bin |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 146 | |
| 147 | # Configure proxies for bitbake |
| 148 | if [[ -n "${http_proxy}" ]]; then |
| 149 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 150 | cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 151 | #!/bin/bash |
| 152 | # \$1 = hostname, \$2 = port |
| 153 | PROXY=${PROXY_HOST} |
| 154 | PROXY_PORT=${PROXY_PORT} |
| 155 | exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT} |
| 156 | EOF_GIT |
| 157 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 158 | chmod a+x ${WORKSPACE}/bin/git-proxy |
| 159 | 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] | 160 | git config core.gitProxy git-proxy |
| 161 | |
| 162 | mkdir -p ~/.subversion |
| 163 | |
| 164 | cat > ~/.subversion/servers << EOF_SVN |
| 165 | [global] |
| 166 | http-proxy-host = ${PROXY_HOST} |
| 167 | http-proxy-port = ${PROXY_PORT} |
| 168 | EOF_SVN |
| 169 | fi |
| 170 | |
| 171 | # Source our build env |
| 172 | ${BITBAKE_CMD} |
| 173 | |
| 174 | # Custom bitbake config settings |
| 175 | cat >> conf/local.conf << EOF_CONF |
Chris Smart | c650c20 | 2015-11-25 15:58:53 +1100 | [diff] [blame] | 176 | BB_NUMBER_THREADS = "$(nproc)" |
| 177 | PARALLEL_MAKE = "-j$(nproc)" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 178 | INHERIT += "rm_work" |
| 179 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 180 | DL_DIR="${HOME}/bitbake_downloads" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 181 | USER_CLASSES += "buildstats" |
| 182 | EOF_CONF |
| 183 | |
| 184 | # Kick off a build |
| 185 | bitbake obmc-phosphor-image |
| 186 | |
| 187 | EOF_SCRIPT |
| 188 | |
| 189 | chmod a+x ${WORKSPACE}/build.sh |
| 190 | |
| 191 | # Run the docker container, execute the build script we just built |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 192 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 193 | -w "${HOME}" -v "${HOME}":"${HOME}" -t openbmc/${distro} ${WORKSPACE}/build.sh |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 194 | |
| 195 | # Create link to images for archiving |
| 196 | ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images |
| 197 | |
| 198 | # Timestamp for build |
| 199 | echo "Build completed, $(date)" |
| 200 | |