blob: 9377617cd01d66dc047c556b7f8d597dbe15ab1b [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#
Alanny Lopeze08e8702018-02-24 18:07:13 -06009# 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 Lopez1246b032018-02-24 23:34:55 -060014# qemu_dir Path of the directory that holds the QEMU repo, if none
Alanny Lopeze08e8702018-02-24 18:07:13 -060015# 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 Lopezcce369b2017-06-20 09:52:50 -050020#
Alanny Lopeze08e8702018-02-24 18:07:13 -060021# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060022# build_dir Path of the directory that is created within the docker
Alanny Lopeze08e8702018-02-24 18:07:13 -060023# container where the build is actually done. Done this way
Alanny Lopez1246b032018-02-24 23:34:55 -060024# to allow NFS volumes to be used as the qemu_dir.
Alanny Lopeze08e8702018-02-24 18:07:13 -060025# Default: "/tmp/qemu"
Alanny Lopez1246b032018-02-24 23:34:55 -060026# img_name Defaults to qemu-build with the arch as its tag, can be
Alanny Lopeze08e8702018-02-24 18:07:13 -060027# 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 Lopezcce369b2017-06-20 09:52:50 -050038#
39###############################################################################
Alanny Lopeze08e8702018-02-24 18:07:13 -060040build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
Joel Stanley0b851182016-06-21 23:51:19 +093041
42# Trace bash processing
43set -x
44
45# Default variables
46WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
47http_proxy=${http_proxy:-}
Alanny Lopez41e2ada2017-06-15 13:54:43 -050048launch=${launch:-}
Alanny Lopez1246b032018-02-24 23:34:55 -060049qemu_dir=${qemu_dir:-${WORKSPACE}/qemu}
50build_dir=${build_dir:-/tmp/qemu}
Alanny Lopezcce369b2017-06-20 09:52:50 -050051ARCH=$(uname -m)
Alanny Lopez1246b032018-02-24 23:34:55 -060052img_name=${img_name:-qemu-build:${ARCH}}
Joel Stanley0b851182016-06-21 23:51:19 +093053
54# Timestamp for job
55echo "Build started, $(date)"
56
Alanny Lopez41e2ada2017-06-15 13:54:43 -050057# Setup Proxy
Joel Stanley0b851182016-06-21 23:51:19 +093058if [[ -n "${http_proxy}" ]]; then
59PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
60fi
61
Alanny Lopez41e2ada2017-06-15 13:54:43 -050062# Determine the prefix of the Dockerfile's base image
63case ${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
73esac
Joel Stanley0b851182016-06-21 23:51:19 +093074
Alanny Lopezcce369b2017-06-20 09:52:50 -050075# If there is no qemu directory, git clone in the openbmc mirror
Alanny Lopez1246b032018-02-24 23:34:55 -060076if [ ! -d ${qemu_dir} ]; then
77 echo "Clone in openbmc master to ${qemu_dir}"
78 git clone https://github.com/openbmc/qemu ${qemu_dir}
Alanny Lopezcce369b2017-06-20 09:52:50 -050079fi
80
Joel Stanley0b851182016-06-21 23:51:19 +093081# Create the docker run script
82export PROXY_HOST=${http_proxy/#http*:\/\/}
83export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
84export PROXY_PORT=${http_proxy/#http*:\/\/*:}
85
86mkdir -p ${WORKSPACE}
87
88cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
89#!/bin/bash
90
91set -x
92
Alanny Lopeza61e99a2017-06-27 14:20:48 -050093# create a copy of the qemudir in /qemu to use as the build directory
Alanny Lopez1246b032018-02-24 23:34:55 -060094cp -a ${qemu_dir}/. ${build_dir}
Alanny Lopeza61e99a2017-06-27 14:20:48 -050095
96# Go into the build directory
Alanny Lopez1246b032018-02-24 23:34:55 -060097cd ${build_dir}
Joel Stanley0b851182016-06-21 23:51:19 +093098
99gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500100git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +0930101# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -0500102./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 Stanley0b851182016-06-21 23:51:19 +0930115make -j4
116
Alanny Lopez1246b032018-02-24 23:34:55 -0600117cp -a ${build_dir}/arm-softmmu/. ${WORKSPACE}/arm-softmmu/
Joel Stanley0b851182016-06-21 23:51:19 +0930118EOF_SCRIPT
119
120chmod a+x ${WORKSPACE}/build.sh
121
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500122# Configure docker build
123Dockerfile=$(cat << EOF
124FROM ${DOCKER_BASE}ubuntu:16.04
125
126${PROXY}
127
128ENV DEBIAN_FRONTEND noninteractive
129RUN 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 Khan5158a322017-10-23 11:31:24 -0500140 python3-yaml \
141 iputils-ping
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500142
143RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
144RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
145USER ${USER}
Alanny Lopez1246b032018-02-24 23:34:55 -0600146RUN mkdir ${build_dir}
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500147ENV HOME ${HOME}
148EOF
149)
150
Alanny Lopez1246b032018-02-24 23:34:55 -0600151docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500152# If Launch is left empty will create a docker container
153if [[ "${launch}" == "" ]]; then
154
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500155 if [[ "$?" -ne 0 ]]; then
156 echo "Failed to build docker container."
157 exit 1
158 fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600159 mount_qemu="-v ""${qemu_dir}"":""${qemu_dir}"" "
160 if [[ "${qemu_dir}" = "${HOME}/"* || "${qemu_dir}" = "${HOME}" ]]; then
161 mount_qemu=""
Alanny Lopezcce369b2017-06-20 09:52:50 -0500162 fi
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500163 docker run \
164 --rm=true \
165 -e WORKSPACE=${WORKSPACE} \
166 -w "${HOME}" \
167 -v "${HOME}":"${HOME}" \
Alanny Lopez1246b032018-02-24 23:34:55 -0600168 ${mount_qemu} \
169 -t ${img_name} \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500170 ${WORKSPACE}/build.sh
Alanny Lopez634ce362017-06-23 12:57:05 -0500171elif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then
Alanny Lopeze08e8702018-02-24 18:07:13 -0600172 . ${build_scripts_dir}/kubernetes/kubernetes-launch.sh QEMU-build true true
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500173else
174 echo "Launch Parameter is invalid"
175fi