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 | ;; |
Joel Stanley | 0e07720 | 2016-06-28 16:42:45 +0930 | [diff] [blame] | 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 | ;; |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 43 | qemu) |
| 44 | BITBAKE_CMD="source openbmc-env" |
| 45 | ;; |
| 46 | *) |
| 47 | exit 1 |
| 48 | ;; |
| 49 | esac |
| 50 | |
| 51 | # Configure docker build |
| 52 | if [[ "${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 |
| 59 | FROM fedora:latest |
| 60 | |
| 61 | ${PROXY} |
| 62 | |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 63 | RUN dnf --refresh install -y \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 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 |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 85 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 86 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 87 | 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] | 88 | |
| 89 | USER ${USER} |
| 90 | ENV HOME ${HOME} |
| 91 | RUN /bin/bash |
| 92 | EOF |
| 93 | ) |
| 94 | |
| 95 | elif [[ "${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 |
| 101 | FROM ubuntu:latest |
| 102 | |
| 103 | ${PROXY} |
| 104 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 105 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 106 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 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 |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 121 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 122 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 123 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 124 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 125 | USER ${USER} |
| 126 | ENV HOME ${HOME} |
| 127 | RUN /bin/bash |
| 128 | EOF |
| 129 | ) |
| 130 | fi |
| 131 | |
| 132 | # Build the docker container |
| 133 | docker build -t openbmc/${distro} - <<< "${Dockerfile}" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 134 | |
| 135 | # Create the docker run script |
| 136 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 137 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 138 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 139 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 140 | mkdir -p ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 141 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 142 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 143 | #!/bin/bash |
| 144 | |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 145 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 146 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 147 | cd ${WORKSPACE} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 148 | |
| 149 | # Go into the openbmc directory (the openbmc script will put us in a build subdir) |
| 150 | cd openbmc |
| 151 | |
| 152 | # Set up proxies |
| 153 | export ftp_proxy=${http_proxy} |
| 154 | export http_proxy=${http_proxy} |
| 155 | export https_proxy=${http_proxy} |
| 156 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 157 | mkdir -p ${WORKSPACE}/bin |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 158 | |
| 159 | # Configure proxies for bitbake |
| 160 | if [[ -n "${http_proxy}" ]]; then |
| 161 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 162 | cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 163 | #!/bin/bash |
| 164 | # \$1 = hostname, \$2 = port |
| 165 | PROXY=${PROXY_HOST} |
| 166 | PROXY_PORT=${PROXY_PORT} |
| 167 | exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT} |
| 168 | EOF_GIT |
| 169 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 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} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 172 | git config core.gitProxy git-proxy |
| 173 | |
| 174 | mkdir -p ~/.subversion |
| 175 | |
| 176 | cat > ~/.subversion/servers << EOF_SVN |
| 177 | [global] |
| 178 | http-proxy-host = ${PROXY_HOST} |
| 179 | http-proxy-port = ${PROXY_PORT} |
| 180 | EOF_SVN |
| 181 | fi |
| 182 | |
| 183 | # Source our build env |
| 184 | ${BITBAKE_CMD} |
| 185 | |
| 186 | # Custom bitbake config settings |
| 187 | cat >> conf/local.conf << EOF_CONF |
Chris Smart | c650c20 | 2015-11-25 15:58:53 +1100 | [diff] [blame] | 188 | BB_NUMBER_THREADS = "$(nproc)" |
| 189 | PARALLEL_MAKE = "-j$(nproc)" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 190 | INHERIT += "rm_work" |
| 191 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 192 | DL_DIR="${HOME}/bitbake_downloads" |
Joel Stanley | 1dda089 | 2016-06-06 16:09:56 -0500 | [diff] [blame] | 193 | SSTATE_DIR="${HOME}/bitbake_sharedstatecache" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 194 | USER_CLASSES += "buildstats" |
Andrew Geissler | 931ec67 | 2016-08-11 13:10:05 -0500 | [diff] [blame] | 195 | INHERIT_remove = "uninative" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 196 | EOF_CONF |
| 197 | |
| 198 | # Kick off a build |
| 199 | bitbake obmc-phosphor-image |
| 200 | |
| 201 | EOF_SCRIPT |
| 202 | |
| 203 | chmod a+x ${WORKSPACE}/build.sh |
| 204 | |
| 205 | # Run the docker container, execute the build script we just built |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 206 | docker 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 |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 208 | |
| 209 | # Create link to images for archiving |
| 210 | ln -sf ${WORKSPACE}/openbmc/build/tmp/deploy/images ${WORKSPACE}/images |
| 211 | |
| 212 | # Timestamp for build |
| 213 | echo "Build completed, $(date)" |
| 214 | |