Skip to content

Latest commit

 

History

History
257 lines (194 loc) · 8.91 KB

DEPLOY.md

File metadata and controls

257 lines (194 loc) · 8.91 KB

Deploying to tasks.chrisdegroot.ca

This deploys the app behind Caddy (automatic HTTPS via Let's Encrypt) on a single Linux box, using Docker Compose. It assumes this is the first service running on that box's ports 80/443.

1. DNS (at your domain registrar)

Add a DNS record for the subdomain pointing at the box's public IP:

Type Name Value
A tasks <box's public IPv4>
AAAA tasks <box's public IPv6> (if it has one)

Using a subdomain (rather than a path like chrisdegroot.ca/tasks) means this doesn't touch whatever currently serves chrisdegroot.ca itself (e.g. your Bluesky .well-known verification) — it's a fully independent site as far as DNS and Caddy are concerned.

Wait for the record to propagate before continuing — check with:

dig +short tasks.chrisdegroot.ca

2. On the Linux box: prerequisites

  • Docker + the Docker Compose plugin installed (docs).

  • Ports 80 and 443 open in the firewall and reachable from the internet (Caddy needs 80 for the ACME HTTP challenge and 443 for HTTPS):

    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp

    (Skip if using a cloud provider's security group instead of ufw — open the same two ports there.)

3. Get the code onto the box

sudo mkdir -p /opt/task-queue
sudo chown "$USER" /opt/task-queue
git clone https://github.com/DeGrootResearchGroup/task-queue.git /opt/task-queue
cd /opt/task-queue

4. Configure secrets on the box

cd /opt/task-queue
cp .env.production.example .env

Edit .env:

  • SECRET_KEY — generate with python3 -c "import secrets; print(secrets.token_urlsafe(48))".

  • OWNER_PASSWORD_HASH — generate on this Mac (so the password never touches the box in plaintext) by running:

    uv run scripts/hash_password.py

    Use the line labeled "Running with docker compose instead?" — it has $ doubled to $$, which Compose's env_file parsing requires. The plain hash will silently corrupt (Owner login just stops working, no error) if pasted in as-is — see the comment in .env.production.example.

  • INTAKE_TOKEN_HASH — optional. Only needed if something will post captured items to POST /intake/requests (see the README). Leave it blank and the route is never registered, so the path does not exist at all. To enable it, generate both halves on this Mac:

    uv run scripts/generate_intake_token.py

    It prints a raw token and an INTAKE_TOKEN_HASH= line. Paste the hash line into .env on the box; give the raw token to whatever calls the endpoint and keep it somewhere that keeps secrets (macOS Keychain, a password manager), not a dotfile.

    The raw token is shown once and cannot be recovered — the server stores only its SHA-256 digest, so a leaked .env, a copied task_queue.db or a restored backup yields nothing that can be presented at the endpoint. Lose it and you generate a new one; there is nothing to look up.

    Unlike OWNER_PASSWORD_HASH, the hash line needs no $-escaping — a hex digest contains none.

    It is still a bearer token: anyone holding the raw value can put items into "Awaiting review", so never commit it and never put it in a URL, where it would land in logs.

DATABASE_URL and ENVIRONMENT are already set correctly for this setup in .env.production.example — leave them as-is.

Rotating the intake token

Generating a new one is the only way to revoke the old, and the app reads .env only at startup. Run the same script again:

uv run scripts/generate_intake_token.py

Put the new INTAKE_TOKEN_HASH line in .env on the box, then restart so it is picked up:

cd /opt/task-queue && docker compose up -d

Then give the new raw token to the caller. Until you do, its posts get a flat 404 — the same response a wrong token has always given, so a stale caller fails looking like "no such endpoint" rather than "wrong credential". Nothing already captured is affected: rotating only changes who may add more.

5. Build and start

docker compose up -d --build

This builds the app image, runs alembic upgrade head automatically on container start, and brings up Caddy in front of it. Caddy will request a certificate from Let's Encrypt for tasks.chrisdegroot.ca on first request — watch it succeed with:

docker compose logs -f caddy

6. Verify

curl -I https://tasks.chrisdegroot.ca/

Then open https://tasks.chrisdegroot.ca/login in a browser and log in with the Owner password you hashed in step 4.

Redeploying after code changes

cd /opt/task-queue
git pull
docker compose up -d --build

This rebuilds the app image (Caddy is untouched unless the Caddyfile changed) and recreates just that container — Docker's layer caching means --build is fast when only application code changed. Database migrations run automatically as part of the container's startup command, so there's no separate migration step. Expect a few seconds of downtime while the old app container stops and the new one starts; Caddy stays up throughout and will just return an error for that brief window.

Verify afterward:

docker compose ps
curl -sD - -o /dev/null https://tasks.chrisdegroot.ca/

The SQLite database lives in the task_queue_data named volume and survives rebuilds. For a quick one-off backup:

docker compose exec app python3 -c "
import sqlite3
src = sqlite3.connect('/app/data/task_queue.db')
dst = sqlite3.connect('/app/data/backup.db')
src.backup(dst)
"
docker cp $(docker compose ps -q app):/app/data/backup.db ./backup-$(date +%F).db
docker compose exec app rm /app/data/backup.db

(The image doesn't include the sqlite3 CLI, only Python's built-in sqlite3 module — hence the inline script above instead of the more common sqlite3 ... ".backup" one-liner.)

For real, ongoing protection you want this automated and off-box — see the next section.

Automated off-box backups (Backblaze B2)

A single SQLite file with no automated, off-box backup is one disk failure from total data loss. scripts/backup_to_b2.sh does the same consistent-snapshot backup as above, then uploads it to a Backblaze B2 bucket via rclone, on a nightly cron schedule. The script's own header comment has the full walkthrough; summary:

# 1. Install rclone
curl https://rclone.org/install.sh | sudo bash

# 2. In the B2 web console: create a bucket (e.g. "task-queue-backups")
#    and an Application Key scoped to just that bucket (not the Master
#    Application Key).

# 3. Configure the rclone remote (name it exactly "b2")
rclone config

# 4. Test it once by hand
sudo bash /opt/task-queue/scripts/backup_to_b2.sh

# 5. Add to root's crontab to run nightly at 3am
sudo crontab -e
# add this line:
0 3 * * * /opt/task-queue/scripts/backup_to_b2.sh >> /var/log/task-queue-backup.log 2>&1

The script keeps the last 14 days of backups locally (/opt/task-queue/backups/) and prunes older ones automatically; it doesn't prune the B2 side, since a bucket-level Lifecycle Rule (configurable in B2's web console) handles that more reliably than a script guessing at retention. At this file's size (a personal request queue's DB stays in the low single-digit MB for a long time), B2's free 10GB tier comfortably covers years of nightly backups even without pruning the remote side at all.

Email notifications (optional)

Off by default. To enable, add to .env on the box:

SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-sending-address@gmail.com
SMTP_PASSWORD=your-16-character-app-password
OWNER_NOTIFICATION_EMAIL=you@example.com   # optional; leave blank to skip Owner-facing pings

SMTP_PASSWORD must be a Gmail App Password, not the account's normal login password — Google's SMTP relay requires it. Generate one at myaccount.google.com/apppasswords (requires 2-Step Verification to already be enabled on that Google account). It's 16 lowercase letters with no $ or other special characters, so unlike OWNER_PASSWORD_HASH there's no Compose escaping gotcha here.

The sender display name isn't set via .env — it's derived from the Owner display name field on the /settings page, shown as <name>'s Task Queue. Change it there if you want a different sender name.

Then docker compose up -d to pick up the new .env values (no rebuild needed — this is only an environment variable change). The Settings page in the app (/settings) shows whether email is currently enabled and where Owner-facing notifications are going, without exposing the credentials themselves.

Requesters get emailed on: received, accepted, declined, needs-information, completed. The Owner (if OWNER_NOTIFICATION_EMAIL is set) gets emailed on: new submission, requester adding information or responding to a question.