Prompt file imported from alanjwade/fct_stats (
.github/prompts/publish_to_production.prompt.md). Copyright stays with the author.
Publishing FCT Stats to Production
This prompt helps you publish the FCT Stats application to the homelab production server.
Overview
The FCT Stats application runs on a homelab server using Docker containers. There are separate publish scripts for:
- Webapp: Flask application code, templates, static files
- Database: SQLite database with all athlete/meet/result data
- Both: Combined publish (recommended for most updates)
Quick Start (Default Command)
To publish everything and restart the production server in one go:
./scripts/publish-all.sh && cd ~/homelab/fct_stats && mkdir -p data/db && mv data/fct_stats.db data/db/fct_stats.db 2>/dev/null || true && docker-compose -f docker/docker-compose.yml up -d --build
Or create an alias in your shell:
alias publish-prod='./scripts/publish-all.sh && cd ~/homelab/fct_stats && mkdir -p data/db && mv data/fct_stats.db data/db/fct_stats.db 2>/dev/null || true && docker-compose -f docker/docker-compose.yml up -d --build'
Then just run: publish-prod
Publishing Options
Option 1: Publish Everything (Recommended)
Use this when you've made changes to both code and data.
./scripts/publish-all.sh
What it does:
- Syncs webapp code to
~/homelab/fct_stats/(excluding development files) - Backs up existing database to
~/homelab/fct_stats/backups/ - Copies new database from
data/db/fct_stats.dbto homelab - Shows database statistics
Then restart the server:
cd ~/homelab/fct_stats
mkdir -p data/db
mv data/fct_stats.db data/db/fct_stats.db 2>/dev/null || true
docker-compose -f docker/docker-compose.yml up -d --build
Or use the restart script:
./scripts/homelab-restart.sh
Option 2: Publish Only Webapp
Use this when you've made code/template/styling changes but no database changes.
./scripts/publish-webapp.sh
What it does:
- Syncs webapp files using rsync
- Excludes: venv, pycache, .git, data/db/, data/sources//pages/, data/sources/
Then restart the webapp container:
./scripts/homelab-restart.sh
Or manually:
cd ~/homelab/fct_stats
docker-compose -f docker/docker-compose.yml restart webapp
Option 3: Publish Only Database
Use this when you've added new meet results or updated data but code is unchanged.
./scripts/publish-db.sh
What it does:
- Creates backup:
~/homelab/fct_stats/backups/fct_stats_YYYYMMDD_HHMMSS.db - Copies
data/db/fct_stats.dbto~/homelab/fct_stats/data/db/ - Shows statistics (athletes, events, meets, results counts)
Then restart the webapp container:
./scripts/homelab-restart.sh
Or manually:
cd ~/homelab/fct_stats
docker-compose -f docker/docker-compose.yml restart webapp
Option 4: Just Restart the Production Server
Use this to restart the server without publishing any changes.
./scripts/homelab-restart.sh
What it does:
- Stops existing services
- Rebuilds and starts fresh containers
- Shows confirmation
Or manually:
cd ~/homelab/fct_stats
docker-compose -f docker/docker-compose.yml down
docker-compose -f docker/docker-compose.yml up -d --build
Step-by-Step Publishing Workflow
For a Typical Update (New Meet Results Added)
-
Ensure database is up to date:
python scripts/import_from_parsed_meets.py -
Verify locally:
cd webapp python app.py # Visit http://localhost:5000 and check changes -
Publish everything:
./scripts/publish-all.sh -
Restart production services:
cd ~/homelab/fct_stats docker-compose -f docker/docker-compose.yml up -d --build -
Check logs for errors:
docker-compose -f docker/docker-compose.yml logs -f webapp -
Visit production site:
For Code-Only Changes (Templates, Styling, Routes)
-
Test locally:
cd webapp python app.py -
Publish webapp only:
./scripts/publish-webapp.sh -
Restart webapp container:
cd ~/homelab/fct_stats docker-compose -f docker/docker-compose.yml restart webapp
For Data-Only Changes (New Results, Updated Records)
-
Import new data:
python scripts/import_from_parsed_meets.py -
Publish database only:
./scripts/publish-db.sh -
Restart webapp container:
cd ~/homelab/fct_stats docker-compose -f docker/docker-compose.yml restart webapp
Important Notes
Database Backups
- Automatic backups are created in
~/homelab/fct_stats/backups/ - Format:
fct_stats_YYYYMMDD_HHMMSS.db - These backups are important! The database is read-only in production
What Gets Excluded During Webapp Sync
The rsync excludes:
venv/- Virtual environments__pycache__/- Python bytecode*.pyc- Compiled Python files.git/- Git repositorydata/db/- Database (published separately)data/sources/<year>/pages/- Raw meet pages (not needed in production)data/sources/- YAML meet files (not needed in production).vscode/- Editor config*.log- Log files
Production Environment
- Location:
~/homelab/fct_stats/ - Docker Compose:
docker/docker-compose.yml - URL: https://track.fchsrunning.org
- Container Name:
fct_stats_webapp - Network:
proxy-network(shared with nginx proxy) - Database: Mounted read-only from
../data/db/fct_stats.db
Troubleshooting
Site Not Updating After Publish
-
Check if services are running:
cd ~/homelab/fct_stats docker-compose -f docker/docker-compose.yml ps -
Rebuild containers:
docker-compose -f docker/docker-compose.yml up -d --build -
Check logs:
docker-compose -f docker/docker-compose.yml logs -f webapp
Database Not Found Error
-
Verify database is in correct location:
ls -lh ~/homelab/fct_stats/data/db/fct_stats.dbIf the database is at
~/homelab/fct_stats/data/fct_stats.db, move it:mkdir -p ~/homelab/fct_stats/data/db mv ~/homelab/fct_stats/data/fct_stats.db ~/homelab/fct_stats/data/db/fct_stats.db -
Check database permissions:
chmod 644 ~/homelab/fct_stats/data/db/fct_stats.db -
Verify database is valid:
sqlite3 ~/homelab/fct_stats/data/db/fct_stats.db "SELECT COUNT(*) FROM athletes;" -
Restart the container:
cd ~/homelab/fct_stats docker-compose -f docker/docker-compose.yml restart webapp
Container Won't Start
-
Check for port conflicts:
docker-compose -f docker/docker-compose.yml ps netstat -tulpn | grep 5000 -
Remove old containers:
docker-compose -f docker/docker-compose.yml down docker-compose -f docker/docker-compose.yml up -d -
Check Docker logs:
docker logs fct_stats_webapp
Quick Reference Commands
# QUICK START: Publish everything and restart (recommended)
./scripts/publish-all.sh && cd ~/homelab/fct_stats && mkdir -p data/db && mv data/fct_stats.db data/db/fct_stats.db 2>/dev/null || true && docker-compose -f docker/docker-compose.yml up -d --build
# Or use the dedicated script
./scripts/homelab-restart.sh
# Publish everything only (without restart)
./scripts/publish-all.sh
# Publish webapp only
./scripts/publish-webapp.sh
# Publish database only
./scripts/publish-db.sh
# Restart services (after publishing separately)
./scripts/homelab-restart.sh
# Manual restart without publish
cd ~/homelab/fct_stats
docker-compose -f docker/docker-compose.yml up -d --build
# Restart just the webapp container
docker-compose -f docker/docker-compose.yml restart webapp
# Stop services
docker-compose -f docker/docker-compose.yml down
# View logs
docker-compose -f docker/docker-compose.yml logs -f
# Check status
docker-compose -f docker/docker-compose.yml ps
Pre-Publish Checklist
- Local changes tested with
cd webapp && python app.py - Database imported with latest data:
python scripts/import_from_parsed_meets.py - No errors in local testing
- Git committed (optional but recommended)
- Ready to run appropriate publish script
Post-Publish Verification
- Services started:
docker-compose psshows "Up" - No errors in logs:
docker-compose logs webapp - Production site accessible: https://track.fchsrunning.org
- New data/changes visible on production site
- Database backup created (if db was published)