blob: 49c799e7c9416a3c5dd4ea9d99ed47dc9b6bf068 [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###############################################################################
Joel Stanley0b851182016-06-21 23:51:19 +093040# Trace bash processing
41set -x
42
Alanny Lopez46967702018-02-25 00:29:14 -060043# Script Variables:
44build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
Joel Stanley0b851182016-06-21 23:51:19 +093045http_proxy=${http_proxy:-}
Alanny Lopez1246b032018-02-24 23:34:55 -060046qemu_dir=${qemu_dir:-${WORKSPACE}/qemu}
Alanny Lopez46967702018-02-25 00:29:14 -060047WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
48
49# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060050build_dir=${build_dir:-/tmp/qemu}
Alanny Lopez1246b032018-02-24 23:34:55 -060051img_name=${img_name:-qemu-build:${ARCH}}
Joel Stanley0b851182016-06-21 23:51:19 +093052
Alanny Lopez46967702018-02-25 00:29:14 -060053# Deployment Variables
54launch=${launch:-}
55
56# Determine the architecture
57ARCH=$(uname -m)
58
Joel Stanley0b851182016-06-21 23:51:19 +093059# Timestamp for job
60echo "Build started, $(date)"
61
Alanny Lopez41e2ada2017-06-15 13:54:43 -050062# Setup Proxy
Joel Stanley0b851182016-06-21 23:51:19 +093063if [[ -n "${http_proxy}" ]]; then
64PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
65fi
66
Alanny Lopez41e2ada2017-06-15 13:54:43 -050067# Determine the prefix of the Dockerfile's base image
68case ${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
78esac
Joel Stanley0b851182016-06-21 23:51:19 +093079
Alanny Lopezcce369b2017-06-20 09:52:50 -050080# If there is no qemu directory, git clone in the openbmc mirror
Alanny Lopez1246b032018-02-24 23:34:55 -060081if [ ! -d ${qemu_dir} ]; then
82 echo "Clone in openbmc master to ${qemu_dir}"
83 git clone https://github.com/openbmc/qemu ${qemu_dir}
Alanny Lopezcce369b2017-06-20 09:52:50 -050084fi
85
Joel Stanley0b851182016-06-21 23:51:19 +093086# Create the docker run script
87export PROXY_HOST=${http_proxy/#http*:\/\/}
88export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
89export PROXY_PORT=${http_proxy/#http*:\/\/*:}
90
91mkdir -p ${WORKSPACE}
92
93cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
94#!/bin/bash
95
96set -x
97
Alanny Lopeza61e99a2017-06-27 14:20:48 -050098# create a copy of the qemudir in /qemu to use as the build directory
Alanny Lopez1246b032018-02-24 23:34:55 -060099cp -a ${qemu_dir}/. ${build_dir}
Alanny Lopeza61e99a2017-06-27 14:20:48 -0500100
101# Go into the build directory
Alanny Lopez1246b032018-02-24 23:34:55 -0600102cd ${build_dir}
Joel Stanley0b851182016-06-21 23:51:19 +0930103
104gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500105git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +0930106# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -0500107./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 \
119 --disable-vnc-png
Joel Stanley0b851182016-06-21 23:51:19 +0930120make -j4
121
Alanny Lopez1246b032018-02-24 23:34:55 -0600122cp -a ${build_dir}/arm-softmmu/. ${WORKSPACE}/arm-softmmu/
Joel Stanley0b851182016-06-21 23:51:19 +0930123EOF_SCRIPT
124
125chmod a+x ${WORKSPACE}/build.sh
126
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500127# Configure docker build
128Dockerfile=$(cat << EOF
129FROM ${DOCKER_BASE}ubuntu:16.04
130
131${PROXY}
132
133ENV DEBIAN_FRONTEND noninteractive
134RUN apt-get update && apt-get install -yy --no-install-recommends \
135 bison \
136 flex \
137 gcc \
138 git \
139 libc6-dev \
140 libfdt-dev \
141 libglib2.0-dev \
142 libpixman-1-dev \
143 make \
144 python-yaml \
Saqib Khan5158a322017-10-23 11:31:24 -0500145 python3-yaml \
146 iputils-ping
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500147
148RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
149RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
150USER ${USER}
Alanny Lopez1246b032018-02-24 23:34:55 -0600151RUN mkdir ${build_dir}
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500152ENV HOME ${HOME}
153EOF
154)
155
Alanny Lopez1246b032018-02-24 23:34:55 -0600156docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500157# If Launch is left empty will create a docker container
158if [[ "${launch}" == "" ]]; then
159
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500160 if [[ "$?" -ne 0 ]]; then
161 echo "Failed to build docker container."
162 exit 1
163 fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600164 mount_qemu="-v ""${qemu_dir}"":""${qemu_dir}"" "
165 if [[ "${qemu_dir}" = "${HOME}/"* || "${qemu_dir}" = "${HOME}" ]]; then
166 mount_qemu=""
Alanny Lopezcce369b2017-06-20 09:52:50 -0500167 fi
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500168 docker run \
169 --rm=true \
170 -e WORKSPACE=${WORKSPACE} \
171 -w "${HOME}" \
172 -v "${HOME}":"${HOME}" \
Alanny Lopez1246b032018-02-24 23:34:55 -0600173 ${mount_qemu} \
174 -t ${img_name} \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500175 ${WORKSPACE}/build.sh
Alanny Lopez634ce362017-06-23 12:57:05 -0500176elif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then
Alanny Lopeze08e8702018-02-24 18:07:13 -0600177 . ${build_scripts_dir}/kubernetes/kubernetes-launch.sh QEMU-build true true
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500178else
179 echo "Launch Parameter is invalid"
180fi