Jump to content

Gadfly/DEPLOY

From MindAttic Docs

Deploying Gadfly

Status: the Azure deployment was decommissioned on 2026-11-26 (MAT-T297). tools/deploy-azure.ps1, tools/provision-azure.ps1, the azure-deploy.yml workflow and the WebJob files (run.cmd, run.sh, settings.job) were removed in GAD-T804; the resource names, slots, Key Vault and Blob key-ring steps they documented are in git history (commit before GAD-T804). Nothing here creates billable cloud resources.

Production configuration

  • Data Protection keys (cookies, launch links, webhook secrets): Production no longer requires a Blob Storage / Key Vault key ring. Set DataProtection:KeysPath (env DataProtection__KeysPath) to a persistent, private folder so keys survive restarts; without it the library's default key location is used. It must be an absolute path that the web app and Gadfly.Worker both point at, so they share one key ring (startup throws otherwise).
  • Secrets: every credential comes from MindAttic.Vault (never a literal).
  • Database: ConnectionStrings:Gadfly, a SQL Server database. Development migrates on start; elsewhere run the server once with --migrate before the new code serves (GAD-T63).
  • Versions (GAD-T291, GAD-T336): a release build passes /p:GadflyVersion=N (the next whole number after the highest vN tag) and /p:GadflyCommit=<sha>, and the deploy tags that commit vN; the app shows V<N> and /healthz/version answers V<N> <sha>. A local build shows the highest tag plus " dev".

The worker

Exams are taken on the website; grading and the other queued work run in Gadfly.Worker, a console host beside it. It shares the site's service registration (GadflyServices.AddGadflyServices, used by Gadfly.Server/Program.cs and Gadfly.Worker/Program.cs), so it reads the same configuration, connection string and AI panel (Gadfly__AiMode). It stops on SIGTERM / Ctrl+C or when the file named by WEBJOBS_SHUTDOWN_FILE appears, within 50 s; a job cut off mid-run is put back on the queue without using up an attempt.

Runs in What
Worker (and the web app while Gadfly:Jobs:RunInWeb is true) JobWorker (every queued job: AI grading, source processing, email, webhooks, retention, stale-session close, LTI passback and roster refresh, reminders); GradingSweeper, ReminderScheduler, StaleSessionScheduler, RetentionScheduler, LtiPassbackSweeper, LtiRosterRefreshScheduler, ResponseBackfillService
Both, each for its own process ApiCallTimingWriter and EvidenceSyncWriter, DeskAdminsListWarning
Web app only Pages, the exam hub and live sessions, voice, the API; the web app always enqueues jobs

Gadfly:Jobs:RunInWeb (default true): the web app also runs the job worker and sweepers; safe, since a job is claimed by an atomic row update. Set it to false to run the queue only in the worker.

A cold database does not crash startup: the first database call of a start (AuthBootstrapper.SeedAdminAsync) is retried 8 times, 15 s apart, in case a serverless database is still resuming.

Idle shutdown (GAD-T775) (Gadfly.Server/Platform/IdleShutdown.cs) only acts on App Service; elsewhere it stays off.

Locally, .\run.ps1 -Redeploy puts Gadfly.Worker.exe beside the server in R:\MindAttic\Apps\Gadfly\Debug. Run it from there with --environment Development --Gadfly:AiMode=mock, and start the server with .\run.ps1 -RunDebug --Gadfly:Jobs:RunInWeb=false beside it to try the split.

The Hetzner pilot host (mindattic-01)

The pilot's live host is mindattic-01 (Tailscale 100.78.183.37, public https://2-31-204-8.sslip.io), stood up per MindAttic.Agency's docs/ops/hetzner-deploy-pipeline.md (GAD-T786). There is no Azure parity to keep: the Azure deployment is gone (MAT-T297, GAD-T804), so this is the only production config. Gadfly.Server and Gadfly.Worker run as separate systemd units (gadfly-server.service, gadfly-worker.service) with Gadfly:Jobs:RunInWeb=false in the env file, so only the worker runs the job queue and schedulers. Secrets come from /etc/gadfly/env, a root-only EnvironmentFile holding the same MindAttic:Vault:<bucket>:...-shaped keys AddMindAtticVaultFiles reads locally (LLM provider keys, SMTP, DataProtection:KeysPath, the auth pepper/reset/bootstrap tokens) — no Key Vault or App Service config of any kind.

Verify it's actually working (not just "the service started"), over Tailscale SSH:

