blob: 33a2a008ef478e4a10b1fb8e3588e9486fbf9393 [file] [log] [blame]
Joel Stanley0b851182016-06-21 23:51:19 +09301#!/bin/bash
Alanny Lopezcce369b2017-06-20 09:52:50 -05002###############################################################################
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.
Alanny Lopeza61e99a2017-06-27 14:20:48 -050012# qemudir = Path of the directory that holds the QEMU repo, if none
13# exists will clone in the OpenBMC/QEMU repo to WORKSPACE.
14# builddir = Path of the directory that is created within the docker
15# container where the build is actually done. Done this way to
16# allow external volumes to be used for the qemudir.
Alanny Lopezcce369b2017-06-20 09:52:50 -050017#
18# Optional Variables:
19# launch = job|pod
20# Can be left blank to launch via Docker if not using
21# Kubernetes to launch the container.
22# Job lets you keep a copy of job and container logs on the
23# api, can be useful if not using Jenkins as you can run the
24# job again via the api without needing this script.
25# Pod launches a container which runs to completion without
26# saving anything to the api when it completes.
27# imgname = Defaults to qemu-build with the arch as its tag, can be
28# changed or passed to give a specific name to created image.
29# http_proxy = The HTTP address for the proxy server you wish to connect to.
30#
31###############################################################################
Joel Stanley0b851182016-06-21 23:51:19 +093032
33# Trace bash processing
34set -x
35
36# Default variables
37WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
38http_proxy=${http_proxy:-}
Alanny Lopez41e2ada2017-06-15 13:54:43 -050039launch=${launch:-}
Alanny Lopezcce369b2017-06-20 09:52:50 -050040qemudir=${qemudir:-${WORKSPACE}/qemu}
Alanny Lopeza61e99a2017-06-27 14:20:48 -050041builddir=${builddir:-/tmp/qemu}
Alanny Lopezcce369b2017-06-20 09:52:50 -050042ARCH=$(uname -m)
43imgname=${imgname:-qemu-build:${ARCH}}
Joel Stanley0b851182016-06-21 23:51:19 +093044
45# Timestamp for job
46echo "Build started, $(date)"
47
Alanny Lopez41e2ada2017-06-15 13:54:43 -050048# Setup Proxy
Joel Stanley0b851182016-06-21 23:51:19 +093049if [[ -n "${http_proxy}" ]]; then
50PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
51fi
52
Alanny Lopez41e2ada2017-06-15 13:54:43 -050053# Determine the prefix of the Dockerfile's base image
54case ${ARCH} in
55 "ppc64le")
56 DOCKER_BASE="ppc64le/"
57 ;;
58 "x86_64")
59 DOCKER_BASE=""
60 ;;
61 *)
62 echo "Unsupported system architecture(${ARCH}) found for docker image"
63 exit 1
64esac
Joel Stanley0b851182016-06-21 23:51:19 +093065
Alanny Lopezcce369b2017-06-20 09:52:50 -050066# If there is no qemu directory, git clone in the openbmc mirror
67if [ ! -d ${qemudir} ]; then
68 echo "Clone in openbmc master to ${qemudir}"
69 git clone https://github.com/openbmc/qemu ${qemudir}
70fi
71
Joel Stanley0b851182016-06-21 23:51:19 +093072# Create the docker run script
73export PROXY_HOST=${http_proxy/#http*:\/\/}
74export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
75export PROXY_PORT=${http_proxy/#http*:\/\/*:}
76
77mkdir -p ${WORKSPACE}
78
79cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
80#!/bin/bash
81
82set -x
83
Alanny Lopeza61e99a2017-06-27 14:20:48 -050084# create a copy of the qemudir in /qemu to use as the build directory
85cp -a ${qemudir}/. ${builddir}
86
87# Go into the build directory
88cd ${builddir}
Joel Stanley0b851182016-06-21 23:51:19 +093089
90gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -050091git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +093092# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -050093./configure \
94 --target-list=arm-softmmu \
95 --disable-spice \
96 --disable-docs \
97 --disable-gtk \
98 --disable-smartcard \
99 --disable-usb-redir \
100 --disable-libusb \
101 --disable-sdl \
102 --disable-gnutls \
103 --disable-vte \
104 --disable-vnc \
105 --disable-vnc-png
Joel Stanley0b851182016-06-21 23:51:19 +0930106make -j4
107
Alanny Lopeza61e99a2017-06-27 14:20:48 -0500108cp -a ${builddir}/arm-softmmu/. ${WORKSPACE}/arm-softmmu/
Joel Stanley0b851182016-06-21 23:51:19 +0930109EOF_SCRIPT
110
111chmod a+x ${WORKSPACE}/build.sh
112
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500113# Configure docker build
114Dockerfile=$(cat << EOF
115FROM ${DOCKER_BASE}ubuntu:16.04
116
117${PROXY}
118
119ENV DEBIAN_FRONTEND noninteractive
120RUN apt-get update && apt-get install -yy --no-install-recommends \
121 bison \
122 flex \
123 gcc \
124 git \
125 libc6-dev \
126 libfdt-dev \
127 libglib2.0-dev \
128 libpixman-1-dev \
129 make \
130 python-yaml \
Saqib Khan5158a322017-10-23 11:31:24 -0500131 python3-yaml \
132 iputils-ping
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500133
134RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
135RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
136USER ${USER}
Alanny Lopeza61e99a2017-06-27 14:20:48 -0500137RUN mkdir ${builddir}
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500138ENV HOME ${HOME}
139EOF
140)
141
Alanny Lopez51186882017-08-01 16:14:41 -0500142docker build -t ${imgname} - <<< "${Dockerfile}"
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500143# If Launch is left empty will create a docker container
144if [[ "${launch}" == "" ]]; then
145
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500146 if [[ "$?" -ne 0 ]]; then
147 echo "Failed to build docker container."
148 exit 1
149 fi
Alanny Lopezcce369b2017-06-20 09:52:50 -0500150 mountqemu="-v ""${qemudir}"":""${qemudir}"" "
Alanny Lopez634ce362017-06-23 12:57:05 -0500151 if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]]; then
Alanny Lopezcce369b2017-06-20 09:52:50 -0500152 mountqemu=""
153 fi
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500154 docker run \
155 --rm=true \
156 -e WORKSPACE=${WORKSPACE} \
157 -w "${HOME}" \
158 -v "${HOME}":"${HOME}" \
Alanny Lopezcce369b2017-06-20 09:52:50 -0500159 ${mountqemu} \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500160 -t ${imgname} \
161 ${WORKSPACE}/build.sh
Alanny Lopez634ce362017-06-23 12:57:05 -0500162elif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then
163 . ./kubernetes/kubernetes-launch.sh QEMU-build true true
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500164else
165 echo "Launch Parameter is invalid"
166fi
167
168