2021-08-23 21:29:57 +00:00
FROM debian:bullseye-slim
2014-09-20 07:00:11 +00:00
2021-03-19 15:38:04 +00:00
RUN set -eux; \
2021-03-21 05:00:52 +00:00
# add backports for (potentially) newer QEMU firmware packages
2021-03-19 15:38:04 +00:00
suite = " $( awk '$1 == "deb" { print $3; exit }' /etc/apt/sources.list) " ; \
echo " deb http://deb.debian.org/debian $suite -backports main " > /etc/apt/sources.list.d/backports.list; \
2021-03-21 05:00:52 +00:00
# and add APT pinning to ensure we don't accidentally get QEMU from Debian
{ \
2021-08-23 21:29:57 +00:00
echo 'Package: src:edk2' ; \
2021-03-21 05:00:52 +00:00
echo 'Pin: release a=*-backports' ; \
echo 'Pin-Priority: 600' ; \
echo; \
2021-08-23 21:29:57 +00:00
echo 'Package: src:qemu' ; \
2021-03-21 05:00:52 +00:00
echo 'Pin: version *' ; \
echo 'Pin-Priority: -10' ; \
} > /etc/apt/preferences.d/qemu.pref; \
2021-03-19 15:38:04 +00:00
apt-get update; \
2021-03-21 05:00:52 +00:00
{ { def firmware_packages: {
amd64: "ovmf" ,
arm64: "qemu-efi-aarch64" ,
"armel | armhf" : "qemu-efi-arm" ,
2021-08-23 21:29:57 +00:00
i386: "ovmf-ia32" ,
# TODO add u-boot-qemu ? https://packages.debian.org/bullseye/u-boot-qemu (not sure which arches to add this to since it contains all of them... maybe every relevant one?)
2021-03-21 05:00:52 +00:00
} -} }
{ { if env.variant = = "native" then ( -} }
arch = " $( dpkg --print-architecture) " ; \
case " $arch " in \
{ {
[
firmware_packages
| to_entries[ ]
| (
-} }
{ { .key } } ) apt-get install -y --no-install-recommends { { .value } } ; ; \
{ {
)
] | add
-} }
*) echo >& 2 " warning: architecture ' $arch ' unknown 😅 (is there a 'QEMU firmware' package that should be installed here? likely candidates: https://packages.debian.org/source/ $suite /edk2) " ; ; \
esac ; \
{ { ) else ( -} }
2021-03-19 15:38:04 +00:00
apt-get install -y --no-install-recommends \
2021-03-21 05:00:52 +00:00
{ {
[
[ firmware_packages[ ] ]
| sort[ ]
| (
-} }
{ { . } } \
{ {
)
] | add
-} }
2021-03-19 15:38:04 +00:00
; \
2021-03-21 05:00:52 +00:00
{ { ) end -} }
2021-03-19 15:38:04 +00:00
rm -rf /var/lib/apt/lists/*
2014-09-20 07:00:11 +00:00
2017-12-18 21:21:01 +00:00
COPY *.patch /qemu-patches/
2019-01-17 22:28:12 +00:00
# https://wiki.qemu.org/SecurityProcess
ENV QEMU_KEYS \
# Michael Roth
CEACC9E15534EBABB82D3FA03353C9CEF108B584
# https://wiki.qemu.org/Planning/ReleaseProcess#Sign_the_resulting_tarball_with_GPG: (they get signed by whoever is making the release)
2017-12-18 21:21:01 +00:00
# https://www.qemu.org/download/#source
2019-01-17 22:28:12 +00:00
# https://download.qemu.org/?C=M;O=D
2020-08-27 23:31:53 +00:00
ENV QEMU_VERSION { { .version } }
ENV QEMU_URL { { .url } }
2017-12-18 21:21:01 +00:00
RUN set -eux; \
\
savedAptMark = " $( apt-mark showmanual) " ; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
2019-01-17 22:28:12 +00:00
gnupg dirmngr \
2017-12-18 21:21:01 +00:00
wget \
xz-utils \
\
patch \
\
2019-07-29 20:20:31 +00:00
bzip2 \
2017-12-18 21:21:01 +00:00
gcc \
2017-12-21 18:07:44 +00:00
gnutls-dev \
libaio-dev \
libbz2-dev \
2017-12-18 21:21:01 +00:00
libc-dev \
2017-12-21 18:07:44 +00:00
libcap-dev \
libcap-ng-dev \
libcurl4-gnutls-dev \
2017-12-18 21:21:01 +00:00
libglib2.0-dev \
2017-12-21 18:07:44 +00:00
libiscsi-dev \
libjpeg-dev \
libncursesw5-dev \
libnfs-dev \
libnuma-dev \
2017-12-18 21:21:01 +00:00
libpixman-1-dev \
2017-12-21 18:07:44 +00:00
libpng-dev \
2020-08-27 20:04:22 +00:00
librbd-dev \
2017-12-21 18:07:44 +00:00
libseccomp-dev \
2019-07-29 20:15:25 +00:00
libssh-dev \
2017-12-21 18:07:44 +00:00
libusb-1.0-0-dev \
libusbredirparser-dev \
libxen-dev \
2017-12-18 21:21:01 +00:00
make \
pkg-config \
2020-11-30 19:03:55 +00:00
python3 \
2017-12-21 18:07:44 +00:00
xfslibs-dev \
2017-12-18 21:21:01 +00:00
zlib1g-dev \
2021-08-23 19:34:17 +00:00
{ { if [ "5.0" , "5.1" ] | index( env.version) then "" else ( -} }
2020-11-30 19:03:55 +00:00
# https://wiki.qemu.org/ChangeLog/5.2#Build_Information
ninja-build \
python3-setuptools \
2021-08-23 19:34:17 +00:00
{ { ) end -} }
{ { if [ "5.0" , "5.1" , "5.2" ] | index( env.version) then "" else ( -} }
# https://www.qemu.org/2021/08/22/fuse-blkexport/
libfuse3-dev \
2020-11-30 19:03:55 +00:00
{ { ) end -} }
2017-12-18 21:21:01 +00:00
; \
rm -rf /var/lib/apt/lists/*; \
\
2019-01-17 22:28:12 +00:00
tarball = " $( basename " $QEMU_URL " ) " ; \
wget -O " $tarball .sig " " $QEMU_URL .sig " ; \
wget -O " $tarball " " $QEMU_URL " --progress= dot:giga; \
\
export GNUPGHOME = " $( mktemp -d) " ; \
for key in $QEMU_KEYS ; do \
2021-06-22 21:18:42 +00:00
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys " $key " ; \
2019-01-17 22:28:12 +00:00
done ; \
gpg --batch --verify " $tarball .sig " " $tarball " ; \
gpgconf --kill all; \
rm -rf " $GNUPGHOME " ; \
\
2017-12-18 21:21:01 +00:00
mkdir /usr/src/qemu; \
2019-01-17 22:28:12 +00:00
tar -xf " $tarball " -C /usr/src/qemu --strip-components= 1; \
rm " $tarball " " $tarball .sig " ; \
2017-12-18 21:21:01 +00:00
\
cd /usr/src/qemu; \
\
for p in /qemu-patches/*.patch; do \
patch --strip 1 --input " $p " ; \
done ; \
rm -rf /qemu-patches; \
2021-03-21 05:00:52 +00:00
{ { if env.variant = = "native" then ( -} }
\
arch = " $( dpkg --print-architecture) " ; \
case " $arch " in \
amd64) targetList = 'x86_64-softmmu' ; ; \
arm64) targetList = 'aarch64-softmmu' ; ; \
armel | armhf) targetList = 'arm-softmmu' ; ; \
i386) targetList = 'i386-softmmu' ; ; \
mips64el) targetList = 'mips64el-softmmu' ; ; \
ppc64el) targetList = 'ppc64-softmmu' ; ; \
s390x) targetList = 's390x-softmmu' ; ; \
*) echo >& 2 " error: architecture ' $arch ' unimplemented 😅 " ; exit 1 ; ; \
esac ; \
{ { ) else "" end -} }
2017-12-18 21:21:01 +00:00
\
./configure --help; \
2017-12-21 18:07:44 +00:00
./configure \
2021-03-19 15:44:22 +00:00
# let's add a link to our source code in the output of "--version" in case our users end up filing bugs against the QEMU project O:)
--with-pkgversion= 'https://github.com/tianon/docker-qemu' \
2021-03-21 05:00:52 +00:00
{ { if env.variant = = "native" then ( -} }
--target-list= " $targetList " \
{ { ) else ( -} }
2017-12-21 18:07:44 +00:00
--target-list= ' \
# system targets
2021-03-01 23:30:19 +00:00
# (https://sources.debian.org/src/qemu/buster/debian/rules/#L59-L63, slimmed)
2017-12-21 18:07:44 +00:00
i386-softmmu x86_64-softmmu aarch64-softmmu arm-softmmu m68k-softmmu \
2021-03-01 23:30:19 +00:00
mips64-softmmu mips64el-softmmu ppc64-softmmu riscv64-softmmu \
2017-12-21 18:07:44 +00:00
sparc64-softmmu s390x-softmmu \
' \
2021-03-21 05:00:52 +00:00
{ { ) end -} }
2021-03-19 15:38:04 +00:00
# let's point "firmware path" to Debian's value so we get access to "OVMF.fd" and friends more easily
--firmwarepath= /usr/share/qemu:/usr/share/seabios:/usr/lib/ipxe/qemu \
# https://salsa.debian.org/qemu-team/qemu/-/blob/058ab4ec8623766b50055c8c56d0d5448d52fb0a/debian/rules#L38
2017-12-21 18:07:44 +00:00
--disable-docs \
--disable-gtk --disable-vte \
--disable-sdl \
--enable-attr \
--enable-bzip2 \
--enable-cap-ng \
--enable-curl \
--enable-curses \
--enable-fdt \
--enable-gnutls \
--enable-kvm \
--enable-libiscsi \
--enable-libnfs \
2019-07-29 20:15:25 +00:00
--enable-libssh \
2017-12-21 18:07:44 +00:00
--enable-libusb \
--enable-linux-aio \
--enable-modules \
--enable-numa \
2020-09-28 23:05:41 +00:00
--enable-rbd \
2017-12-21 18:07:44 +00:00
--enable-seccomp \
--enable-tools \
--enable-usb-redir \
--enable-vhost-net \
--enable-vhost-user \
--enable-vhost-vsock \
--enable-virtfs \
--enable-vnc \
--enable-vnc-jpeg \
--enable-vnc-png \
--enable-xen \
--enable-xfsctl \
2020-08-27 20:04:22 +00:00
# rbd support is enabled, but "librbd1" is not included since it adds ~60MB and is version-sensitive (https://github.com/tianon/docker-qemu/pull/11#issuecomment-689816553)
2017-12-21 18:07:44 +00:00
# --enable-vde \
2021-08-23 19:34:17 +00:00
{ { if [ "5.0" , "5.1" , "5.2" ] | index( env.version) then "" else ( -} }
# https://www.qemu.org/2021/08/22/fuse-blkexport/
--enable-fuse \
{ { ) end -} }
2017-12-21 18:07:44 +00:00
; \
2017-12-18 21:21:01 +00:00
make -j " $( nproc) " ; \
make install; \
\
cd /; \
rm -rf /usr/src/qemu; \
\
apt-mark auto '.*' > /dev/null; \
2020-05-11 17:10:42 +00:00
[ -z " $savedAptMark " ] || apt-mark manual $savedAptMark > /dev/null; \
2020-09-28 23:05:41 +00:00
find /usr/local \
-type f \
\( -executable -o -name '*.so' \) \
# rbd support is enabled, but "librbd1" is not included since it adds ~60MB and is version-sensitive (https://github.com/tianon/docker-qemu/pull/11#issuecomment-689816553)
-not -name 'block-rbd.so' \
-exec ldd '{}' ';' \
2018-01-03 20:44:57 +00:00
| awk '/=>/ { print $(NF-1) }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
; \
2019-01-17 22:28:12 +00:00
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant= false; \
\
# basic smoke test
qemu-img --version
2017-12-18 21:21:01 +00:00
STOPSIGNAL SIGHUP
2014-09-20 07:00:11 +00:00
EXPOSE 22
EXPOSE 5900
COPY start-qemu /usr/local/bin/
CMD [ "start-qemu" ]