ssh -i <key> root@100.78.183.37 "systemctl is-active gadfly-server gadfly-worker"
# "web app runs jobs too: False" in the worker's own startup line confirms the RunInWeb split:
ssh -i <key> root@100.78.183.37 "journalctl -u gadfly-worker --no-pager -n 50 | grep 'Gadfly.Worker.*started:'"
# scheduled jobs actually firing, not just registered -- session.stale-sweep runs every ~15 min:
ssh -i <key> root@100.78.183.37 "journalctl -u gadfly-worker --since '2 hours ago' | grep 'Running job'"
# Vault-sourced settings resolved (AI panel/voice/SMTP report live providers) and nothing failed since boot:
ssh -i <key> root@100.78.183.37 "journalctl -u gadfly-server -u gadfly-worker --since '24 hours ago' -p warning"

Confirmed 2026-12-01 (GAD-T868): both units active, the worker runs every job kind with the web app's own queue off, session.stale-sweep and notify.reminder-sweep jobs ran on schedule, the AI panel/voice/SMTP lines all report live providers, and there were no warnings or errors in the prior 24h.

Running it locally

run.ps1 at the repo root (or a double-click on run.bat) is the MindAttic standard run menu: 1 Redeploy builds Gadfly.Server, Gadfly.Worker and the CLI (gadfly.exe) into R:\MindAttic\Apps\Gadfly\Debug and \Release, 2 Run Debug starts the Debug server in this console, 3 Run Release starts the Release one on its own, and 13 redeploys then runs Release. Both runs are Development against LocalDB (database Gadfly, migrated on start). Run Debug binds localhost only (https://localhost:7311) and passes --Gadfly:AiMode=mock, so no provider is called and nothing is billed. Run Release is the pilot host (GAD-T831): it binds every interface (--urls https://+:7311;http://+:5311), not just localhost, so it is reachable from another machine, and passes --Gadfly:AiMode=live --Gadfly:Voice:Mode=live, a voice id (MindAttic:Avatar:ElevenLabs:VoiceId, until an exam or org picks its own) and a DataProtection:KeysPath outside \Debug/\Release so a redeploy does not invalidate the key ring — every exam taken against it calls the real LLM and ElevenLabs providers and is billed; the keys it needs (MindAttic:Vault:LLM:{elevenlabs,openai,claude,...}:apiKey) come from MindAttic.Vault's LLM bucket on this machine, already loaded by AddMindAtticVaultFiles. Arguments after the switches go to the Debug server, so a seed flag goes last:

.\run.ps1                                  # the menu
.\run.ps1 -Redeploy -RunDebug              # build, deploy and serve
.\run.ps1 -RunDebug --seed-demo            # also seed Gadfly Demo Academy (demo.owner ... demo.student)
.\run.ps1 -RunDebug --seed-classroom       # also seed the classroom (Teacher_A..C, Student_A..Z)
.\run.ps1 -Redeploy -DryRun                # print what would be built and launched

The seeders use Gadfly:Demo:Password (for example $env:Gadfly__Demo__Password) as every account's password, or generate one and print it once in the log. The demo tour runs from source: dotnet run --project Gadfly.Tour -- --fresh (docs/TOUR.md).

Reachable from Erin's machine (GAD-T831). The owner's machine (snowcrash) is 100.64.100.7 on the same Tailscale network Gadfly's Hetzner host already uses (GAD-T870, https://2-31-204-8.sslip.io); once Erin's device is on that tailnet (Tailscale admin console, or a share invite — a one-time owner step), she reaches the Release host at https://100.64.100.7:7311 and accepts the self-signed development certificate warning once. A fresh machine needs one inbound firewall rule first (admin PowerShell, once):

New-NetFirewallRule -DisplayName "Gadfly Pilot Host (7311)" -Direction Inbound -Protocol TCP -LocalPort 7311 -Action Allow -Profile Private

Start: .\run.ps1 -RunRelease (already-built copy) or .\run.ps1 -Redeploy -RunRelease (rebuild first), from D:\Projects\MindAttic\Gadfly, or run.bat picking 3/13; it launches Gadfly.Server.exe detached. Stop: close its console window, or Stop-Process -Name Gadfly.Server -Force (add -Name Gadfly.Worker too if the worker was started separately). See docs/PILOT.md, "Reaching the local pilot host", for Erin's side of this.

Part of Gadfly.
From Gadfly/docs/DEPLOY.md via MindAttic.Docs; synced automatically, so edit the repo, not this page.