10b851182SJoel Stanley#!/bin/bash 2cce369b6SAlanny Lopez############################################################################### 3cce369b6SAlanny Lopez# 4cce369b6SAlanny Lopez# This build script is for running the QEMU build as a container with the 5cce369b6SAlanny Lopez# option of launching the container with Docker or Kubernetes. 6cce369b6SAlanny Lopez# 7cce369b6SAlanny Lopez############################################################################### 8cce369b6SAlanny Lopez# 9cce369b6SAlanny Lopez# Variables used for in the build: 10cce369b6SAlanny Lopez# WORKSPACE = Path of the workspace directory where some intermediate files 11cce369b6SAlanny Lopez# and the images will be saved to. 12cce369b6SAlanny Lopez# qemudir = Path of the QEMU directory where the build will be done, if 13cce369b6SAlanny Lopez# none exists will clone in the OpenBMC/QEMU repo to WORKSPACE. 14cce369b6SAlanny Lopez# 15cce369b6SAlanny Lopez# Optional Variables: 16cce369b6SAlanny Lopez# launch = job|pod 17cce369b6SAlanny Lopez# Can be left blank to launch via Docker if not using 18cce369b6SAlanny Lopez# Kubernetes to launch the container. 19cce369b6SAlanny Lopez# Job lets you keep a copy of job and container logs on the 20cce369b6SAlanny Lopez# api, can be useful if not using Jenkins as you can run the 21cce369b6SAlanny Lopez# job again via the api without needing this script. 22cce369b6SAlanny Lopez# Pod launches a container which runs to completion without 23cce369b6SAlanny Lopez# saving anything to the api when it completes. 24cce369b6SAlanny Lopez# imgname = Defaults to qemu-build with the arch as its tag, can be 25cce369b6SAlanny Lopez# changed or passed to give a specific name to created image. 26cce369b6SAlanny Lopez# http_proxy = The HTTP address for the proxy server you wish to connect to. 27cce369b6SAlanny Lopez# 28cce369b6SAlanny Lopez############################################################################### 290b851182SJoel Stanley 300b851182SJoel Stanley# Trace bash processing 310b851182SJoel Stanleyset -x 320b851182SJoel Stanley 330b851182SJoel Stanley# Default variables 340b851182SJoel StanleyWORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} 350b851182SJoel Stanleyhttp_proxy=${http_proxy:-} 3641e2ada2SAlanny Lopezlaunch=${launch:-} 37cce369b6SAlanny Lopezqemudir=${qemudir:-${WORKSPACE}/qemu} 38cce369b6SAlanny LopezARCH=$(uname -m) 39cce369b6SAlanny Lopezimgname=${imgname:-qemu-build:${ARCH}} 400b851182SJoel Stanley 410b851182SJoel Stanley# Timestamp for job 420b851182SJoel Stanleyecho "Build started, $(date)" 430b851182SJoel Stanley 4441e2ada2SAlanny Lopez# Setup Proxy 450b851182SJoel Stanleyif [[ -n "${http_proxy}" ]]; then 460b851182SJoel StanleyPROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 470b851182SJoel Stanleyfi 480b851182SJoel Stanley 4941e2ada2SAlanny Lopez# Determine the prefix of the Dockerfile's base image 5041e2ada2SAlanny Lopezcase ${ARCH} in 5141e2ada2SAlanny Lopez "ppc64le") 5241e2ada2SAlanny Lopez DOCKER_BASE="ppc64le/" 5341e2ada2SAlanny Lopez ;; 5441e2ada2SAlanny Lopez "x86_64") 5541e2ada2SAlanny Lopez DOCKER_BASE="" 5641e2ada2SAlanny Lopez ;; 5741e2ada2SAlanny Lopez *) 5841e2ada2SAlanny Lopez echo "Unsupported system architecture(${ARCH}) found for docker image" 590b851182SJoel Stanley exit 1 6041e2ada2SAlanny Lopezesac 610b851182SJoel Stanley 62cce369b6SAlanny Lopez# If there is no qemu directory, git clone in the openbmc mirror 63cce369b6SAlanny Lopezif [ ! -d ${qemudir} ]; then 64cce369b6SAlanny Lopez echo "Clone in openbmc master to ${qemudir}" 65cce369b6SAlanny Lopez git clone https://github.com/openbmc/qemu ${qemudir} 66cce369b6SAlanny Lopezfi 67cce369b6SAlanny Lopez 680b851182SJoel Stanley# Create the docker run script 690b851182SJoel Stanleyexport PROXY_HOST=${http_proxy/#http*:\/\/} 700b851182SJoel Stanleyexport PROXY_HOST=${PROXY_HOST/%:[0-9]*} 710b851182SJoel Stanleyexport PROXY_PORT=${http_proxy/#http*:\/\/*:} 720b851182SJoel Stanley 730b851182SJoel Stanleymkdir -p ${WORKSPACE} 740b851182SJoel Stanley 750b851182SJoel Stanleycat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 760b851182SJoel Stanley#!/bin/bash 770b851182SJoel Stanley 780b851182SJoel Stanleyset -x 790b851182SJoel Stanley 80cce369b6SAlanny Lopez# Go into the source directory (the script will put us in a build subdir) 81cce369b6SAlanny Lopezcd ${qemudir} 820b851182SJoel Stanley 830b851182SJoel Stanleygcc --version 8441e2ada2SAlanny Lopezgit submodule update --init dtc 850b851182SJoel Stanley# disable anything that requires us to pull in X 86e30237caSAlanny Lopez./configure \ 87e30237caSAlanny Lopez --target-list=arm-softmmu \ 88e30237caSAlanny Lopez --disable-spice \ 89e30237caSAlanny Lopez --disable-docs \ 90e30237caSAlanny Lopez --disable-gtk \ 91e30237caSAlanny Lopez --disable-smartcard \ 92e30237caSAlanny Lopez --disable-usb-redir \ 93e30237caSAlanny Lopez --disable-libusb \ 94e30237caSAlanny Lopez --disable-sdl \ 95e30237caSAlanny Lopez --disable-gnutls \ 96e30237caSAlanny Lopez --disable-vte \ 97e30237caSAlanny Lopez --disable-vnc \ 98e30237caSAlanny Lopez --disable-vnc-png 990b851182SJoel Stanleymake -j4 1000b851182SJoel Stanley 1010b851182SJoel StanleyEOF_SCRIPT 1020b851182SJoel Stanley 1030b851182SJoel Stanleychmod a+x ${WORKSPACE}/build.sh 1040b851182SJoel Stanley 10541e2ada2SAlanny Lopez# Configure docker build 10641e2ada2SAlanny LopezDockerfile=$(cat << EOF 10741e2ada2SAlanny LopezFROM ${DOCKER_BASE}ubuntu:16.04 10841e2ada2SAlanny Lopez 10941e2ada2SAlanny Lopez${PROXY} 11041e2ada2SAlanny Lopez 11141e2ada2SAlanny LopezENV DEBIAN_FRONTEND noninteractive 11241e2ada2SAlanny LopezRUN apt-get update && apt-get install -yy --no-install-recommends \ 11341e2ada2SAlanny Lopez bison \ 11441e2ada2SAlanny Lopez flex \ 11541e2ada2SAlanny Lopez gcc \ 11641e2ada2SAlanny Lopez git \ 11741e2ada2SAlanny Lopez libc6-dev \ 11841e2ada2SAlanny Lopez libfdt-dev \ 11941e2ada2SAlanny Lopez libglib2.0-dev \ 12041e2ada2SAlanny Lopez libpixman-1-dev \ 12141e2ada2SAlanny Lopez make \ 12241e2ada2SAlanny Lopez python-yaml \ 12341e2ada2SAlanny Lopez python3-yaml 12441e2ada2SAlanny Lopez 12541e2ada2SAlanny LopezRUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} 12641e2ada2SAlanny LopezRUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} 12741e2ada2SAlanny LopezUSER ${USER} 12841e2ada2SAlanny LopezENV HOME ${HOME} 12941e2ada2SAlanny LopezEOF 13041e2ada2SAlanny Lopez) 13141e2ada2SAlanny Lopez 13241e2ada2SAlanny Lopez# If Launch is left empty will create a docker container 13341e2ada2SAlanny Lopezif [[ "${launch}" == "" ]]; then 13441e2ada2SAlanny Lopez 13541e2ada2SAlanny Lopez docker build -t ${imgname} - <<< "${Dockerfile}" 13641e2ada2SAlanny Lopez if [[ "$?" -ne 0 ]]; then 13741e2ada2SAlanny Lopez echo "Failed to build docker container." 13841e2ada2SAlanny Lopez exit 1 13941e2ada2SAlanny Lopez fi 140cce369b6SAlanny Lopez mountqemu="-v ""${qemudir}"":""${qemudir}"" " 141cce369b6SAlanny Lopez if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]]; then 142cce369b6SAlanny Lopez mountqemu="" 143cce369b6SAlanny Lopez fi 144e30237caSAlanny Lopez docker run \ 145e30237caSAlanny Lopez --rm=true \ 146e30237caSAlanny Lopez -e WORKSPACE=${WORKSPACE} \ 147e30237caSAlanny Lopez -w "${HOME}" \ 148e30237caSAlanny Lopez -v "${HOME}":"${HOME}" \ 149cce369b6SAlanny Lopez ${mountqemu} \ 15041e2ada2SAlanny Lopez -t ${imgname} \ 151e30237caSAlanny Lopez ${WORKSPACE}/build.sh 152*634ce36dSAlanny Lopezelif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then 153*634ce36dSAlanny Lopez . ./kubernetes/kubernetes-launch.sh QEMU-build true true 15441e2ada2SAlanny Lopezelse 15541e2ada2SAlanny Lopez echo "Launch Parameter is invalid" 15641e2ada2SAlanny Lopezfi 15741e2ada2SAlanny Lopez 15841e2ada2SAlanny Lopez 159