7.4 KiB · text History cd071af

Deploying Vigil

Vigil ships as one OCI image (Dockerfile): a Debian runner with the release under /app, running as nobody under tini, started by bin/server. CI builds and pushes it on every push to master (.forgejo/workflows/image.yml). It needs Postgres (17; pg_trgm, which the migrations create) and nothing else. The three Rust NIFs are built from source into the release, and the runner image carries no extra system libraries for them.

Docker or Podman both work. With Podman, build with --format docker, or the image’s HEALTHCHECK is dropped (OCI images have none):

podman build --format docker -t vigil .   # or: docker build -t vigil .
docker run --rm -e DATABASE_URL=... -e SECRET_KEY_BASE=... vigil /app/bin/migrate
docker run -p 4000:4000 -v vigil-storage:/data/storage \
  -e DATABASE_URL=... -e SECRET_KEY_BASE=... -e PHX_HOST=vigil.example.com vigil

Release commands

All under /app/bin/ in the image (rel/overlays/bin/):

Command What
server Starts the app (sets PHX_SERVER=true). The image’s default command
migrate Runs the migrations. Run it before a new version’s server starts
invite [--email E] [--note T] [--days N] [--by E] Prints a registration invite link. The first account is made this way while registration is closed
invite-link EMAIL Prints a fresh link for the newest active invite to EMAIL
token EMAIL LABEL SCOPE[,SCOPE...] Makes an API token for an existing user (for sentry-cli and similar) and prints it once. mix vigil.token in development

Scopes are org:read org:write org:admin org:integrations member:read member:write member:admin team:read team:write team:admin project:read project:write project:admin project:releases event:read event:write event:admin. In each organization a token is narrowed to the user’s role there.

Health

The image’s HEALTHCHECK fetches GET /_health/ on 127.0.0.1:$PORT, with Host: localhost so the HTTPS redirect leaves it alone. Point liveness probes there: it answers ok without touching the database.

GET /api/0/internal/health/ is the readiness check, in Sentry’s shape ({"problems": [...], "healthy": {...}}): the database answers, Oban is running, and the ingest buffer is under 50,000 waiting items. It answers 503, listing the problems, otherwise.

GET /metrics is Prometheus text: request, query, ingest and Oban timings, backlog gauges and VM figures. It is off unless one of the variables below turns it on.

Variable Default
METRICS_TOKEN unset Serves /metrics to Authorization: Bearer <token>
METRICS_PUBLIC false true serves /metrics to anyone (scrape over a private network only)

Environment

Required (prod)

Variable
DATABASE_URL ecto://USER:PASS@HOST/DATABASE
SECRET_KEY_BASE 64+ random bytes: mix phx.gen.secret
PHX_HOST The public hostname. URLs and DSNs are built as https://PHX_HOST. Default example.com, which is never right

Web and database

Variable Default
PORT 4000 HTTP listen port. TLS is terminated in front of Vigil
POOL_SIZE 10 Postgres connections per node
ECTO_IPV6 off true to reach Postgres over IPv6
REGISTRATION_OPEN false true lets anyone sign up; otherwise sign-up needs an invite
VIGIL_ORG_GROUP_RULES unset Org membership from identity-provider groups: org:group:role[:provider],...

Storage

Uploaded files (source maps, artifact bundles) go to local disk unless S3_BUCKET is set.

Variable Default
VIGIL_STORAGE_ROOT /data/storage in the image (storage/ otherwise) Local storage root. The image declares a volume there; with several replicas it must be shared (or use S3)
S3_BUCKET unset Switches storage to an S3-compatible bucket. The rest are then required, except S3_REGION
S3_ENDPOINT e.g. https://s3.us-west-004.backblazeb2.com
S3_REGION us-east-1
S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY

Mail

Login links, account emails and alert emails. Without SMTP_RELAY, mail is only logged (Swoosh’s Logger adapter at info), so nothing is sent but the pod log shows what would have been.

Variable Default
SMTP_RELAY unset The relay’s hostname. Setting it turns SMTP on
SMTP_PORT 587
SMTP_USERNAME, SMTP_PASSWORD unset
SMTP_TLS if_available STARTTLS: always, if_available or never
SMTP_SSL false true for implicit TLS (port 465)
SMTP_AUTH if_available always, if_available or never
SMTP_TLS_VERIFY verify_peer verify_none for a self-signed private relay
SMTP_CACERTFILE /etc/ssl/certs/ca-certificates.crt Fallback CA bundle when the OS store can’t be loaded
MAIL_FROM_ADDRESS noreply@PHX_HOST Sender of every email
MAIL_FROM_NAME Vigil

TLS is pinned to 1.2 and 1.3 and the peer is verified against the OS CA store; see the comments in config/runtime.exs.

Clustering

Replicas work unclustered: ingest is stateless apart from a per-node key cache, which then lags a key, project or organization change by up to 30 seconds on the other nodes. Clustered, Phoenix PubSub spans the nodes, so such changes flush every node’s cache at once and live updates reach users wherever they are connected. Ingest rate limits are counted per node either way, so with N replicas a key can take up to N times its limit.

Variable Default
POD_IP unset Turns on libcluster’s Kubernetes strategy, and names the node vigil@POD_IP (rel/env.sh.eex). Set it from the downward API (status.podIP)
POD_NAMESPACE vigil Where to look for peers
CLUSTER_SELECTOR name=vigil Label selector for the peer pods. The service account needs list on pods
CLUSTER_SERVICE vigil-headless Headless Service name
RELEASE_COOKIE generated at image build Must be the same on every replica; set it from a Secret rather than rely on the baked-in one
DNS_CLUSTER_QUERY unset Alternative to libcluster: cluster by DNS (dns_cluster)

With POD_IP set, the Erlang distribution listens on port 9100 only.

Self-reporting

Vigil can report its own errors and Oban cron jobs (as cron monitors) through sentry-elixir, to a project on itself or on another Vigil. Errors about the ingest path itself are dropped, so a broken ingest can’t report into a loop.

Variable Default
VIGIL_SELF_DSN unset The project’s DSN. Unset: nothing is sent
VIGIL_SELF_ENVIRONMENT production The environment those events carry

Retention

Partitioned data is kept for set periods (config :vigil, Vigil.Partitions): events 90 days, logs 30, spans 14, uptime checks 30, session counts 400. Releases are kept 365 days after their last issue (config :vigil, Vigil.Retention, release_days:). An organization can keep less, under Settings → General. A daily job (03:53 UTC) applies those limits. It also removes stale issues, releases and orphaned artifact bundles, and, a day after deletion, deleted projects and organizations with their files.

Sign in with NEIAM (OIDC)

Off unless OIDC_ENABLED=true. OIDC_LOGIN_MODE, PUBLIC_URL, OIDC_PROVIDERS and the per-provider OIDC_* variables are neiam_auth’s; see its README (deps/neiam_auth/README.md).