Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 1 | #!/bin/bash |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 2 | ############################################################################### |
| 3 | # |
| 4 | # This build script is for running the QEMU build as a container with the |
| 5 | # option of launching the container with Docker or Kubernetes. |
| 6 | # |
| 7 | ############################################################################### |
| 8 | # |
| 9 | # Variables used for in the build: |
| 10 | # WORKSPACE = Path of the workspace directory where some intermediate files |
| 11 | # and the images will be saved to. |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame^] | 12 | # qemudir = Path of the directory that holds the QEMU repo, if none |
| 13 | # exists will clone in the OpenBMC/QEMU repo to WORKSPACE. |
| 14 | # builddir = Path of the directory that is created within the docker |
| 15 | # container where the build is actually done. Done this way to |
| 16 | # allow external volumes to be used for the qemudir. |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 17 | # |
| 18 | # Optional Variables: |
| 19 | # launch = job|pod |
| 20 | # Can be left blank to launch via Docker if not using |
| 21 | # Kubernetes to launch the container. |
| 22 | # Job lets you keep a copy of job and container logs on the |
| 23 | # api, can be useful if not using Jenkins as you can run the |
| 24 | # job again via the api without needing this script. |
| 25 | # Pod launches a container which runs to completion without |
| 26 | # saving anything to the api when it completes. |
| 27 | # imgname = Defaults to qemu-build with the arch as its tag, can be |
| 28 | # changed or passed to give a specific name to created image. |
| 29 | # http_proxy = The HTTP address for the proxy server you wish to connect to. |
| 30 | # |
| 31 | ############################################################################### |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 32 | |
| 33 | # Trace bash processing |
| 34 | set -x |
| 35 | |
| 36 | # Default variables |
| 37 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 38 | http_proxy=${http_proxy:-} |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 39 | launch=${launch:-} |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 40 | qemudir=${qemudir:-${WORKSPACE}/qemu} |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame^] | 41 | builddir=${builddir:-/tmp/qemu} |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 42 | ARCH=$(uname -m) |
| 43 | imgname=${imgname:-qemu-build:${ARCH}} |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 44 | |
| 45 | # Timestamp for job |
| 46 | echo "Build started, $(date)" |
| 47 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 48 | # Setup Proxy |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 49 | if [[ -n "${http_proxy}" ]]; then |
| 50 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 51 | fi |
| 52 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 53 | # Determine the prefix of the Dockerfile's base image |
| 54 | case ${ARCH} in |
| 55 | "ppc64le") |
| 56 | DOCKER_BASE="ppc64le/" |
| 57 | ;; |
| 58 | "x86_64") |
| 59 | DOCKER_BASE="" |
| 60 | ;; |
| 61 | *) |
| 62 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 63 | exit 1 |
| 64 | esac |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 65 | |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 66 | # If there is no qemu directory, git clone in the openbmc mirror |
| 67 | if [ ! -d ${qemudir} ]; then |
| 68 | echo "Clone in openbmc master to ${qemudir}" |
| 69 | git clone https://github.com/openbmc/qemu ${qemudir} |
| 70 | fi |
| 71 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 72 | # Create the docker run script |
| 73 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 74 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 75 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 76 | |
| 77 | mkdir -p ${WORKSPACE} |
| 78 | |
| 79 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 80 | #!/bin/bash |
| 81 | |
| 82 | set -x |
| 83 | |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame^] | 84 | # create a copy of the qemudir in /qemu to use as the build directory |
| 85 | cp -a ${qemudir}/. ${builddir} |
| 86 | |
| 87 | # Go into the build directory |
| 88 | cd ${builddir} |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 89 | |
| 90 | gcc --version |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 91 | git submodule update --init dtc |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 92 | # disable anything that requires us to pull in X |
Alanny Lopez | e30237c | 2017-06-15 13:27:47 -0500 | [diff] [blame] | 93 | ./configure \ |
| 94 | --target-list=arm-softmmu \ |
| 95 | --disable-spice \ |
| 96 | --disable-docs \ |
| 97 | --disable-gtk \ |
| 98 | --disable-smartcard \ |
| 99 | --disable-usb-redir \ |
| 100 | --disable-libusb \ |
| 101 | --disable-sdl \ |
| 102 | --disable-gnutls \ |
| 103 | --disable-vte \ |
| 104 | --disable-vnc \ |
| 105 | --disable-vnc-png |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 106 | make -j4 |
| 107 | |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame^] | 108 | cp -a ${builddir}/arm-softmmu/. ${WORKSPACE}/arm-softmmu/ |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 109 | EOF_SCRIPT |
| 110 | |
| 111 | chmod a+x ${WORKSPACE}/build.sh |
| 112 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 113 | # Configure docker build |
| 114 | Dockerfile=$(cat << EOF |
| 115 | FROM ${DOCKER_BASE}ubuntu:16.04 |
| 116 | |
| 117 | ${PROXY} |
| 118 | |
| 119 | ENV DEBIAN_FRONTEND noninteractive |
| 120 | RUN apt-get update && apt-get install -yy --no-install-recommends \ |
| 121 | bison \ |
| 122 | flex \ |
| 123 | gcc \ |
| 124 | git \ |
| 125 | libc6-dev \ |
| 126 | libfdt-dev \ |
| 127 | libglib2.0-dev \ |
| 128 | libpixman-1-dev \ |
| 129 | make \ |
| 130 | python-yaml \ |
| 131 | python3-yaml |
| 132 | |
| 133 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 134 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 135 | USER ${USER} |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame^] | 136 | RUN mkdir ${builddir} |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 137 | ENV HOME ${HOME} |
| 138 | EOF |
| 139 | ) |
| 140 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 141 | # If Launch is left empty will create a docker container |
| 142 | if [[ "${launch}" == "" ]]; then |
| 143 | |
| 144 | docker build -t ${imgname} - <<< "${Dockerfile}" |
| 145 | if [[ "$?" -ne 0 ]]; then |
| 146 | echo "Failed to build docker container." |
| 147 | exit 1 |
| 148 | fi |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 149 | mountqemu="-v ""${qemudir}"":""${qemudir}"" " |
Alanny Lopez | 634ce36 | 2017-06-23 12:57:05 -0500 | [diff] [blame] | 150 | if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]]; then |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 151 | mountqemu="" |
| 152 | fi |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 153 | docker run \ |
| 154 | --rm=true \ |
| 155 | -e WORKSPACE=${WORKSPACE} \ |
| 156 | -w "${HOME}" \ |
| 157 | -v "${HOME}":"${HOME}" \ |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 158 | ${mountqemu} \ |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 159 | -t ${imgname} \ |
| 160 | ${WORKSPACE}/build.sh |
Alanny Lopez | 634ce36 | 2017-06-23 12:57:05 -0500 | [diff] [blame] | 161 | elif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then |
| 162 | . ./kubernetes/kubernetes-launch.sh QEMU-build true true |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 163 | else |
| 164 | echo "Launch Parameter is invalid" |
| 165 | fi |
| 166 | |
| 167 | |