-
Notifications
You must be signed in to change notification settings - Fork 34
/
Dockerfile.template
255 lines (247 loc) · 7.17 KB
/
Dockerfile.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
FROM debian:bookworm-slim
RUN set -eux; \
# add backports for (potentially) newer QEMU firmware packages
if grep backports /etc/apt/sources.list.d/debian.sources; then exit 1; fi; \
sed -ri -e 's/([[:space:]])([^[:space:]]+)-updates($|[[:space:]])/\0\1\2-backports\3/' /etc/apt/sources.list.d/debian.sources; \
grep backports /etc/apt/sources.list.d/debian.sources; \
# and add APT pinning to ensure we don't accidentally get QEMU from Debian
{ \
echo 'Package: src:edk2'; \
echo 'Pin: release a=*-backports'; \
echo 'Pin-Priority: 600'; \
echo; \
echo 'Package: src:qemu'; \
echo 'Pin: version *'; \
echo 'Pin-Priority: -10'; \
} > /etc/apt/preferences.d/qemu.pref; \
apt-get update; \
# https://github.com/tianon/docker-qemu/issues/30
apt-get install -y --no-install-recommends ca-certificates; \
{{ def firmware_packages: {
amd64: "ovmf",
arm64: "qemu-efi-aarch64",
"armel | armhf": "qemu-efi-arm",
i386: "ovmf-ia32",
riscv64: "opensbi u-boot-qemu",
# TODO add u-boot-qemu to more arches? https://packages.debian.org/bookworm/u-boot-qemu
} -}}
{{ 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 ( -}}
apt-get install -y --no-install-recommends \
{{
[
firmware_packages
| to_entries[]
| (
-}}
# {{ .key }}
{{ .value }} \
{{
)
] | add
-}}
; \
{{ ) end -}}
rm -rf /var/lib/apt/lists/*
COPY *.patch /qemu-patches/
# 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)
# https://www.qemu.org/download/#source
# https://download.qemu.org/?C=M;O=D
ENV QEMU_VERSION {{ .version }}
ENV QEMU_URL {{ .url }}
RUN set -eux; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
gnupg \
wget \
xz-utils \
\
patch \
\
bzip2 \
gcc \
gnutls-dev \
libaio-dev \
libbz2-dev \
libc-dev \
libcap-dev \
libcap-ng-dev \
libcurl4-gnutls-dev \
libglib2.0-dev \
libiscsi-dev \
libjpeg-dev \
libncursesw5-dev \
libnfs-dev \
libnuma-dev \
libpixman-1-dev \
libpng-dev \
librbd-dev \
libseccomp-dev \
libssh-dev \
libusb-1.0-0-dev \
libusbredirparser-dev \
libxen-dev \
make \
pkg-config \
python3 \
zlib1g-dev \
# https://wiki.qemu.org/ChangeLog/5.2#Build_Information
ninja-build \
python3-setuptools \
# https://www.qemu.org/2021/08/22/fuse-blkexport/
libfuse3-dev \
# https://wiki.qemu.org/ChangeLog/7.2#Removal_of_the_.22slirp.22_submodule_.28affects_.22-netdev_user.22.29
libslirp-dev \
{{ if env.version | IN("7.2", "8.0") then "" else ( -}}
# https://wiki.qemu.org/ChangeLog/8.1#Build_Dependencies
python3-venv \
# "../meson.build:3070:18: ERROR: Git program not found, cannot download dtc.wrap via git."
git \
{{ ) end -}}
; \
rm -rf /var/lib/apt/lists/*; \
\
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 \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
done; \
gpg --batch --verify "$tarball.sig" "$tarball"; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME"; \
\
mkdir /usr/src/qemu; \
tar -xf "$tarball" -C /usr/src/qemu --strip-components=1; \
rm "$tarball" "$tarball.sig"; \
\
cd /usr/src/qemu; \
\
for p in /qemu-patches/*.patch; do \
patch --strip 1 --input "$p"; \
done; \
rm -rf /qemu-patches; \
{{ 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 -}}
\
./configure --help; \
./configure \
# 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' \
{{ if env.variant == "native" then ( -}}
--target-list="$targetList" \
{{ ) else ( -}}
--target-list=' \
# system targets
# (https://sources.debian.org/src/qemu/buster/debian/rules/#L59-L63, slimmed)
i386-softmmu x86_64-softmmu aarch64-softmmu arm-softmmu m68k-softmmu \
mips64-softmmu mips64el-softmmu ppc64-softmmu riscv64-softmmu \
sparc64-softmmu s390x-softmmu \
' \
{{ ) end -}}
# 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
--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 \
--enable-libssh \
--enable-libusb \
--enable-linux-aio \
--enable-modules \
--enable-numa \
--enable-rbd \
--enable-seccomp \
--enable-strip \
--enable-tools \
--enable-usb-redir \
--enable-vhost-net \
--enable-vhost-user \
--enable-vhost-vdpa \
--enable-virtfs \
--enable-vnc \
--enable-vnc-jpeg \
--enable-xen \
# 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)
# --enable-vde \
# https://www.qemu.org/2021/08/22/fuse-blkexport/
--enable-fuse \
# https://wiki.qemu.org/ChangeLog/7.2#Removal_of_the_.22slirp.22_submodule_.28affects_.22-netdev_user.22.29
--enable-slirp \
; \
make -j "$(nproc)"; \
make install; \
\
cd /; \
rm -rf /usr/src/qemu; \
\
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
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 '{}' ';' \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
\
# basic smoke test
qemu-img --version
STOPSIGNAL SIGHUP
EXPOSE 22
EXPOSE 5900
COPY start-qemu /usr/local/bin/
CMD ["start-qemu"]