Skip to content

Latest commit

 

History

History
113 lines (88 loc) · 4.27 KB

deployment.md

File metadata and controls

113 lines (88 loc) · 4.27 KB

Deployment

Contester ships as two images (contester-api, contester-web) plus off-the-shelf images (PostgreSQL, Piston, Caddy, Prometheus, Grafana). One Docker host runs everything with Compose.

flowchart LR
  user((Browser)) -->|443| caddy[Caddy<br/>TLS, HSTS]
  caddy --> web[web<br/>nginx + SPA]
  web -->|/api| api[api<br/>Spring Boot]
  api --> db[(PostgreSQL)]
  api -->|judge network| piston[Piston<br/>privileged]
  prometheus --> api
  prometheus --> exporter[nginx-exporter] --> web
  grafana --> prometheus
Loading

Requirements

  • Linux host with Docker Engine and the Compose plugin (v2.24+ for !reset).
  • Piston needs a privileged container: it creates isolate sandboxes with cgroups. Platforms that forbid privileged containers (most PaaS offerings) cannot run the judge.
  • cgroup v2 (default on current Ubuntu and Debian).
  • 2 vCPU and 4 GB RAM are enough for a small contest. The judge is CPU bound; see performance.md.
  • A domain whose A/AAAA record points at the host, with ports 80 and 443 open.
  • An SMTP account for verification and password reset mails.

Environment

Copy .env.example to .env (mode 600, owned by the deploy user) and set at least:

Variable Example
DB_PASSWORD openssl rand -base64 24
DOMAIN, ACME_EMAIL contester.example.com, ops@example.com
IMAGE_PREFIX ghcr.io/<owner>
APP_VERSION 1.0.0
SMTP_HOST, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD, SMTP_AUTH=true, SMTP_STARTTLS=true, MAIL_FROM from the mail provider
GRAFANA_ADMIN_PASSWORD random, if the observability profile is used

compose.prod.yml turns on COOKIE_SECURE, turns off Swagger, removes every host port except Caddy's 80/443, and runs the released images.

Releasing

  1. Update CHANGELOG.md: move the items under Unreleased to the new version.
  2. Tag and push: git tag v1.0.0 && git push origin v1.0.0.
  3. release.yml builds both images with SBOM and provenance, pushes them to GHCR as :1.0.0 and :1.0, and creates the GitHub release from the changelog section.

GHCR packages are private by default. Either make them public in the package settings, or run docker login ghcr.io on the host with a token that has read:packages.

First deployment

git clone https://github.com/<owner>/Contester.git && cd Contester
cp .env.example .env && chmod 600 .env && $EDITOR .env
APP_VERSION=1.0.0 scripts/deploy.sh
# optional demo data:
docker compose -f compose.yml -f compose.prod.yml --profile seed run --rm seed

deploy.sh does the following:

  1. Backs up the database, if it already exists.
  2. Pulls the images and starts the stack.
  3. Installs the judge runtimes with piston-install. This is idempotent; the first run downloads about 1 GB.
  4. Waits for readiness and runs scripts/smoke.sh against https://$DOMAIN.

To create the first real admin, register normally and then run:

docker compose -f compose.yml -f compose.prod.yml exec db \
  psql -U contester -c "UPDATE users SET role='ADMIN' WHERE email='you@example.com'"

If you loaded demo data, delete the seeded admin@contester.dev account or change its password.

Updating and rollback

  • Update: APP_VERSION=1.1.0 scripts/deploy.sh.
  • Rollback without schema changes: APP_VERSION=1.0.0 scripts/deploy.sh.
  • Rollback across a migration: Flyway migrations are forward-only, so restore the backup that deploy.sh took before the update (runbook.md).

Monitoring

Prometheus, Grafana and the nginx exporter are in the observability profile (docker compose --profile observability up -d). In production they have no host ports. Reach Grafana through an SSH tunnel to the container network, or add a separate Caddy site protected by authentication. Dashboards and alerts are described in runbook.md.

Manual GitHub settings

These settings cannot be configured from the repository, and none of them is set up yet:

  • Branch protection on main: require pull requests, the backend, frontend, e2e and gitleaks checks, and linear history.
  • Secret scanning and push protection (Settings → Code security).
  • Dependabot alerts and security updates.
  • Package visibility for contester-api and contester-web in GHCR.