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 | ############################################################################### |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 40 | # Trace bash processing |
| 41 | set -x |
| 42 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 43 | # Script Variables: |
| 44 | build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"} |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 45 | http_proxy=${http_proxy:-} |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 46 | qemu_dir=${qemu_dir:-${WORKSPACE}/qemu} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 47 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 48 | |
Joel Stanley | 62d1802 | 2018-08-15 12:46:23 +0930 | [diff] [blame] | 49 | # Determine the architecture |
| 50 | ARCH=$(uname -m) |
| 51 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 52 | # Docker Image Build Variables: |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 53 | build_dir=${build_dir:-/tmp/qemu} |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 54 | img_name=${img_name:-qemu-build:${ARCH}} |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 55 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 56 | # Deployment Variables |
| 57 | launch=${launch:-} |
| 58 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 59 | # Timestamp for job |
| 60 | echo "Build started, $(date)" |
| 61 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 62 | # Setup Proxy |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 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 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 67 | # Determine the prefix of the Dockerfile's base image |
| 68 | case ${ARCH} in |
| 69 | "ppc64le") |
| 70 | DOCKER_BASE="ppc64le/" |
| 71 | ;; |
| 72 | "x86_64") |
| 73 | DOCKER_BASE="" |
| 74 | ;; |
| 75 | *) |
| 76 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 77 | exit 1 |
| 78 | esac |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 79 | |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 80 | # If there is no qemu directory, git clone in the openbmc mirror |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 81 | if [ ! -d ${qemu_dir} ]; then |
| 82 | echo "Clone in openbmc master to ${qemu_dir}" |
| 83 | git clone https://github.com/openbmc/qemu ${qemu_dir} |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 84 | fi |
| 85 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 86 | # Create the docker run script |
| 87 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 88 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 89 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 90 | |
| 91 | mkdir -p ${WORKSPACE} |
| 92 | |
| 93 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 94 | #!/bin/bash |
| 95 | |
| 96 | set -x |
| 97 | |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame] | 98 | # 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] | 99 | cp -a ${qemu_dir}/. ${build_dir} |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame] | 100 | |
| 101 | # Go into the build directory |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 102 | cd ${build_dir} |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 103 | |
| 104 | gcc --version |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 105 | git submodule update --init dtc |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 106 | # disable anything that requires us to pull in X |
Alanny Lopez | e30237c | 2017-06-15 13:27:47 -0500 | [diff] [blame] | 107 | ./configure \ |
| 108 | --target-list=arm-softmmu \ |
| 109 | --disable-spice \ |
| 110 | --disable-docs \ |
| 111 | --disable-gtk \ |
| 112 | --disable-smartcard \ |
| 113 | --disable-usb-redir \ |
| 114 | --disable-libusb \ |
| 115 | --disable-sdl \ |
| 116 | --disable-gnutls \ |
| 117 | --disable-vte \ |
| 118 | --disable-vnc \ |
Joel Stanley | e32aaee | 2018-10-24 15:30:17 +1030 | [diff] [blame] | 119 | --disable-werror \ |
Alanny Lopez | e30237c | 2017-06-15 13:27:47 -0500 | [diff] [blame] | 120 | --disable-vnc-png |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 121 | make -j4 |
| 122 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 123 | cp -a ${build_dir}/arm-softmmu/. ${WORKSPACE}/arm-softmmu/ |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 124 | EOF_SCRIPT |
| 125 | |
| 126 | chmod a+x ${WORKSPACE}/build.sh |
| 127 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 128 | # Configure docker build |
| 129 | Dockerfile=$(cat << EOF |
| 130 | FROM ${DOCKER_BASE}ubuntu:16.04 |
| 131 | |
| 132 | ${PROXY} |
| 133 | |
| 134 | ENV DEBIAN_FRONTEND noninteractive |
| 135 | RUN apt-get update && apt-get install -yy --no-install-recommends \ |
| 136 | bison \ |
| 137 | flex \ |
| 138 | gcc \ |
| 139 | git \ |
| 140 | libc6-dev \ |
| 141 | libfdt-dev \ |
| 142 | libglib2.0-dev \ |
| 143 | libpixman-1-dev \ |
| 144 | make \ |
| 145 | python-yaml \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 146 | python3-yaml \ |
| 147 | iputils-ping |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 148 | |
| 149 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 150 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 151 | USER ${USER} |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 152 | RUN mkdir ${build_dir} |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 153 | ENV HOME ${HOME} |
| 154 | EOF |
| 155 | ) |
| 156 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 157 | docker build -t ${img_name} - <<< "${Dockerfile}" |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 158 | # If Launch is left empty will create a docker container |
| 159 | if [[ "${launch}" == "" ]]; then |
| 160 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 161 | if [[ "$?" -ne 0 ]]; then |
| 162 | echo "Failed to build docker container." |
| 163 | exit 1 |
| 164 | fi |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 165 | mount_qemu="-v ""${qemu_dir}"":""${qemu_dir}"" " |
| 166 | if [[ "${qemu_dir}" = "${HOME}/"* || "${qemu_dir}" = "${HOME}" ]]; then |
| 167 | mount_qemu="" |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 168 | fi |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 169 | docker run \ |
| 170 | --rm=true \ |
| 171 | -e WORKSPACE=${WORKSPACE} \ |
| 172 | -w "${HOME}" \ |
| 173 | -v "${HOME}":"${HOME}" \ |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 174 | ${mount_qemu} \ |
| 175 | -t ${img_name} \ |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 176 | ${WORKSPACE}/build.sh |
Alanny Lopez | 634ce36 | 2017-06-23 12:57:05 -0500 | [diff] [blame] | 177 | elif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 178 | . ${build_scripts_dir}/kubernetes/kubernetes-launch.sh QEMU-build true true |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 179 | else |
| 180 | echo "Launch Parameter is invalid" |
| 181 | fi |