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