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