- Profiler and monitoring: schema_migrations table, additive ordered
migrations, single write lock, integrity check, consistent backup via
the SQLite backup API (newest 5 kept), row-count verification before
commit, refusal to start on a database newer than the code.
- Profiler baseline migration is generated from the models and adds every
missing column (replaces ensure_columns and the manual add_*.py scripts).
- migrate.py in each component (--check exit 0/2/1, --db); services migrate
at start, OVPMON_AUTO_MIGRATE=0 only checks.
- Tests: test_migrations.py per component; verified on databases created by
the code of commit 3836049 and on the live stand.
- Docs: Database_Migrations reference, change summary, deployment
scenarios plan, README, Index.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
8.4 KiB
8.4 KiB
Deployment scenarios and safe upgrade: plan (2026-10-05)
Goal: two documented, scripted scenarios.
- Scenario 1, containers: A) all components in one container; B) one container per component.
- Scenario 2, system services, install and update: A) Alpine, B) Debian, C) Ubuntu.
Priority: an update must not damage the databases; a database must survive the migration that a new version needs.
(The request lists "variant A" three times for scenario 2; this plan reads them as A, B, C.)
What exists today
- Containers:
docker-compose.yml(four services, variant B) andDOCS/General/Deployment_Docker.md. No single-container variant. - System services: manual guide
Deployment_Native.md(tested on Alpine only), systemd units, OpenRC scripts, privilege-separation helper withdoas. No install or update script. - Database migration is incomplete:
- Profiler:
create_allplusensure_columns()for the single columnnote. The other columns that models have (public_ip,tun_mtu,mssfix,is_revoked,is_expired,expiration_date, ...) are added only by standalone manual scripts inAPP_PROFILER/scriptsandadd_columns.py. A database from an older version breaks after an update unless someone runs them. - Monitoring (
APP_CORE/db.py):CREATE TABLE IF NOT EXISTSplus_ensure_column. No schema version, no backup, no integrity check.
- Profiler:
- Found blockers for Debian/Ubuntu:
ovpmon-helpercalls/sbin/rc-service openvpnonly;process.pyusessystemctl <action> openvpnfor non-Alpine, but on Debian/Ubuntu the real unit isopenvpn-server@serverand the config is expected in/etc/openvpn/server/.doasis not installed by default (opendoaspackage; Ubuntu and Debian have it, version differs).- The UI build needs Node 20.19+ (Vite 7); Debian 12 and Ubuntu 22.04 ship older Node.
- Nginx paths and Python versions differ (
/etc/nginx/http.don Alpine,conf.dorsites-availableon Debian/Ubuntu).
Steps
1. Database migration (foundation, done first)
- One migration mechanism for both databases: table
schema_migrations(version, applied_at), ordered idempotent migrations in code (APP_PROFILER/migrations.py,APP_CORE/migrations.py), applied in a transaction at startup and by the CLImigrateused in the update script. - Migration 1 for the Profiler adds every column that the current models need and a pre-versioned database lacks (generated from the models, not hand-written);
notemoves into it. Migration forAPP_COREstamps the baseline after checking the existing schema. - Safety rules:
- Before any migration:
PRAGMA integrity_check, then a consistent backup through the SQLite backup API (<db>.bak-<timestamp>), kept. - The migration never drops or rewrites data; only
ADD COLUMNandCREATE ... IF NOT EXISTS, with defaults. - A database newer than the application is not touched: the service refuses to start with a clear message (downgrade protection).
- After the migration: integrity check and row counts compared with the backup; on failure the backup is restored automatically by the update script.
- Before any migration:
- One
VERSIONfile is written on install and update and logged on start. - Test: one pytest builds a database with the old schema (taken from the baseline commit
3836049), puts data into it, migrates, checks that the data is intact, the columns exist and a second run changes nothing.
2. Scenario 1: containers
- B (distributed): existing
docker-compose.yml, hardened: named volumes kept on update,.envtemplate, health checks, documenteddocker compose pull/build && up -d; the migration runs at the start of the Profiler and the API; pre-update volume backup command (docker run ... tar). - A (one container): new
deploy/allinone/Dockerfileanddocker-compose.allinone.yml: Alpine,supervisord(or OpenRC-free supervisor) running nginx, gunicorn, gatherer, uvicorn and OpenVPN; same environment variables, one data volume (databases, PKI, client config,/etc/openvpn), ports 80 and 1194/udp. - Script
deploy/docker/install.shandupdate.sh(idempotent: generates the secret, asks for the admin once, creates the backup, rebuilds, waits for health, prints the result). - Document:
DOCS/Deployment/Scenario1_Containers.md(A and B, install, update, backup and restore, rollback).
3. Scenario 2: system services (Alpine, Debian, Ubuntu)
deploy/native/install.shandupdate.shwith an OS adapter (detects Alpine / Debian / Ubuntu; package names, service manager, nginx paths, doas package):- install: packages,
ovpmonuser, directories, venvs, environment file (random secret), services (OpenRC or systemd), root helper and doas rules, Nginx with a self-signed certificate, firewall hints; - update: preflight (free space, version, services state) → backup (databases through the backup API,
/etc/ovpmon, PKI, client config,server.conf, code version) → stop → new code → dependencies → database migration → UI → start → health check → on failure automatic rollback (code and databases) with a log.
- install: packages,
- Debian/Ubuntu support in the code:
ovpmon-helperandprocess.pychoose the service manager (OpenRCopenvpn, systemdopenvpn-server@server) and the config location; the helper rules are checked on both. - UI build: the script builds
distin a Node 20 container (or uses a prebuilt archive) so that the host does not need a recent Node. - Document:
DOCS/Deployment/Scenario2_System_Services.mdwith one section per OS, the update procedure, backup, rollback and a "what is preserved" table.
4. Verification (containers, no real host is touched)
- Scenario 1: build and start A and B, log in, initialize PKI, create a client; then update from the old version (baseline
3836049data volume) to the new one and check that data and PKI survive. - Scenario 2: run
install.shand thenupdate.shinside Alpine 3.23, Debian 12 and Ubuntu 24.04 containers with an init system (OpenRC / systemd); seed an old database and PKI before the update; check migration, health check and rollback (forced failure). - Limit to state in the report: a container is not a full host (no real firewall,
tunand service-manager details can differ); a final run on a VM of each OS is recommended before production.
5. Documentation
- The two scenario documents, links from
README.md,DOCS/General/Index.md; the oldDeployment_Docker.mdandDeployment_Native.mdbecome short pointers to the new documents; summaryDOCS/Changes/2026-10-05_Deployment_Scenarios.md.
Decisions for the owner
- Form: scripts (
install.sh,update.sh) plus documents (recommended), or documents only. - Order of work: database migration first, then Scenario 1, then Scenario 2 (recommended), or all in one step.
- Debian/Ubuntu service manager: use
openvpn-server@serverand/etc/openvpn/server/server.conf(the distribution convention, recommended) instead of the Alpine-styleopenvpn.conf. - UI build: in a Node 20 container (recommended) or require Node 20+ on the host.
Out of scope
High availability, PostgreSQL instead of SQLite, automatic OS package upgrades, Windows hosts, a real-host run (needs a VM).
Decisions of the owner (2026-10-05)
- Scripts
install.shandupdate.shplus documents. - The database migration phase is separated from the component update. Phase 1 (this stage): migration mechanism, standalone
migratecommand, backup, checks, tests; it also runs by itself at service start. Phase 2: scenario 1 (containers). Phase 3: scenario 2 (system services). The update scripts call the migration as its own, separate step before the components are replaced or restarted. - Debian and Ubuntu:
openvpn-server@serverand/etc/openvpn/server/server.conf. - The UI is built in a Node 20 container.
Phase 1 details (migration)
- Each component has its own build context and virtualenv, so the small migration helper is a separate copy in
APP_PROFILER/andAPP_CORE/(same behaviour). - Service start applies pending migrations automatically (after the backup);
OVPMON_AUTO_MIGRATE=0makes the service only check and refuse to start while migrations are pending (used by the update scripts). The standalone command:migrate.py [--check]in each component, exit codes 0 / 2 (pending) / 1 (error). - Old standalone scripts (
add_columns.py,scripts/add_*.py) stay in place and are marked as superseded in the documentation. - Tests: one file per component, with the oldest and the baseline (
3836049) schemas embedded as SQL.