Add a Nginx reverse proxy to combine all the used ports into one single port
This will allow this web UI to sit nicely behind a reverse proxy. Dynamically set the ports used for the - VNC service - noVNC service - Pulseaudio socket - VNC audio transport websocket Remove all mentions of the above used ports in the Dockerfile.
This commit is contained in:
@@ -1,10 +1,48 @@
|
||||
|
||||
echo "**** Configure VNC ****"
|
||||
|
||||
function get_unused_port() {
|
||||
__start_port=${1}
|
||||
__start_port=$((__start_port+1))
|
||||
for __check_port in $(seq ${__start_port} 65000); do
|
||||
[[ -z $(netstat -ap 2> /dev/null | grep ${__check_port}) ]] && break;
|
||||
done
|
||||
echo ${__check_port}
|
||||
}
|
||||
|
||||
# Export empty values to start
|
||||
# Without this, supervisor will not be able to parse the ini configs
|
||||
export PORT_VNC
|
||||
export PORT_NOVNC_SERVICE
|
||||
export PORT_AUDIO_WEBSOCKET
|
||||
export PORT_AUDIO_STREAM
|
||||
|
||||
if ([ "${MODE}" != "s" ] && [ "${MODE}" != "secondary" ]); then
|
||||
if [ ${WEB_UI_MODE} = "vnc" ]; then
|
||||
echo "Enable VNC server"
|
||||
sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisor.d/vnc.ini
|
||||
|
||||
# Configure random ports for VNC service, pulseaudio socket, noVNC service and audio transport websocket
|
||||
# Note: Ports 32035-32248 are unallocated port ranges. We should be able to find something in here that we can use
|
||||
# REF: https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?&page=130
|
||||
export PORT_VNC=$(get_unused_port 32035)
|
||||
echo "Configure VNC service port '${PORT_NOVNC_SERVICE}'"
|
||||
export PORT_NOVNC_SERVICE=$(get_unused_port ${PORT_VNC})
|
||||
echo "Configure noVNC service port '${PORT_NOVNC_SERVICE}'"
|
||||
export PORT_AUDIO_WEBSOCKET=$(get_unused_port ${PORT_NOVNC_SERVICE})
|
||||
echo "Configure audio websocket port '${PORT_AUDIO_WEBSOCKET}'"
|
||||
export PORT_AUDIO_STREAM=$(get_unused_port ${PORT_AUDIO_WEBSOCKET})
|
||||
echo "Configure pulseaudio encoded stream port '${PORT_AUDIO_STREAM}'"
|
||||
|
||||
# Configure Nginx proxy for the websocket and VNC
|
||||
sed -i "s|<USER>|${USER}|" /opt/noVNC/nginx.conf
|
||||
sed -i "s|<PORT_NOVNC_WEB>|${PORT_NOVNC_WEB}|" /opt/noVNC/nginx.conf
|
||||
sed -i "s|<PORT_NOVNC_SERVICE>|${PORT_NOVNC_SERVICE}|" /opt/noVNC/nginx.conf
|
||||
sed -i "s|<PORT_AUDIO_WEBSOCKET>|${PORT_AUDIO_WEBSOCKET}|" /opt/noVNC/nginx.conf
|
||||
mkdir -p /var/log/vncproxy
|
||||
chown -R ${USER} /var/log/vncproxy
|
||||
|
||||
|
||||
if [[ "${ENABLE_VNC_AUDIO}" == "true" ]]; then
|
||||
# Credits for this audio patch:
|
||||
# - https://github.com/novnc/noVNC/issues/302
|
||||
@@ -12,8 +50,8 @@ if ([ "${MODE}" != "s" ] && [ "${MODE}" != "secondary" ]); then
|
||||
# - https://github.com/calebj/noVNC
|
||||
if [ -f /opt/noVNC/audio.patch ]; then
|
||||
echo "Patching noVNC with audio websocket"
|
||||
# Enable supervisord script
|
||||
sed -i "s|32123|${PORT_AUDIO_WEBSOCKET}|" /opt/noVNC/audio.patch
|
||||
# Update port specification in patch file
|
||||
sed -i "s|<PORT_AUDIO_WEBSOCKET>|${PORT_AUDIO_WEBSOCKET}|" /opt/noVNC/audio.patch
|
||||
# Apply patch
|
||||
pushd /opt/noVNC/ &> /dev/null
|
||||
patch -p1 --input=/opt/noVNC/audio.patch --batch --quiet
|
||||
|
||||
@@ -6,7 +6,7 @@ autorestart=true
|
||||
# Retry a restart a few times.
|
||||
# This allows this container to start up before X is ready and restart the process until it becomes available.
|
||||
# Each restart will have a small delay of a few seconds. So 50 attempts should be a few mins.
|
||||
startretries=50
|
||||
startretries=50
|
||||
priority=50
|
||||
user=%(ENV_USER)s
|
||||
directory=/home/%(ENV_USER)s
|
||||
|
||||
@@ -18,7 +18,8 @@ autostart=false
|
||||
autorestart=true
|
||||
priority=30
|
||||
user=%(ENV_USER)s
|
||||
command=/opt/noVNC/utils/launch.sh --vnc localhost:%(ENV_PORT_VNC)s --listen %(ENV_PORT_NOVNC_WEB)s
|
||||
# /opt/noVNC/utils/launch.sh --vnc localhost:${PORT_VNC} --listen ${PORT_NOVNC_SERVICE}
|
||||
command=/opt/noVNC/utils/launch.sh --vnc localhost:%(ENV_PORT_VNC)s --listen %(ENV_PORT_NOVNC_SERVICE)s
|
||||
environment=HOME="/home/%(ENV_USER)s",USER="%(ENV_USER)s"
|
||||
stopsignal=INT
|
||||
stdout_logfile=/home/%(ENV_USER)s/.cache/log/novnc.log
|
||||
@@ -27,3 +28,20 @@ stdout_logfile_backups=7
|
||||
stderr_logfile=/home/%(ENV_USER)s/.cache/log/novnc.err.log
|
||||
stderr_logfile_maxbytes=10MB
|
||||
stderr_logfile_backups=7
|
||||
|
||||
[program:vncproxy]
|
||||
autostart=false
|
||||
autorestart=true
|
||||
priority=30
|
||||
numprocs=1
|
||||
startsecs=0
|
||||
user=%(ENV_USER)s
|
||||
command=/usr/sbin/nginx -c /opt/noVNC/nginx.conf
|
||||
environment=HOME="/home/%(ENV_USER)s",USER="%(ENV_USER)s"
|
||||
stopsignal=INT
|
||||
stdout_logfile=/home/%(ENV_USER)s/.cache/log/vncproxy.log
|
||||
stdout_logfile_maxbytes=10MB
|
||||
stdout_logfile_backups=7
|
||||
stderr_logfile=/home/%(ENV_USER)s/.cache/log/vncproxy.err.log
|
||||
stderr_logfile_maxbytes=10MB
|
||||
stderr_logfile_backups=7
|
||||
|
||||
Reference in New Issue
Block a user