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. 12a61e99abSAlanny Lopez# qemudir = Path of the directory that holds the QEMU repo, if none 13a61e99abSAlanny Lopez# exists will clone in the OpenBMC/QEMU repo to WORKSPACE. 14a61e99abSAlanny Lopez# builddir = Path of the directory that is created within the docker 15a61e99abSAlanny Lopez# container where the build is actually done. Done this way to 16a61e99abSAlanny Lopez# allow external volumes to be used for the qemudir. 17cce369b6SAlanny Lopez# 18cce369b6SAlanny Lopez# Optional Variables: 19cce369b6SAlanny Lopez# launch = job|pod 20cce369b6SAlanny Lopez# Can be left blank to launch via Docker if not using 21cce369b6SAlanny Lopez# Kubernetes to launch the container. 22cce369b6SAlanny Lopez# Job lets you keep a copy of job and container logs on the 23cce369b6SAlanny Lopez# api, can be useful if not using Jenkins as you can run the 24cce369b6SAlanny Lopez# job again via the api without needing this script. 25cce369b6SAlanny Lopez# Pod launches a container which runs to completion without 26cce369b6SAlanny Lopez# saving anything to the api when it completes. 27cce369b6SAlanny Lopez# imgname = Defaults to qemu-build with the arch as its tag, can be 28cce369b6SAlanny Lopez# changed or passed to give a specific name to created image. 29cce369b6SAlanny Lopez# http_proxy = The HTTP address for the proxy server you wish to connect to. 30cce369b6SAlanny Lopez# 31cce369b6SAlanny Lopez############################################################################### 320b851182SJoel Stanley 330b851182SJoel Stanley# Trace bash processing 340b851182SJoel Stanleyset -x 350b851182SJoel Stanley 360b851182SJoel Stanley# Default variables 370b851182SJoel StanleyWORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} 380b851182SJoel Stanleyhttp_proxy=${http_proxy:-} 3941e2ada2SAlanny Lopezlaunch=${launch:-} 40cce369b6SAlanny Lopezqemudir=${qemudir:-${WORKSPACE}/qemu} 41a61e99abSAlanny Lopezbuilddir=${builddir:-/tmp/qemu} 42cce369b6SAlanny LopezARCH=$(uname -m) 43cce369b6SAlanny Lopezimgname=${imgname:-qemu-build:${ARCH}} 440b851182SJoel Stanley 450b851182SJoel Stanley# Timestamp for job 460b851182SJoel Stanleyecho "Build started, $(date)" 470b851182SJoel Stanley 4841e2ada2SAlanny Lopez# Setup Proxy 490b851182SJoel Stanleyif [[ -n "${http_proxy}" ]]; then 500b851182SJoel StanleyPROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 510b851182SJoel Stanleyfi 520b851182SJoel Stanley 5341e2ada2SAlanny Lopez# Determine the prefix of the Dockerfile's base image 5441e2ada2SAlanny Lopezcase ${ARCH} in 5541e2ada2SAlanny Lopez "ppc64le") 5641e2ada2SAlanny Lopez DOCKER_BASE="ppc64le/" 5741e2ada2SAlanny Lopez ;; 5841e2ada2SAlanny Lopez "x86_64") 5941e2ada2SAlanny Lopez DOCKER_BASE="" 6041e2ada2SAlanny Lopez ;; 6141e2ada2SAlanny Lopez *) 6241e2ada2SAlanny Lopez echo "Unsupported system architecture(${ARCH}) found for docker image" 630b851182SJoel Stanley exit 1 6441e2ada2SAlanny Lopezesac 650b851182SJoel Stanley 66cce369b6SAlanny Lopez# If there is no qemu directory, git clone in the openbmc mirror 67cce369b6SAlanny Lopezif [ ! -d ${qemudir} ]; then 68cce369b6SAlanny Lopez echo "Clone in openbmc master to ${qemudir}" 69cce369b6SAlanny Lopez git clone https://github.com/openbmc/qemu ${qemudir} 70cce369b6SAlanny Lopezfi 71cce369b6SAlanny Lopez 720b851182SJoel Stanley# Create the docker run script 730b851182SJoel Stanleyexport PROXY_HOST=${http_proxy/#http*:\/\/} 740b851182SJoel Stanleyexport PROXY_HOST=${PROXY_HOST/%:[0-9]*} 750b851182SJoel Stanleyexport PROXY_PORT=${http_proxy/#http*:\/\/*:} 760b851182SJoel Stanley 770b851182SJoel Stanleymkdir -p ${WORKSPACE} 780b851182SJoel Stanley 790b851182SJoel Stanleycat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 800b851182SJoel Stanley#!/bin/bash 810b851182SJoel Stanley 820b851182SJoel Stanleyset -x 830b851182SJoel Stanley 84a61e99abSAlanny Lopez# create a copy of the qemudir in /qemu to use as the build directory 85a61e99abSAlanny Lopezcp -a ${qemudir}/. ${builddir} 86a61e99abSAlanny Lopez 87a61e99abSAlanny Lopez# Go into the build directory 88a61e99abSAlanny Lopezcd ${builddir} 890b851182SJoel Stanley 900b851182SJoel Stanleygcc --version 9141e2ada2SAlanny Lopezgit submodule update --init dtc 920b851182SJoel Stanley# disable anything that requires us to pull in X 93e30237caSAlanny Lopez./configure \ 94e30237caSAlanny Lopez --target-list=arm-softmmu \ 95e30237caSAlanny Lopez --disable-spice \ 96e30237caSAlanny Lopez --disable-docs \ 97e30237caSAlanny Lopez --disable-gtk \ 98e30237caSAlanny Lopez --disable-smartcard \ 99e30237caSAlanny Lopez --disable-usb-redir \ 100e30237caSAlanny Lopez --disable-libusb \ 101e30237caSAlanny Lopez --disable-sdl \ 102e30237caSAlanny Lopez --disable-gnutls \ 103e30237caSAlanny Lopez --disable-vte \ 104e30237caSAlanny Lopez --disable-vnc \ 105e30237caSAlanny Lopez --disable-vnc-png 1060b851182SJoel Stanleymake -j4 1070b851182SJoel Stanley 108a61e99abSAlanny Lopezcp -a ${builddir}/arm-softmmu/. ${WORKSPACE}/arm-softmmu/ 1090b851182SJoel StanleyEOF_SCRIPT 1100b851182SJoel Stanley 1110b851182SJoel Stanleychmod a+x ${WORKSPACE}/build.sh 1120b851182SJoel Stanley 11341e2ada2SAlanny Lopez# Configure docker build 11441e2ada2SAlanny LopezDockerfile=$(cat << EOF 11541e2ada2SAlanny LopezFROM ${DOCKER_BASE}ubuntu:16.04 11641e2ada2SAlanny Lopez 11741e2ada2SAlanny Lopez${PROXY} 11841e2ada2SAlanny Lopez 11941e2ada2SAlanny LopezENV DEBIAN_FRONTEND noninteractive 12041e2ada2SAlanny LopezRUN apt-get update && apt-get install -yy --no-install-recommends \ 12141e2ada2SAlanny Lopez bison \ 12241e2ada2SAlanny Lopez flex \ 12341e2ada2SAlanny Lopez gcc \ 12441e2ada2SAlanny Lopez git \ 12541e2ada2SAlanny Lopez libc6-dev \ 12641e2ada2SAlanny Lopez libfdt-dev \ 12741e2ada2SAlanny Lopez libglib2.0-dev \ 12841e2ada2SAlanny Lopez libpixman-1-dev \ 12941e2ada2SAlanny Lopez make \ 13041e2ada2SAlanny Lopez python-yaml \ 13141e2ada2SAlanny Lopez python3-yaml 13241e2ada2SAlanny Lopez 13341e2ada2SAlanny LopezRUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} 13441e2ada2SAlanny LopezRUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} 13541e2ada2SAlanny LopezUSER ${USER} 136a61e99abSAlanny LopezRUN mkdir ${builddir} 13741e2ada2SAlanny LopezENV HOME ${HOME} 13841e2ada2SAlanny LopezEOF 13941e2ada2SAlanny Lopez) 14041e2ada2SAlanny Lopez 141*51186883SAlanny Lopezdocker build -t ${imgname} - <<< "${Dockerfile}" 14241e2ada2SAlanny Lopez# If Launch is left empty will create a docker container 14341e2ada2SAlanny Lopezif [[ "${launch}" == "" ]]; then 14441e2ada2SAlanny Lopez 14541e2ada2SAlanny Lopez if [[ "$?" -ne 0 ]]; then 14641e2ada2SAlanny Lopez echo "Failed to build docker container." 14741e2ada2SAlanny Lopez exit 1 14841e2ada2SAlanny Lopez fi 149cce369b6SAlanny Lopez mountqemu="-v ""${qemudir}"":""${qemudir}"" " 150cce369b6SAlanny Lopez if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]]; then 151cce369b6SAlanny Lopez mountqemu="" 152cce369b6SAlanny Lopez fi 153e30237caSAlanny Lopez docker run \ 154e30237caSAlanny Lopez --rm=true \ 155e30237caSAlanny Lopez -e WORKSPACE=${WORKSPACE} \ 156e30237caSAlanny Lopez -w "${HOME}" \ 157e30237caSAlanny Lopez -v "${HOME}":"${HOME}" \ 158cce369b6SAlanny Lopez ${mountqemu} \ 15941e2ada2SAlanny Lopez -t ${imgname} \ 160e30237caSAlanny Lopez ${WORKSPACE}/build.sh 161634ce36dSAlanny Lopezelif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then 162634ce36dSAlanny Lopez . ./kubernetes/kubernetes-launch.sh QEMU-build true true 16341e2ada2SAlanny Lopezelse 16441e2ada2SAlanny Lopez echo "Launch Parameter is invalid" 16541e2ada2SAlanny Lopezfi 16641e2ada2SAlanny Lopez 16741e2ada2SAlanny Lopez 168