# petrolyst-infra Everything that runs on the petrolyst server (109.199.127.84, Ubuntu 24.04), deployed on every push to `main`: - **Traefik** at the edge for every project on the server. Its dashboard is at https://traefik.petrolyst.com, behind Keycloak. - **fuel-monitoring** (ATOMA): Superset at https://atoma.petrolyst.com, reading the operational store `fuel-db` (Postgres 17 with TimescaleDB) through Trino. Sign-in goes through Keycloak client `petrolyst`, and the UI carries the Petrolyst brand. Customization and deployment are separate, as with media-insights and media-intelligence-docker: | Folder | Holds | |---|---| | `petrolyst-insights/` | how Superset looks and behaves for Petrolyst: config, Keycloak login code, branding, patches, dashboards. See its README. | | `traefik/` | edge proxy, TLS, the `sso` middleware (oauth2-proxy) that guards the dashboard | | `stacks/fuel-monitoring/` | Compose stack, Superset Dockerfile, Trino config and catalog, fuel-db roles | | `deploy/` | `deploy.sh` (run by CI), `rollback.sh` (manual), `lib.sh` (shared) | | `host/` | one-time server setup: `bootstrap.sh`, `secrets-init.sh` | | `keycloak/` | the `petrolyst` client for Keycloak's partial import | | `.gitea/workflows/deploy.yml` | the pipeline | No credential is in this repository. Secrets exist only on the server, under `/opt/petrolyst/secrets/`; CI holds only the SSH deploy key. ## How a deploy works 1. A push to `main` (or a manual run) starts `.gitea/workflows/deploy.yml` on the act_runner. It lints the scripts, rsyncs the checkout to a fresh `/opt/petrolyst/incoming/-/`, and calls `deploy/deploy.sh ` over SSH as user `deploy`. 2. `deploy.sh` takes the host lock `/opt/petrolyst/deploy.lock`, which it shares with `rollback.sh`, and keeps it until it exits. 3. It finalizes the upload. A new commit is moved to `releases/`, and the release is made read-only. A re-run of a deployed commit must match it byte for byte; a mismatch aborts. 4. It resolves the artifacts and writes them to `releases//ARTIFACTS`: - `SUPERSET_IMAGE_TAG` is a hash of exactly the Superset image's build inputs. They include `superset/init.sh`, so changing that file runs `superset-init` again. - `TRINO_CONFIG_HASH` and `TRAEFIK_CONFIG_HASH` are hashes of the bind-mounted config. - Compose recreates a container only when its value changes. 5. Preflight, before anything live changes: - every secret and env file exists; - `petrolyst-insights/` holds no deployment files; - `docker compose config` passes for every stack; - the Superset image is built if it is new; - the **downgrade guard** refuses an image older than the metadata database's schema. 6. It promotes the release to `/opt/petrolyst/infra`, then starts Traefik, then each stack under `stacks/`. 7. For Superset, it reads the metadata database's state: - An empty database is a fresh install: it runs `superset-init`. - If the image changed, or the database is not at the image's migration head: it stops `superset`, writes `backups/superset-meta___