feat: Replace websockify by nginx (#340)
This commit is contained in:
parent
d1e289eb12
commit
a19b245b1e
6 changed files with 94 additions and 36 deletions
|
@ -10,6 +10,7 @@ RUN apt-get update \
|
||||||
wget \
|
wget \
|
||||||
ovmf \
|
ovmf \
|
||||||
socat \
|
socat \
|
||||||
|
nginx \
|
||||||
procps \
|
procps \
|
||||||
iptables \
|
iptables \
|
||||||
iproute2 \
|
iproute2 \
|
||||||
|
@ -20,10 +21,18 @@ RUN apt-get update \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
netcat-openbsd \
|
netcat-openbsd \
|
||||||
qemu-system-x86 \
|
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 \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
COPY ./src /run/
|
COPY ./src /run/
|
||||||
|
COPY nginx.conf /etc/nginx/sites-enabled/novnc.conf
|
||||||
|
|
||||||
RUN chmod +x /run/*.sh
|
RUN chmod +x /run/*.sh
|
||||||
|
|
||||||
VOLUME /storage
|
VOLUME /storage
|
||||||
|
|
|
@ -2,9 +2,8 @@ version: "3"
|
||||||
services:
|
services:
|
||||||
qemu:
|
qemu:
|
||||||
container_name: qemu
|
container_name: qemu
|
||||||
image: qemux/qemu-docker:latest
|
image: qemux/qemu-docker
|
||||||
environment:
|
environment:
|
||||||
DISPLAY: "vnc"
|
|
||||||
RAM_SIZE: "1G"
|
RAM_SIZE: "1G"
|
||||||
CPU_CORES: "1"
|
CPU_CORES: "1"
|
||||||
DISK_SIZE: "16G"
|
DISK_SIZE: "16G"
|
||||||
|
@ -16,7 +15,6 @@ services:
|
||||||
cap_add:
|
cap_add:
|
||||||
- NET_ADMIN
|
- NET_ADMIN
|
||||||
ports:
|
ports:
|
||||||
- 2222:22
|
- 8006:8006
|
||||||
- 5900:5900
|
|
||||||
stop_grace_period: 2m
|
stop_grace_period: 2m
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
49
nginx.conf
Normal file
49
nginx.conf
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
<h1 align="center">QEMU in Docker<br />
|
<h1 align="center">QEMU<br />
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="https://github.com/qemus/qemu-docker/raw/master/.github/logo.png" title="Logo" style="max-width:100%;" width="128" />
|
<img src="https://github.com/qemus/qemu-docker/raw/master/.github/logo.png" title="Logo" style="max-width:100%;" width="128" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,15 +32,13 @@ services:
|
||||||
container_name: qemu
|
container_name: qemu
|
||||||
image: qemux/qemu-docker
|
image: qemux/qemu-docker
|
||||||
environment:
|
environment:
|
||||||
DISPLAY: "vnc"
|
|
||||||
BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.0-x86_64.iso"
|
BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.0-x86_64.iso"
|
||||||
devices:
|
devices:
|
||||||
- /dev/kvm
|
- /dev/kvm
|
||||||
cap_add:
|
cap_add:
|
||||||
- NET_ADMIN
|
- NET_ADMIN
|
||||||
ports:
|
ports:
|
||||||
- 2222:22
|
- 8006:8006
|
||||||
- 5900:5900
|
|
||||||
stop_grace_period: 2m
|
stop_grace_period: 2m
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
```
|
```
|
||||||
|
@ -48,7 +46,7 @@ services:
|
||||||
Via `docker run`
|
Via `docker run`
|
||||||
|
|
||||||
```bash
|
```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
|
## FAQ
|
||||||
|
|
|
@ -4,19 +4,21 @@ set -Eeuo pipefail
|
||||||
# Docker environment variables
|
# Docker environment variables
|
||||||
|
|
||||||
: "${GPU:="N"}" # GPU passthrough
|
: "${GPU:="N"}" # GPU passthrough
|
||||||
: "${DISPLAY:="none"}" # Display type
|
: "${VGA:="virtio"}" # VGA adaptor
|
||||||
|
: "${DISPLAY:="web"}" # Display type
|
||||||
|
|
||||||
case "${DISPLAY,,}" in
|
case "${DISPLAY,,}" in
|
||||||
vnc)
|
vnc)
|
||||||
DISPLAY_OPTS="-display vnc=:0 -vga virtio"
|
DISPLAY_OPTS="-display vnc=:0 -vga $VGA"
|
||||||
;;
|
;;
|
||||||
web)
|
web)
|
||||||
addPackage "novnc" "web-based VNC client"
|
DISPLAY_OPTS="-display vnc=:0,websocket=5700 -vga $VGA"
|
||||||
ln -sfn /usr/share/novnc/vnc_lite.html /usr/share/novnc/index.html
|
;;
|
||||||
DISPLAY_OPTS="-display vnc=:0 -vga virtio"
|
none)
|
||||||
|
DISPLAY_OPTS="-display none -vga none"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
DISPLAY_OPTS="-display $DISPLAY -vga none"
|
DISPLAY_OPTS="-display $DISPLAY -vga $VGA"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -24,8 +26,10 @@ if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128 -vga virtio"
|
DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128 -vga $VGA"
|
||||||
[[ "${DISPLAY,,}" == "vnc" || "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0"
|
|
||||||
|
[[ "${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
|
[ ! -d /dev/dri ] && mkdir -m 755 /dev/dri
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ cd /run
|
||||||
trap - ERR
|
trap - ERR
|
||||||
|
|
||||||
if [[ "${DISPLAY,,}" == "web" ]]; then
|
if [[ "${DISPLAY,,}" == "web" ]]; then
|
||||||
websockify -D --web /usr/share/novnc/ 8006 localhost:5900 2>/dev/null
|
nginx -e stderr
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Booting image using $VERS..."
|
info "Booting image using $VERS..."
|
||||||
|
|
Loading…
Reference in a new issue