1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

build(docker): the image is Ubuntu 26.04 with supervisord in place of phusion's runit

phusion/baseimage brought sshd, syslog-ng, my_init and runit's per
service scripts, and an nginx log forwarder tailing a file. The image
is now ubuntu:26.04 with Ubuntu's supervisor: conf/docker holds the
start script (settings, secret key, ownership, migrations as www-data),
one supervisord.conf for the six processes, nginx's config with errors
to docker logs, the backup's cron line and the health check. A stop
signals every process at once, so the worker keeps its 60 s drain
within the 95 s grace. The same volumes and container name work as
before; README runs commands with exec -u www-data in place of
/sbin/setuser. The image goes from 805 MB to 642 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-08 16:01:38 +03:00
parent b03828c684
commit 80a66dc8b5
21 changed files with 218 additions and 203 deletions

2
conf/docker/backup.cron Normal file
View file

@ -0,0 +1,2 @@
# The daily backup into /srv/webvirtcloud/backups (the webvirtcloud-backups volume); its output goes to docker logs
15 3 * * * root (. /run/webvirtcloud.env && cd /srv/webvirtcloud && runuser -u www-data -- venv/bin/python3 manage.py backup) > /proc/1/fd/1 2>&1

10
conf/docker/healthcheck Normal file
View file

@ -0,0 +1,10 @@
#!/bin/sh
# Docker's health check: every process has run for 5 s at least (one that
# keeps failing never has) and the panel answers through nginx.
# X-Forwarded-Proto: https keeps the HTTPS profile from redirecting it.
# "webvirtcloud:worker RUNNING pid 27, uptime 0:00:10" (or "1 day, 0:00:10")
supervisorctl status | awk '
$2 != "RUNNING" { print; bad = 1; next }
$0 !~ / day/ { split($NF, t, ":"); if (t[1] * 3600 + t[2] * 60 + t[3] < 5) { print; bad = 1 } }
END { exit bad }' || exit 1
exec /srv/webvirtcloud/venv/bin/python3 -c "import urllib.request as u; u.urlopen(u.Request('http://127.0.0.1/accounts/login/', headers={'X-Forwarded-Proto': 'https'}), timeout=5)"

18
conf/docker/nginx.conf Normal file
View file

@ -0,0 +1,18 @@
# nginx of the container: the panel's site (conf/nginx/webvirtcloud.conf),
# errors to docker logs; gunicorn logs the requests.
user www-data;
worker_processes 1;
pid /run/nginx.pid;
error_log /dev/stderr warn;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
access_log off;
include /etc/nginx/conf.d/*.conf;
}

26
conf/docker/start Normal file
View file

@ -0,0 +1,26 @@
#!/bin/sh
# The container's start: settings, secret key and database in place, the
# data the panel's own, migrations run; then the command (supervisord).
set -eu
cd /srv/webvirtcloud
[ -f webvirtcloud/settings.py ] || cp webvirtcloud/settings.py.template webvirtcloud/settings.py
if [ -z "${SECRET_KEY:-}" ] && [ ! -s data/secret_key ]; then
(umask 077 && venv/bin/python3 -c 'import secrets; print(secrets.token_urlsafe(50))' > data/secret_key)
fi
# the database lives in the data volume
touch data/db.sqlite3
ln -sfn /srv/webvirtcloud/data/db.sqlite3 db.sqlite3
# The database holds compute passwords and password hashes: the data, keys,
# settings and backups are readable by the panel's user only.
chown -R www-data:www-data data /var/www/.ssh /var/www/.pki
chown www-data:www-data backups webvirtcloud/settings.py
chmod 700 data backups /var/www/.ssh /var/www/.pki
chmod 600 data/db.sqlite3 webvirtcloud/settings.py
# cron starts its jobs with an empty environment: the backup reads this one
(umask 077 && export -p > /run/webvirtcloud.env)
runuser -u www-data -- venv/bin/python3 manage.py migrate --noinput
exec "$@"

View file

@ -0,0 +1,92 @@
; The container's processes; each one's output goes to docker logs.
[supervisord]
nodaemon=true
user=root
logfile=/dev/null
logfile_maxbytes=0
pidfile=/run/supervisord.pid
[unix_http_server]
file=/run/supervisor.sock
chmod=0700
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///run/supervisor.sock
; Every process starts again whenever it ends (startsecs=0: supervisord never
; gives up on one); the health check wants each up for 5 s.
; One group: a stop signals every process at once, so the worker has its
; whole drain time within docker's stop_grace_period (95 s).
[group:webvirtcloud]
programs=nginx,gunicorn,worker,novncd,socketiod,cron
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
stopsignal=QUIT
autorestart=true
startsecs=0
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
[program:gunicorn]
command=/srv/webvirtcloud/venv/bin/gunicorn webvirtcloud.wsgi:application -c gunicorn.conf.py
directory=/srv/webvirtcloud
user=www-data
environment=HOME="/var/www"
; gunicorn ends its requests for up to 30 s (graceful_timeout)
stopwaitsecs=35
autorestart=true
startsecs=0
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
; It drains running jobs for 60 s after TERM and exits by itself.
[program:worker]
command=/srv/webvirtcloud/venv/bin/python3 manage.py run_worker
directory=/srv/webvirtcloud
user=www-data
environment=HOME="/var/www",WEBVIRTCLOUD_LOG_FILE="/srv/webvirtcloud/data/webvirtcloud-worker.log"
stopwaitsecs=80
autorestart=true
startsecs=0
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
[program:novncd]
command=/srv/webvirtcloud/venv/bin/python3 console/novncd
directory=/srv/webvirtcloud
user=www-data
environment=HOME="/var/www"
; a console is a child process of its own
stopasgroup=true
autorestart=true
startsecs=0
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
; The serial console; it refuses connections while SERIAL_CONSOLE_ENABLED is off.
[program:socketiod]
command=/srv/webvirtcloud/venv/bin/python3 console/socketiod
directory=/srv/webvirtcloud
user=www-data
environment=HOME="/var/www"
autorestart=true
startsecs=0
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
[program:cron]
command=/usr/sbin/cron -f
autorestart=true
startsecs=0
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true