Prepare database-free BortStack deployment
This commit is contained in:
+75
-105
@@ -1,118 +1,88 @@
|
||||
# Production Deployment
|
||||
# Deployment plan — not commissioned
|
||||
|
||||
## Architecture
|
||||
BS-009 prepares a database-free marketing deployment. No server, DNS, mail
|
||||
provider or production GitHub environment has been changed by this task. Launch
|
||||
still requires the Captain's explicit authorization and the gates below.
|
||||
|
||||
The supported production pattern is a Hetzner-hosted Docker Compose project:
|
||||
## Topology
|
||||
|
||||
1. LinuxServer SWAG runs as the existing shared TLS reverse proxy on an external
|
||||
Docker network (default `swagnet`).
|
||||
2. The template's nginx container joins that network, serves the built React SPA,
|
||||
and proxies `/api/` to the private API container.
|
||||
3. Gunicorn serves Flask in the non-root API container.
|
||||
4. MySQL persists to a named volume and is reachable only on the internal network.
|
||||
5. Resend provides outbound transactional account/contact email from the generated project's `@roborto.net` product identity when explicitly enabled.
|
||||
6. 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.
|
||||
7. GitHub Actions validates pull requests; pushes to `production` publish images
|
||||
tagged with the tested commit SHA and deploy that exact commit and image set.
|
||||
Docker Compose runs two services. `nginx` serves the prerendered React build and
|
||||
proxies `/api/` to the private `api` service. The API image starts
|
||||
`contact_app:app` under Gunicorn; it has no account routes, SQLAlchemy startup,
|
||||
database, migration or persistent enquiry store. The existing LinuxServer SWAG
|
||||
instance should terminate public TLS and reach `nginx:80` over the external
|
||||
network named by `SWAG_NETWORK` (default `swagnet`). The API is on the internal
|
||||
network only. Port 8081 (web) and 5001 (API) bind to host loopback for local
|
||||
diagnostics. No public hostname has been confirmed.
|
||||
|
||||
## Server prerequisites
|
||||
`/api/health/ready` confirms that the Contact process can serve requests; it
|
||||
does **not** confirm email configuration, provider delivery or inbox receipt.
|
||||
`/api/contact/config` reports whether the configured mail settings are present;
|
||||
that is not a provider or inbox test. The sample environment disables mail and
|
||||
leaves sender, recipient and API key blank. Contact responds with 503 when
|
||||
delivery is disabled or unconfigured.
|
||||
|
||||
- Docker Engine with the Compose plugin.
|
||||
- A running SWAG stack and external Docker network matching `SWAG_NETWORK`.
|
||||
- A clean clone on branch `production` at the path stored in the GitHub variable
|
||||
`PRODUCTION_DEPLOY_PATH`.
|
||||
- A mode-`600` production environment file outside the repository at the path in
|
||||
`PRODUCTION_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.
|
||||
## Server and GitHub prerequisites
|
||||
|
||||
Use `.env.example` only as a variable-name reference. Generate unique secrets and
|
||||
never commit the production file.
|
||||
- Docker Engine with Compose and an existing SWAG stack on the configured
|
||||
external network; validate the final SWAG proxy configuration and TLS.
|
||||
- A clean `production` branch checkout at `PRODUCTION_DEPLOY_PATH`, a readable
|
||||
external mode-600 environment file at `PRODUCTION_ENV_PATH`, and a deployment
|
||||
user with Docker and GHCR pull access.
|
||||
- GitHub Actions secrets `PRODUCTION_SSH_HOST`, `PRODUCTION_SSH_USER`,
|
||||
`PRODUCTION_SSH_PRIVATE_KEY`, `PRODUCTION_SSH_KNOWN_HOSTS`; variables
|
||||
`PRODUCTION_DEPLOY_PATH`, `PRODUCTION_ENV_PATH`, `PRODUCTION_PUBLIC_URL`.
|
||||
Confirm the public URL before enabling this path.
|
||||
|
||||
## Product email commissioning
|
||||
The current workflow runs on `production` pushes and manual dispatch, publishes
|
||||
commit-tagged API/nginx images, fast-forwards a clean server checkout, pulls and
|
||||
starts the two services, then probes the loopback web endpoint and public Contact
|
||||
readiness. Protect the branch and `production` environment before using that
|
||||
trigger. The workflow is **configured**, not evidence of a successful release.
|
||||
It does not perform automatic rollback.
|
||||
|
||||
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`.
|
||||
## Commissioning sequence
|
||||
|
||||
Before setting `EMAIL_DELIVERY_ENABLED=true` in production:
|
||||
1. Confirm the public hostname, SWAG network/proxy configuration, host capacity,
|
||||
firewall, GHCR access, TLS and external environment file. Use `.env.example`
|
||||
only as a variable reference; keep real settings and secrets outside Git.
|
||||
2. With mail disabled, validate
|
||||
`APP_ENV_FILE=/path/to/env docker compose --env-file /path/to/env config --quiet`
|
||||
and `python3 scripts/check-deployment-config.py` in a checkout containing
|
||||
the candidate. The script validates the safe example topology, not the
|
||||
server's secrets or connectivity.
|
||||
3. On a separately authorized deployment, start `api` and `nginx` using the
|
||||
tested images. Probe `/`, a known static route, an unknown route, local
|
||||
`/api/health/ready`, public `/api/health/ready`, and
|
||||
`/api/contact/config`. Confirm an unconfigured submission cannot report
|
||||
success. Check container health and logs without recording visitor data.
|
||||
4. Before enabling delivery, verify a BortStack sender/domain with Resend,
|
||||
verify the intended recipient mailbox and incoming routing, configure
|
||||
credentials outside Git, then make a controlled enquiry and confirm inbox
|
||||
receipt and visitor Reply-To. Provider acceptance alone is insufficient.
|
||||
5. Complete privacy/legal, authentic media, domain/SEO, backup/retention and
|
||||
production readiness review. Record the deployed commit/image tags and
|
||||
operator observations. Captain acceptance and launch authority remain
|
||||
separate from CI checks.
|
||||
|
||||
1. Confirm the generated address and reserve it for the product.
|
||||
2. Verify the required `roborto.net` sending identity and DNS records with Resend using the captain's existing domain-management process.
|
||||
3. Create the matching Cloudflare Email Routing rule and point it to the intended mailbox on the captain's private mail system.
|
||||
4. Confirm inbound delivery from an unrelated external account; a successful Resend API call does not prove inbound routing works.
|
||||
5. Send verification and password-reset messages to test users and confirm links use the production `APP_URL`.
|
||||
6. Submit the public contact form, confirm delivery to the product mailbox, and verify that replying targets the visitor address supplied through `Reply-To`.
|
||||
7. Record the sender identity, routing owner, destination owner, and test date without storing API keys, mailbox credentials, or DNS secrets in the repository.
|
||||
Do not copy inherited account/MySQL keys from an old deployment file. Existing
|
||||
MySQL containers or volumes from an earlier stack require a separate inventory
|
||||
and explicit disposal plan; changing Compose does not authorize deleting them.
|
||||
|
||||
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.
|
||||
## Operations and rollback
|
||||
|
||||
## GitHub configuration
|
||||
Gunicorn defaults to one worker because Contact's attempt limits are held in
|
||||
process memory (5/hour and 20/day per perceived IP). Multiple workers or
|
||||
replicas require a shared limiter before scaling. Nginx forwards one proxy hop
|
||||
to Contact; verify the real client IP through the actual SWAG chain before
|
||||
enabling public submissions. A shared proxy IP can cause unrelated visitors to
|
||||
share the limit. Do not trust arbitrary incoming forwarding headers. The
|
||||
sample SWAG config is a starting point, not a verified host configuration.
|
||||
|
||||
Configure these Actions secrets:
|
||||
|
||||
- `PRODUCTION_SSH_HOST`
|
||||
- `PRODUCTION_SSH_USER`
|
||||
- `PRODUCTION_SSH_PRIVATE_KEY`
|
||||
- `PRODUCTION_SSH_KNOWN_HOSTS`
|
||||
|
||||
Configure these repository or `production` environment variables:
|
||||
|
||||
- `PRODUCTION_DEPLOY_PATH`, for example `/home/deploy/example-app`
|
||||
- `PRODUCTION_ENV_PATH`, for example `/opt/example-app/.env`
|
||||
- `PRODUCTION_PUBLIC_URL`, for example `https://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
|
||||
|
||||
1. Copy `.env.example` to the external production path and replace every example.
|
||||
2. Create the configured MySQL database volume and external SWAG network through
|
||||
the normal Compose/SWAG lifecycle.
|
||||
3. Run `docker compose --env-file /path/to/.env config --quiet`.
|
||||
4. Start MySQL, run `flask --app api.py db upgrade` from the API image, then start
|
||||
the API and nginx services.
|
||||
5. Confirm `/api/health/live` and `/api/health/ready` locally and through the public URL.
|
||||
|
||||
## Health and logs
|
||||
|
||||
- `/api/health` and `/api/health/live` prove that Flask can serve a request; they do not query external dependencies.
|
||||
- `/api/health/ready` executes a minimal database query and returns `503` without 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:
|
||||
|
||||
1. Confirm a recent recoverable database backup and record the current commit and immutable image tags.
|
||||
2. Review the pending migration upgrade and downgrade operations against disposable data.
|
||||
3. 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-Proto` value 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=None` cookie 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.
|
||||
Logs are container output; define host retention, monitoring and recovery
|
||||
procedures before launch. There is no application database to back up, but
|
||||
mailbox records, server configuration and external service recovery still need
|
||||
an operator plan. For rollback, retain the previous verified commit and image
|
||||
tags, restore their clean checkout and external image overrides, validate
|
||||
Compose, restart the two services and repeat probes. Do not delete resources
|
||||
or assume that a successful health probe proves mail delivery.
|
||||
|
||||
Reference in New Issue
Block a user