red-teaming-api

red-teaming-api

Stub FastAPI service for splitting backend functionality into standalone apps.

Endpoints

  • GET /health -> runs SELECT 1 against configured SQL DB
  • GET /version -> {"version":"0.1.0"} (or APP_VERSION env var)

Database Connectivity

Set DATABASE_URL before starting the API or running migrations.

export DATABASE_URL='postgresql+psycopg://USER:PASSWORD@HOST:5432/fdcdb?sslmode=require'

For Fly deployment:

flyctl secrets set DATABASE_URL='postgresql+psycopg://USER:PASSWORD@HOST:5432/fdcdb?sslmode=require' --app red-teaming-api

Migrations

cd red-teaming/api
uv run alembic upgrade head      # apply all migrations
uv run alembic downgrade -1      # rollback one migration

Run locally

cd red-teaming/api
export DATABASE_URL='sqlite+pysqlite:///./local.db'
uv run uvicorn app.main:app --reload --port 8080

Run tests

cd red-teaming/api
uv run pytest

Deploy manually

cd red-teaming/api
flyctl deploy --remote-only --app red-teaming-api

Always-on policy

fly.toml is configured to keep this app warm:

  • auto_stop_machines = "off"
  • min_machines_running = 1
  • [[restart]] policy = "always"

After a deploy, verify at least one machine is running:

flyctl machine list --app red-teaming-api --json | jq -r '.[] | [.id, .state, (.config.restart.policy // "unset")] | @tsv'

If the app is already suspended/stopped, recover with:

flyctl machine list --app red-teaming-api --json | jq -r '.[] | select(.state != "destroyed") | .id' | head -n1 | xargs -I{} flyctl machine start {} --app red-teaming-api