# Installation

# Installation

This page covers a ground-up install, including the reverse-proxy and DNS pieces that [Getting started](/docs/drillmark/getting-started) assumes are already in place. If you are standing Drillmark up for the first time on a fresh host, read this first.

## Prerequisites

- A Linux host with Docker 24+ and Compose v2. 2 CPU / 4 GB RAM is a comfortable starting size for Phase 1 workloads (one admin, a few dozen monitored domains).
- Public DNS you can edit. You need two names: `${DOMAIN}` for the SPA and `api.${DOMAIN}` for the backend.
- A Postgres-reachable TCP endpoint. The default `compose.yml` runs Postgres 17 in a container; you can also point `DATABASE_URL` at an existing cluster.
- An existing Bunyip / mokosh-server OIDC provider with permission to register Drillmark as a client. Standalone / local-auth mode is not supported today.
- An IMAP mailbox that already receives DMARC aggregate reports.

## 1. Clone the repo

```
git clone https://dev.a8n.run/psa-systems/drillmark.git
cd drillmark
```

## 2. DNS records

Point two `A` (or `CNAME`) records at the host before starting the stack, so Traefik can request the TLS certificates on first boot:

- `${DOMAIN}` -> host IP (or CDN edge).
- `api.${DOMAIN}` -> same host IP. Caddy proxies `/api/*` to the backend on the same origin, but the backend's own host name is useful for machine clients that hit the API directly.

## 3. Register Drillmark at Bunyip

Create an `oauth_clients` row at your mokosh-server OIDC provider with:

- Grant types: `authorization_code`, `refresh_token`.
- Public (PKCE) client; no client secret.
- Redirect URIs: `https://${DOMAIN}/auth/callback` for the SPA, plus the backend-derived `OAUTH_REDIRECT_URI` from [configuration](/docs/drillmark/configuration).
- Post-logout redirect URI: `https://${DOMAIN}/`.
- Allowed scopes: at least `openid email offline_access mokosh:read`.

Record the client UUID. You need it for `OIDC_CLIENT_ID`.

## 4. Fill .env

```
cp .env.example .env
```

See [configuration](/docs/drillmark/configuration) for the variable reference. The four blocks you cannot skip: database, security (`ENCRYPTION_KEY`), alert SMTP, and OIDC. Generate the encryption key once with:

```
openssl rand -base64 32
```

and record the value out-of-band. Losing it invalidates every stored IMAP credential and refresh token.

## 5. Reverse proxy

The sample `compose.yml` uses Traefik v3 with the `cert-cloudflare` resolver. If you already run a shared reverse proxy, remove the `traefik-public` service, drop the Traefik labels on `api` and `web`, and front them yourself. The two targets to expose are:

- `web:80` (Caddy serving the SPA) at `https://${DOMAIN}`.
- `api:8080` (Axum backend) at `https://api.${DOMAIN}`, with `/api/*` also reachable through the same path on `${DOMAIN}` so the SPA stays same-origin.

If your reverse proxy terminates TLS and reaches the api over HTTP, set `TRUSTED_PROXY_CIDRS` to the proxy's CIDR so forwarded client IPs and country headers are honoured.

## 6. First boot

```
docker compose up --detach
docker compose logs --follow api
```

The api runs SeaORM migrations at startup. Boot output you should see:

- `Applied migrations` followed by the latest migration name.
- `AuthProviderChain` lines listing each enabled authentication provider.
- `Scheduler started` with the next-fire times for the incoming queue, failed queue, geolocation, and alerts jobs.

A migration mismatch, a missing required env var, or an unreachable Postgres fails the boot before the listener binds. Fix the underlying issue; do not edit committed migrations.

## 7. Sanity check

- `curl https://api.${DOMAIN}/health` -> `{"status":"ok","service":"drillmark"}`.
- `curl https://api.${DOMAIN}/health/db` -> same shape with a database roundtrip.
- Open `https://${DOMAIN}/`, click Sign in, complete the OIDC round-trip, and land on the dashboard.
- Add a data source from Settings and watch the first incoming-queue run in the jobs history.

If any of those four steps fails, see [Troubleshooting](/docs/drillmark/troubleshooting).
