7.7 KiB
Production Deployment
Architecture
The supported production pattern is a Hetzner-hosted Docker Compose project:
- LinuxServer SWAG runs as the existing shared TLS reverse proxy on an external
Docker network (default
swagnet). - The template's nginx container joins that network, serves the built React SPA,
and proxies
/api/to the private API container. - Gunicorn serves Flask in the non-root API container.
- MySQL persists to a named volume and is reachable only on the internal network.
- Resend provides outbound transactional account/contact email from the generated project's
@roborto.netproduct identity when explicitly enabled. - Cloudflare Email Routing receives mail sent to that product address and forwards it to the captain's private mail server; this inbound path is provisioned outside the repository.
- GitHub Actions validates pull requests; pushes to
productionpublish images tagged with the tested commit SHA and deploy that exact commit and image set.
Server prerequisites
- Docker Engine with the Compose plugin.
- A running SWAG stack and external Docker network matching
SWAG_NETWORK. - A clean clone on branch
productionat the path stored in the GitHub variablePRODUCTION_DEPLOY_PATH. - A mode-
600production environment file outside the repository at the path inPRODUCTION_ENV_PATH. - A deployment user able to run Docker without an interactive prompt and pull the repository's GHCR packages.
- A verified SSH host key and dedicated deployment key.
Use .env.example only as a variable-name reference. Generate unique secrets and
never commit the production file.
Product email commissioning
The generator derives a product mailbox from the project slug. For example, a project named Example Product receives example-product@roborto.net as both the example Resend sender address and contact destination. The visible sender name remains independently configurable in EMAIL_FROM.
Before setting EMAIL_DELIVERY_ENABLED=true in production:
- Confirm the generated address and reserve it for the product.
- Verify the required
roborto.netsending identity and DNS records with Resend using the captain's existing domain-management process. - Create the matching Cloudflare Email Routing rule and point it to the intended mailbox on the captain's private mail system.
- Confirm inbound delivery from an unrelated external account; a successful Resend API call does not prove inbound routing works.
- Send verification and password-reset messages to test users and confirm links use the production
APP_URL. - Submit the public contact form, confirm delivery to the product mailbox, and verify that replying targets the visitor address supplied through
Reply-To. - Record the sender identity, routing owner, destination owner, and test date without storing API keys, mailbox credentials, or DNS secrets in the repository.
Resend handles application-originated outbound mail; Cloudflare Email Routing handles inbound mail. The application does not host an SMTP receiver, read the destination mailbox, or provision either provider. Keep RESEND_API_KEY and all private-mail-server credentials outside Git.
GitHub configuration
Configure these Actions secrets:
PRODUCTION_SSH_HOSTPRODUCTION_SSH_USERPRODUCTION_SSH_PRIVATE_KEYPRODUCTION_SSH_KNOWN_HOSTS
Configure these repository or production environment variables:
PRODUCTION_DEPLOY_PATH, for example/home/deploy/example-appPRODUCTION_ENV_PATH, for example/opt/example-app/.envPRODUCTION_PUBLIC_URL, for examplehttps://app.example.com
The workflow refuses a dirty remote checkout or a branch other than production,
fast-forwards to the tested commit, runs migrations from the immutable API image,
and checks the local frontend plus the public health endpoint. Protect the
production environment/branch where the GitHub plan permits it.
SWAG
Adapt ops/swag/app.subdomain.conf.sample to the desired SWAG hostname convention.
SWAG should proxy to the Compose nginx service on port 80 over the shared network.
Do not expose MySQL. Loopback-bound ports 8081 and 5001 are provided only for
server-local diagnostics.
Manual first deployment
- Copy
.env.exampleto the external production path and replace every example. - Create the configured MySQL database volume and external SWAG network through the normal Compose/SWAG lifecycle.
- Run
docker compose --env-file /path/to/.env config --quiet. - Start MySQL, run
flask --app api.py db upgradefrom the API image, then start the API and nginx services. - Confirm
/api/health/liveand/api/health/readylocally and through the public URL.
Health and logs
/api/healthand/api/health/liveprove that Flask can serve a request; they do not query external dependencies./api/health/readyexecutes a minimal database query and returns503without database details when persistence is unavailable. Compose and deployment verification use this readiness endpoint.- Application events use one-line JSON on standard error with timestamp, severity, logger, and generic message. Account tokens, request bodies, contact contents, email addresses, credentials, and provider/database exception details must not be added to logs.
- Container logs remain the default collection boundary. Add a host-level retention/forwarding policy before production; this template does not select an external observability vendor.
Use liveness for process restarts and readiness for routing/deployment gates. A healthy probe does not prove registration, email delivery, authentication, or every migration is correct.
Deployment failure and rollback
The workflow stops on failed configuration, pull, migration, service update, or health verification. Because database migrations may be forward-only, application rollback and schema rollback are separate decisions.
Before each production deployment:
- Confirm a recent recoverable database backup and record the current commit and immutable image tags.
- Review the pending migration upgrade and downgrade operations against disposable data.
- Confirm the previous API/nginx image tags remain pullable.
For an application-only rollback, set API_IMAGE and NGINX_IMAGE to the previously verified commit tags in the external environment/deployment invocation, restore the corresponding clean Git commit, run docker compose config --quiet, and update the API/nginx services. Do not run a database downgrade automatically.
If the previous application is incompatible with the migrated schema, keep the new application stopped or in maintenance mode while following a migration-specific recovery plan. Restore into disposable infrastructure first; never overwrite the production volume merely because a deployment health check failed.
Security and proxy boundaries
- SWAG is the sole public TLS boundary. MySQL is internal-only; diagnostic API/nginx ports bind to loopback.
- Nginx preserves the trusted upstream
X-Forwarded-Protovalue from SWAG and replaces client forwarding headers at the application boundary. Flask trusts exactly one nginx proxy hop. - Production startup rejects wildcard CORS, short secret keys, SQLAlchemy query logging, and insecure
SameSite=Nonecookie configuration. - Nginx applies frame, MIME-sniffing, referrer, and browser-permission headers. Add a project-specific Content Security Policy only after inventorying required scripts, styles, fonts, frames, and external origins.
- Review host firewalling, Docker daemon access, SSH key scope, GHCR package access, log retention, disk alerts, resource limits, and security updates before launch.
Production provisioning, Resend identity verification, and DNS/Cloudflare changes remain deliberate operator actions; this repository does not create or mutate external infrastructure.