feat: Replace websockify by nginx (#340)

This commit is contained in:
Kroese 2024-01-17 19:51:22 +01:00 committed by GitHub
parent d1e289eb12
commit a19b245b1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 94 additions and 36 deletions

View file

@ -10,6 +10,7 @@ RUN apt-get update \
wget \
ovmf \
socat \
nginx \
procps \
iptables \
iproute2 \
@ -20,10 +21,18 @@ RUN apt-get update \
ca-certificates \
netcat-openbsd \
qemu-system-x86 \
&& novnc="v1.4.0" \
&& wget https://github.com/novnc/noVNC/archive/refs/tags/$novnc.tar.gz -O /tmp/novnc.tar.gz -q \
&& tar -xf /tmp/novnc.tar.gz -C /tmp/ \
&& cd /tmp/noVNC-$novnc \
&& mkdir -p /usr/share/novnc \
&& mv app core vendor package.json *.html /usr/share/novnc \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY ./src /run/
COPY nginx.conf /etc/nginx/sites-enabled/novnc.conf
RUN chmod +x /run/*.sh
VOLUME /storage

View file

@ -2,9 +2,8 @@ version: "3"
services:
qemu:
container_name: qemu
image: qemux/qemu-docker:latest
image: qemux/qemu-docker
environment:
DISPLAY: "vnc"
RAM_SIZE: "1G"
CPU_CORES: "1"
DISK_SIZE: "16G"
@ -16,7 +15,6 @@ services:
cap_add:
- NET_ADMIN
ports:
- 2222:22
- 5900:5900
- 8006:8006
stop_grace_period: 2m
restart: unless-stopped

49
nginx.conf Normal file
View file

@ -0,0 +1,49 @@
server {
listen 8006 default_server;
listen [::]:8006 default_server;
autoindex on;
server_name _;
tcp_nodelay on;
server_tokens off;
error_log /dev/null;
access_log /dev/null;
include /etc/nginx/mime.types;
location / {
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_min_length 500;
gzip_disable "msie6";
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
add_header Cache-Control "no-cache";
root /usr/share/novnc;
index vnc.html;
if ($request_uri = "/") {
return 301 /?resize=scale&autoconnect=true;
}
}
location /websockify {
proxy_pass http://127.0.0.1:5700/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_read_timeout 61s;
proxy_connect_timeout 61s;
proxy_send_timeout 61s;
}
}

View file

@ -1,4 +1,4 @@
<h1 align="center">QEMU in Docker<br />
<h1 align="center">QEMU<br />
<div align="center">
<img src="https://github.com/qemus/qemu-docker/raw/master/.github/logo.png" title="Logo" style="max-width:100%;" width="128" />
</div>
@ -32,15 +32,13 @@ services:
container_name: qemu
image: qemux/qemu-docker
environment:
DISPLAY: "vnc"
BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.0-x86_64.iso"
devices:
- /dev/kvm
cap_add:
- NET_ADMIN
ports:
- 2222:22
- 5900:5900
- 8006:8006
stop_grace_period: 2m
restart: unless-stopped
```
@ -48,7 +46,7 @@ services:
Via `docker run`
```bash
docker run -it --rm -e "DISPLAY=vnc" -e "BOOT=http://example.com/image.iso" -p 5900:5900 --device=/dev/kvm --cap-add NET_ADMIN qemux/qemu-docker
docker run -it --rm -e "BOOT=http://example.com/image.iso" -p 8006:8006 --device=/dev/kvm --cap-add NET_ADMIN qemux/qemu-docker
```
## FAQ

View file

@ -4,19 +4,21 @@ set -Eeuo pipefail
# Docker environment variables
: "${GPU:="N"}" # GPU passthrough
: "${DISPLAY:="none"}" # Display type
: "${VGA:="virtio"}" # VGA adaptor
: "${DISPLAY:="web"}" # Display type
case "${DISPLAY,,}" in
vnc)
DISPLAY_OPTS="-display vnc=:0 -vga virtio"
DISPLAY_OPTS="-display vnc=:0 -vga $VGA"
;;
web)
addPackage "novnc" "web-based VNC client"
ln -sfn /usr/share/novnc/vnc_lite.html /usr/share/novnc/index.html
DISPLAY_OPTS="-display vnc=:0 -vga virtio"
DISPLAY_OPTS="-display vnc=:0,websocket=5700 -vga $VGA"
;;
none)
DISPLAY_OPTS="-display none -vga none"
;;
*)
DISPLAY_OPTS="-display $DISPLAY -vga none"
DISPLAY_OPTS="-display $DISPLAY -vga $VGA"
;;
esac
@ -24,8 +26,10 @@ if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
return 0
fi
DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128 -vga virtio"
[[ "${DISPLAY,,}" == "vnc" || "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0"
DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128 -vga $VGA"
[[ "${DISPLAY,,}" == "vnc" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0"
[[ "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0,websocket=5700"
[ ! -d /dev/dri ] && mkdir -m 755 /dev/dri

View file

@ -18,7 +18,7 @@ cd /run
trap - ERR
if [[ "${DISPLAY,,}" == "web" ]]; then
websockify -D --web /usr/share/novnc/ 8006 localhost:5900 2>/dev/null
nginx -e stderr
fi
info "Booting image using $VERS..."