Skip to content

About

Automated deployments to {tournament-name}.nu-tab.com

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

This is an application to handle automatic deployments of the mit-tab application

This app is a very light wrapper ontop of the DigitalOcean App Platform API, as the deployments themselves are no longer very complex. In particular, the deployer:

  • Creates a database instance for the app
  • Creates an App Platform instance connected to that database and the nu-tab.com domain
  • Charges users for the deployment using Stripe
  • Deletes tournaments automatically

Once DigitalOcean reports an active deployment, the deployer shows its temporary .ondigitalocean.app URL on the tournament page and includes it with the login credentials in the confirmation email. Users can open that URL while their permanent domain becomes available.

Development

Pre-requisites: External accounts

Digital Ocean

The deployer manages deployments to Digital Ocean. (The entire deployer app is essentially just an API call to Digital Ocean's App Platform API). You will need to create a DigitalOcean account with an API key. If you wish to test the subdomain set-up, you must also have the DNS of that domain managed by DigitalOcean (instructions).

Stripe

Test mode stripe credentials are necessary to test the deployment flow.

Installation

To run this app, you will need:

  • MySQL (8.0+)
  • Redis

Install these according to your local environment (e.g. brew install mysql redis).

Then, install the python dependencies:

pip install uv
uv insall

Environment Variables

Copy .env.example to .env and fill in the necessary values. If you want deployed tournaments to receive BOARD_PASSWORD at startup, set BOARD_PASSWORD in the deployer environment. Set AWS_SES_ACCESS_KEY_ID and AWS_SES_SECRET_ACCESS_KEY in the deployer environment to inject the credentials used for tournament email. The optional SES, Mail Manager, and sender settings documented in .env.example are passed through as well.

Running

With MySQL and Redis running:

# Run migrations if necessary
uv run --env-file .env flask db upgrade

# Start the web server
uv run --env-file .env flask run

In another tab, start the celery worker to process deployments:

uv run --env-file .env ./bin/start_celery

Pull request CI watcher

Run bin/ci-watch --detach once from your PR branch after pushing. It uses authenticated GitHub CLI access to check the current PR head every 60 seconds. A completed failing check triggers an alert on the next poll, even while other checks are running. When all checks pass, the watcher saves the result locally.

In Codex, the watcher sends alerts to the chat identified by CODEX_THREAD_ID or --thread if codex queue is available. Detached runs without a thread save results at the printed path. Run bin/ci-watch to see the result in your terminal. You can pass a PR number or URL to either mode.

Management Commands

Redeploy all active tournament servers

Use Actions → Redeploy active tournaments → Run workflow in this repository. The workflow is manual only; pushing code or merging a PR never triggers it. It becomes available after its workflow file is merged into master.

One-time setup: add a repository Actions secret named DIGITALOCEAN_TOKEN with access to the tournament apps (app:read and app:update scopes). The workflow discovers apps directly through DigitalOcean and does not need MySQL, Redis, Stripe, or the deployer's other credentials.

  1. Push the MITTab changes to the tournament source branch (master or discord).
  2. Run the workflow with Preview checked to see eligible apps and skipped apps.
  3. Run it again with Preview unchecked to deploy. Choose the tournament source branch, optionally include -test servers, and optionally name the first app to deploy (full name, such as mittab-example). The workflow's own GitHub branch selector chooses the script version, not the tournament source branch.

The first eligible app (alphabetically, unless specified) must reach DigitalOcean's ACTIVE phase before the rest deploy in batches of three by default. A failed, changed, or timed-out app stops subsequent batches; the current batch finishes. The run summary links each app and lists deployment IDs, successes, failures, skips, and apps that were not started. Concurrent workflow runs are serialized.

Eligible apps have a mittab- name, an active deployment, and all source components pointing to MIT-Tab/mit-tab on the selected branch. Tests are excluded by default. Apps with pending/in-progress deployments or a pinned deployment are skipped. Here, "active" means live in DigitalOcean; discovery does not use the deployer's database active flag or deletion date. App specs and active deployments are rechecked immediately before each redeploy. A preview is a snapshot, not a saved deployment plan.

This creates deployments of the latest source on each app's existing branch. It preserves the app spec, domains, environment variables, and database attachments; it does not recreate servers, charge Stripe, or update settings generated by this deployer. Application startup tasks and migrations still run as usual. Choose all to include every source branch without moving any app between branches. Avoid pushing more changes during a rollout if all apps need the same revision. Force build optionally prevents build reuse and is not required to fetch new source changes.

You can also use the same dependency-free script locally (Python 3.8+), with DIGITALOCEAN_TOKEN already exported:

# Preview only
python scripts/redeploy_active.py --branch master

# Deploy first to one named server, then the rest in batches
python scripts/redeploy_active.py --branch master --execute --canary mittab-example

Each deployment has a 30-minute wait limit (--timeout in seconds locally). Timeouts or canceling a workflow stop the script, but do not cancel deployments already submitted to DigitalOcean. Check those apps before retrying. The first app reaching ACTIVE checks platform deployment health; it is not an application smoke test. Rollback remains an explicit per-app action in DigitalOcean, and does not reverse database migrations.

Individual tournament management

List recent tournaments, including failed deployments:

uv run --env-file .env flask list-tournaments

Redeploy an existing tournament without charging Stripe again:

uv run --env-file .env flask redeploy-tournament <app-id>

Delete a DigitalOcean database by exact name:

uv run --env-file .env flask delete-digitalocean-resource <database-name>

Delete a DigitalOcean app by name:

uv run --env-file .env flask delete-digitalocean-resource --type app <app-name>

Shared MySQL (opt-in)

See shared MySQL rollout, pricing and verification before setting SHARED_MYSQL_ENABLED=true. Existing tournament deployments retain their current database ownership and pricing. The default remains dedicated hosting.

About

Automated deployments to {tournament-name}.nu-tab.com

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages