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