Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.
Feature/fly demo (#6)
Carter64c440efba19
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 0c91e91..1676469 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -1,40 +1,98 @@# Contributing to Lyftr-Bug reports, feature requests, and pull requests are welcome. Here's how to get involved without wasting your time or mine.+Bug reports, feature requests, and pull requests are welcome. Open an issue before submitting large changes.-## Reporting bugs+---++## Branch Naming++| Prefix | Use for | Example |+|--------|---------|---------|+| `feature/` | New functionality | `feature/csv-import` |+| `bugfix/` | Non-urgent bug fixes | `bugfix/weight-unit-display` |+| `hotfix/` | Urgent production fixes — branch off `main` directly | `hotfix/auth-token-expiry` |+| `chore/` | Deps, tooling, CI, config — no behavior change | `chore/bump-go-1.27` |+| `docs/` | Documentation only | `docs/vps-setup-guide` |+| `release/` | Version bump + changelog prep | `release/v0.2.0` |++Lowercase, hyphen-separated, specific enough to be self-explanatory.++---++## Workflow++```bash+# Start from an up-to-date main+git checkout main && git pull --rebase+git checkout -b feature/your-feature++# Work, commit, push+git push -u origin feature/your-feature++# Open a PR against main+```++Rebase against main before opening a PR if the branch has been open a while:++```bash+git fetch origin+git rebase origin/main+```++---++## Commit Messages++Follow conventional commits:++```+feat(scope): short description+fix(scope): short description+chore(scope): short description+docs(scope): short description+```++Examples:+- `feat(weight): add CSV export`+- `fix(auth): handle expired refresh token`+- `chore(deps): bump Go to 1.27`++---++## Reporting BugsUse the [bug report template](.github/ISSUE_TEMPLATE/bug_report.md). Include logs. Don't skip steps to reproduce.-## Requesting features+## Requesting FeaturesUse the [feature request template](.github/ISSUE_TEMPLATE/feature_request.md). Explain the problem first, not just the solution.-## Submitting a pull request+----1. Open an issue first for anything non-trivial — alignment before code saves everyone time-2. Fork the repo and create a branch: `git checkout -b feat/your-thing`-3. Keep changes focused. One feature or fix per PR-4. Test it locally before opening the PR+## Code Standards-## Local development+- **Backend:** `gofmt` before committing. Errors wrapped with context. No unnecessary abstractions.+- **Frontend:** Follow existing patterns. No new npm dependencies without discussion.+- **Tests:** Go controller tests and Playwright E2E must pass before any PR.```bash-# Backend (Go, runs on :3000)-cd backend && go run main.go+# Backend+cd backend && go test ./controllers/ -timeout 30s-# Frontend (React + Vite, runs on :5173)-cd web && npm install && npm run dev+# Frontend E2E (requires backend on :3000 and frontend on :5173)+cd web && npm run test:e2e```-See the [README](README.md) for full setup instructions.+Never commit with failing tests. Fix root cause — don't skip or comment out.++----## Code style+## Pull Requests-- Go: standard `gofmt` formatting-- TypeScript/React: existing patterns in the codebase — no new dependencies without discussion-- No half-finished features. If it's not ready, keep it on a branch+- One feature or fix per PR — focused diffs only+- Reference the related issue if one exists+- PRs without passing tests will not be merged## Questions?-Open a [discussion](../../discussions) or an issue. Happy to help.+Open a [discussion](../../discussions) or an issue.diff --git a/README.md b/README.mdindex aa50447..901fa9b 100644--- a/README.md+++ b/README.md@@ -25,7 +25,7 @@> **Early beta** — actively being built. Expect rough edges and frequent updates. Issues and feedback are welcome. The software equivalent of going to the gym for the first time.-> 🌐 **Live demo coming soon** — try it without spinning up Docker.+> 🌐 **[Live demo → lyftr-demo.fly.dev](https://lyftr-demo.fly.dev)** — log in with `[email protected]` / `password123`. Shared instance, resets every hour.---@@ -71,6 +71,21 @@ Lyftr is for people who want a modern, mobile-first workout tracker that they fu---+## Live Demo++**[lyftr-demo.fly.dev](https://lyftr-demo.fly.dev)**++| Field | Value |+|-------|-------|+| Email | `[email protected]` |+| Password | `password123` |++Pre-loaded with 8 weeks of PPL workouts, 90 days of weight logs, and food logs so every page has data to explore. Shared instance — resets automatically every hour so any changes are wiped clean.++Or **register your own account** on the demo — your data persists until the next hourly reset, and nobody else can see it.++---+## Quick Start> No clone. No build. No Go install required. Just Docker.diff --git a/backend/main.go b/backend/main.goindex 690dadc..910758c 100644--- a/backend/main.go+++ b/backend/main.go@@ -15,6 +15,7 @@ func main() {db.Connect()seed.DemoUser(db.DB)seed.Exercises(db.DB)+ go seed.DemoData(db.DB)if config.C.Env == "production" {gin.SetMode(gin.ReleaseMode)diff --git a/backend/seed/demo_data.go b/backend/seed/demo_data.gonew file mode 100644index 0000000..d8d622a--- /dev/null+++ b/backend/seed/demo_data.go@@ -0,0 +1,320 @@+package seed++import (+ "database/sql"+ "fmt"+ "log"+ "math/rand"+ "time"+)++type demoEx struct {+ patterns []string // LIKE patterns tried in order+ sets int+ reps int+ baseWeight float64 // lbs, week 1+ peakWeight float64 // lbs, week 8+}++var pushA = []demoEx{+ {[]string{"%bench press%medium%", "%barbell bench press%", "%bench press%"}, 4, 5, 135, 160},+ {[]string{"%barbell shoulder press%", "%military press%", "%overhead press%"}, 3, 8, 95, 115},+ {[]string{"%incline%barbell%press%", "%incline%press%"}, 3, 8, 105, 125},+ {[]string{"%tricep%pushdown%", "%triceps pushdown%", "%pushdown%"}, 3, 12, 50, 65},+ {[]string{"%lateral raise%"}, 3, 15, 20, 30},+}++var pullA = []demoEx{+ {[]string{"%barbell deadlift%", "%deadlift%"}, 3, 5, 225, 275},+ {[]string{"%bent over%row%", "%barbell row%"}, 4, 8, 135, 165},+ {[]string{"%lat pulldown%"}, 3, 10, 120, 150},+ {[]string{"%face pull%"}, 3, 15, 40, 55},+ {[]string{"%barbell curl%", "%standing barbell curl%", "%curl%"}, 3, 10, 65, 85},+}++var legsA = []demoEx{+ {[]string{"%barbell squat%", "%back squat%", "%squat%"}, 4, 5, 185, 225},+ {[]string{"%romanian deadlift%"}, 3, 8, 135, 165},+ {[]string{"%leg press%"}, 3, 12, 270, 360},+ {[]string{"%leg curl%", "%lying leg curl%"}, 3, 12, 90, 120},+ {[]string{"%standing calf%", "%calf raise%"}, 4, 15, 135, 175},+}++var pushB = []demoEx{+ {[]string{"%incline%dumbbell%press%", "%incline%press%"}, 4, 8, 65, 80},+ {[]string{"%dumbbell shoulder press%", "%seated dumbbell press%", "%dumbbell press%"}, 3, 10, 45, 60},+ {[]string{"%cable fly%", "%chest fly%", "%pec deck%"}, 3, 12, 60, 80},+ {[]string{"%skull crusher%", "%lying tricep%", "%ez-bar tricep%"}, 3, 10, 60, 80},+ {[]string{"%dumbbell lateral raise%", "%lateral raise%"}, 3, 15, 20, 30},+}++var pullB = []demoEx{+ {[]string{"%sumo deadlift%", "%romanian deadlift%"}, 3, 6, 205, 245},+ {[]string{"%seated cable row%", "%cable row%", "%seated row%"}, 4, 10, 120, 150},+ {[]string{"%pull-up%", "%pullup%", "%chin-up%"}, 3, 6, 0, 0},+ {[]string{"%reverse fly%", "%bent over reverse%", "%rear delt%"}, 3, 15, 25, 35},+ {[]string{"%hammer curl%", "%dumbbell hammer curl%"}, 3, 10, 35, 50},+}++var legsB = []demoEx{+ {[]string{"%front squat%", "%hack squat%", "%goblet squat%"}, 4, 6, 135, 165},+ {[]string{"%good morning%"}, 3, 10, 95, 115},+ {[]string{"%walking lunge%", "%lunge%"}, 3, 12, 50, 70},+ {[]string{"%seated leg curl%", "%leg curl%"}, 3, 12, 80, 105},+ {[]string{"%seated calf%", "%calf raise%"}, 4, 15, 90, 120},+}++// weekSchedule maps day-of-week (0=Sun) to workout template index.+// -1 = rest. 0=PushA 1=PullA 2=LegsA 3=PushB 4=PullB 5=LegsB+var weekSchedule = map[time.Weekday]int{+ time.Monday: 0,+ time.Tuesday: 1,+ time.Wednesday: 2,+ time.Thursday: 3,+ time.Friday: 4,+ time.Saturday: 5,+ time.Sunday: -1,+}++var workoutNames = []string{"Push A", "Pull A", "Legs A", "Push B", "Pull B", "Legs B"}+var workoutDurations = []int{3720, 3480, 4200, 3660, 3540, 4320}+var workoutTemplates = [][]demoEx{pushA, pullA, legsA, pushB, pullB, legsB}++func DemoData(db *sql.DB) {+ // Wait for exercises to be seeded (up to 90s)+ var exCount int+ for i := 0; i < 18; i++ {+ db.QueryRow(`SELECT COUNT(*) FROM exercises`).Scan(&exCount)+ if exCount >= 100 {+ break+ }+ log.Printf("seed: demo data waiting for exercises... (%d/18)", i+1)+ time.Sleep(5 * time.Second)+ }+ if exCount < 100 {+ log.Println("seed: exercises not ready, skipping demo data")+ return+ }++ var userID int64+ if err := db.QueryRow(`SELECT id FROM users WHERE email = ?`, "[email protected]").Scan(&userID); err != nil {+ log.Printf("seed: demo user not found: %v", err)+ return+ }++ // Idempotency check+ var wCount int+ db.QueryRow(`SELECT COUNT(*) FROM workouts WHERE user_id = ?`, userID).Scan(&wCount)+ if wCount > 0 {+ return+ }++ if err := seedProgram(db, userID); err != nil {+ log.Printf("seed: program: %v", err)+ }+ if err := seedWorkouts(db, userID); err != nil {+ log.Printf("seed: workouts: %v", err)+ }+ seedWeightLogs(db, userID)+ seedFoodLogs(db, userID)+ log.Println("seed: demo data complete")+}++func lookupExercise(db *sql.DB, patterns []string) (int64, bool) {+ for _, p := range patterns {+ var id int64+ err := db.QueryRow(`SELECT id FROM exercises WHERE LOWER(name) LIKE ? LIMIT 1`, p).Scan(&id)+ if err == nil {+ return id, true+ }+ }+ return 0, false+}++func seedProgram(db *sql.DB, userID int64) error {+ res, err := db.Exec(`INSERT INTO programs (user_id, name, notes) VALUES (?, ?, ?)`,+ userID, "PPL — Push Pull Legs", "Classic 6-day PPL split for strength and hypertrophy.")+ if err != nil {+ return err+ }+ progID, _ := res.LastInsertId()++ for dayIdx, template := range workoutTemplates {+ for exOrder, exDef := range template {+ exID, ok := lookupExercise(db, exDef.patterns)+ if !ok {+ continue+ }+ pexRes, err := db.Exec(+ `INSERT INTO program_exercises (program_id, exercise_id, order_index) VALUES (?, ?, ?)`,+ progID, exID, exOrder,+ )+ if err != nil {+ continue+ }+ pexID, _ := pexRes.LastInsertId()+ for s := 1; s <= exDef.sets; s++ {+ db.Exec(+ `INSERT INTO program_sets (program_exercise_id, set_number, target_reps, target_weight) VALUES (?, ?, ?, ?)`,+ pexID, s, exDef.reps, exDef.peakWeight,+ )+ }+ _ = dayIdx+ }+ }+ return nil+}++func seedWorkouts(db *sql.DB, userID int64) error {+ rng := rand.New(rand.NewSource(42))+ now := time.Now()+ // 8 weeks of workouts ending 3 days ago+ startDay := now.AddDate(0, 0, -59)++ sessionCount := [6]int{} // counts per template type++ for d := 0; d <= 56; d++ {+ day := startDay.AddDate(0, 0, d)+ if day.After(now.AddDate(0, 0, -3)) {+ break+ }++ tmplIdx, ok := weekSchedule[day.Weekday()]+ if !ok || tmplIdx < 0 {+ continue+ }++ template := workoutTemplates[tmplIdx]+ sessionNum := sessionCount[tmplIdx]+ sessionCount[tmplIdx]++++ // Linear progression: 0.0 (session 0) → 1.0 (session 7)+ progress := float64(sessionNum) / 7.0+ if progress > 1 {+ progress = 1+ }++ startedAt := time.Date(day.Year(), day.Month(), day.Day(),+ 17+rng.Intn(3), rng.Intn(60), 0, 0, time.UTC)++ res, err := db.Exec(+ `INSERT INTO workouts (user_id, name, notes, duration, started_at) VALUES (?, ?, ?, ?, ?)`,+ userID,+ workoutNames[tmplIdx],+ "",+ workoutDurations[tmplIdx]+rng.Intn(600)-300,+ startedAt.Format("2006-01-02T15:04:05Z"),+ )+ if err != nil {+ return fmt.Errorf("workout insert: %w", err)+ }+ workoutID, _ := res.LastInsertId()++ for exOrder, exDef := range template {+ exID, ok := lookupExercise(db, exDef.patterns)+ if !ok {+ continue+ }+ wexRes, err := db.Exec(+ `INSERT INTO workout_exercises (workout_id, exercise_id, order_index) VALUES (?, ?, ?)`,+ workoutID, exID, exOrder,+ )+ if err != nil {+ continue+ }+ wexID, _ := wexRes.LastInsertId()++ w := exDef.baseWeight + (exDef.peakWeight-exDef.baseWeight)*progress+ // Snap to nearest 5 lbs plate increment+ w = float64(int(w/5+0.5)) * 5+ // Bodyweight exercises+ if exDef.baseWeight == 0 {+ w = 0+ }++ for s := 1; s <= exDef.sets; s++ {+ reps := exDef.reps+ // Last set occasionally one rep short (fatigue)+ if s == exDef.sets && rng.Intn(4) == 0 {+ reps--+ }+ db.Exec(+ `INSERT INTO sets (workout_exercise_id, set_number, reps, weight) VALUES (?, ?, ?, ?)`,+ wexID, s, reps, w,+ )+ }+ }+ }+ return nil+}++func seedWeightLogs(db *sql.DB, userID int64) {+ rng := rand.New(rand.NewSource(99))+ now := time.Now()+ // 90 days, ~185 lbs trending down to ~173 lbs+ startWeight := 185.0+ endWeight := 173.0++ for d := 89; d >= 0; d-- {+ // Skip ~18% of days (missed weigh-ins)+ if rng.Intn(100) < 18 {+ continue+ }+ day := now.AddDate(0, 0, -d)+ progress := float64(89-d) / 89.0+ w := startWeight + (endWeight-startWeight)*progress+ // Daily noise ±1.5 lbs+ w += (rng.Float64()*3 - 1.5)+ loggedAt := time.Date(day.Year(), day.Month(), day.Day(), 7, 30, 0, 0, time.UTC)+ db.Exec(+ `INSERT INTO weight_logs (user_id, weight, notes, logged_at) VALUES (?, ?, ?, ?)`,+ userID, fmt.Sprintf("%.1f", w), "", loggedAt.Format("2006-01-02T15:04:05Z"),+ )+ }+}++type mealRow struct {+ meal string+ name string+ calories float64+ protein float64+ carbs float64+ fat float64+}++var mealPatterns = [][]mealRow{+ {+ {"breakfast", "Eggs, oats and banana", 520, 38, 62, 12},+ {"lunch", "Chicken breast with rice and broccoli", 640, 55, 70, 8},+ {"dinner", "Salmon fillet with sweet potato and asparagus", 590, 48, 48, 16},+ {"snacks", "Greek yogurt and protein shake", 370, 52, 28, 6},+ },+ {+ {"breakfast", "Protein oats with blueberries", 490, 35, 65, 9},+ {"lunch", "Turkey and avocado wrap", 610, 46, 58, 18},+ {"dinner", "Lean ground beef with pasta and marinara", 680, 52, 72, 14},+ {"snacks", "Cottage cheese and almonds", 330, 38, 14, 16},+ },+ {+ {"breakfast", "Scrambled eggs with whole-wheat toast", 480, 34, 48, 15},+ {"lunch", "Tuna salad with quinoa", 570, 50, 52, 12},+ {"dinner", "Grilled chicken thighs with roasted veg", 620, 54, 38, 22},+ {"snacks", "Protein shake with banana", 340, 40, 40, 4},+ },+}++func seedFoodLogs(db *sql.DB, userID int64) {+ now := time.Now()+ for d := 6; d >= 0; d-- {+ day := now.AddDate(0, 0, -d)+ pattern := mealPatterns[d%len(mealPatterns)]+ for _, m := range pattern {+ loggedAt := time.Date(day.Year(), day.Month(), day.Day(), 12, 0, 0, 0, time.UTC)+ db.Exec(+ `INSERT INTO food_logs (user_id, name, meal, calories, protein, carbs, fat, logged_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,+ userID, m.name, m.meal, m.calories, m.protein, m.carbs, m.fat,+ loggedAt.Format("2006-01-02T15:04:05Z"),+ )+ }+ }+}diff --git a/fly.toml b/fly.tomlnew file mode 100644index 0000000..7fba3f8--- /dev/null+++ b/fly.toml@@ -0,0 +1,40 @@+# fly.toml — Lyftr demo instance+# Set app name below, then: fly secrets set JWT_SECRET=<random-32-chars>+# First deploy: fly deploy+# See fly/SETUP.md for full instructions.++app = "lyftr-demo"+primary_region = "fra"++[build]+ dockerfile = "fly/Dockerfile"++[env]+ ENV = "production"+ PORT = "3000"+ DB_PATH = "/app/data/lyftr.db"+ CORS_ORIGIN = "https://lyftr-demo.fly.dev"++# JWT_SECRET must be set as a secret:+# fly secrets set JWT_SECRET=$(openssl rand -hex 32)++[http_service]+ internal_port = 80+ force_https = true+ auto_stop_machines = false+ auto_start_machines = true+ min_machines_running = 1++ [http_service.concurrency]+ type = "connections"+ hard_limit = 100+ soft_limit = 80++[[mounts]]+ source = "lyftr_data"+ destination = "/app/data"++[[vm]]+ memory = "512mb"+ cpu_kind = "shared"+ cpus = 1diff --git a/fly/Dockerfile b/fly/Dockerfilenew file mode 100644index 0000000..14cb07e--- /dev/null+++ b/fly/Dockerfile@@ -0,0 +1,52 @@+# Lyftr demo — single-container build for Fly.io+#+# Architecture: nginx (port 80) serves the React SPA and proxies /api/ to+# the Go backend running on localhost:3000 inside the same container.+# A persistent Fly volume at /app/data holds the SQLite DB across deploys.+#+# Hourly demo reset: crond inside the container runs reset.sh every hour,+# which restores lyftr.db from a seed snapshot so the demo stays fresh.+# The seed snapshot is created manually on first deploy (see fly/SETUP.md).++# ── Stage 1: Frontend ────────────────────────────────────────────────────────+FROM --platform=$BUILDPLATFORM node:20-alpine AS frontend+WORKDIR /app+COPY web/package.json web/package-lock.json ./+RUN npm ci+COPY web/ .+RUN npm run build++# ── Stage 2: Backend ─────────────────────────────────────────────────────────+# CGO_ENABLED=0 produces a fully static binary — no libc dependency in runtime.+FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS backend+ARG TARGETOS TARGETARCH+WORKDIR /build+COPY backend/go.mod backend/go.sum ./+RUN go mod download+COPY backend/ .+RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \+ go build -ldflags="-s -w" -o lyftr-api .++# ── Stage 3: Runtime ─────────────────────────────────────────────────────────+FROM nginx:alpine+# ca-certificates: needed for Go TLS (exercise seed fetch from GitHub)+# wget: used in health checks if needed+RUN apk add --no-cache ca-certificates wget++COPY --from=backend /build/lyftr-api /app/lyftr-api+COPY --from=frontend /app/dist /usr/share/nginx/html++# Fly-specific nginx config: proxy_pass uses localhost:3000 (not :3000 service name)+COPY fly/nginx.fly.conf /etc/nginx/conf.d/default.conf++# sed strips Windows \r\n → \n so the #!/bin/sh shebang works on Linux+COPY fly/entrypoint.sh /app/entrypoint.sh+COPY fly/reset.sh /app/reset.sh+RUN sed -i 's/\r$//' /app/entrypoint.sh /app/reset.sh && chmod +x /app/entrypoint.sh /app/reset.sh++# /app/data is a Fly volume mount — this mkdir is a fallback for local testing+RUN mkdir -p /app/data++EXPOSE 80++ENTRYPOINT ["/app/entrypoint.sh"]diff --git a/fly/SETUP.md b/fly/SETUP.mdnew file mode 100644index 0000000..97f4c31--- /dev/null+++ b/fly/SETUP.md@@ -0,0 +1,91 @@+# Fly.io Demo Instance — Setup Guide++One-time setup for the public demo at `demo.lyftr.app` (or your chosen subdomain).++## Prerequisites++```bash+# Install flyctl+curl -L https://fly.io/install.sh | sh++# Log in+fly auth login+```++## 1. Create the app and volume++```bash+# From the project root+fly apps create lyftr-demo # or your preferred name+fly volumes create lyftr_data --app lyftr-demo --region fra --size 1+```++## 2. Set secrets++```bash+fly secrets set JWT_SECRET=$(openssl rand -hex 32) --app lyftr-demo+```++## 3. Update fly.toml++Edit `fly.toml` — set `app`, `CORS_ORIGIN` and `[env].CORS_ORIGIN` to your final URL+(e.g. `https://lyftr-demo.fly.dev` or `https://demo.lyftr.app`).++## 4. Deploy++```bash+fly deploy --app lyftr-demo+```++The first deploy will:+- Start the Go backend+- Seed the demo user (`[email protected]` / `password123`)+- Begin seeding 800+ exercises async (takes ~30s)+- `DemoData` goroutine waits for exercises then seeds 8 weeks of workouts,+ 90 days of weight logs, and 7 days of food logs automatically++## 5. Create the seed snapshot++Once exercises and demo data are fully seeded (~60s after first deploy):++```bash+fly ssh console --app lyftr-demo -C "cp /app/data/lyftr.db /app/data/lyftr.seed.db"+```++From this point the hourly cron (`reset.sh`) will restore this snapshot every hour,+keeping the demo clean regardless of what visitors do.++## 6. Custom domain (optional)++```bash+fly certs add demo.lyftr.app --app lyftr-demo+```++Then add a CNAME `demo.lyftr.app → lyftr-demo.fly.dev` in your DNS.+Update `CORS_ORIGIN` in `fly.toml` and redeploy.++## Ongoing operations++```bash+# Check logs+fly logs --app lyftr-demo++# Manual reset+fly ssh console --app lyftr-demo -C "/app/reset.sh"++# Redeploy after code changes+fly deploy --app lyftr-demo++# Update seed snapshot after improving demo data+fly ssh console --app lyftr-demo -C "cp /app/data/lyftr.db /app/data/lyftr.seed.db"+```++## Architecture++Single Fly machine running:+- **nginx** (port 80) — serves React SPA, proxies `/api/` → localhost:3000+- **Go backend** (port 3000) — in a restart loop (so reset.sh can kill and restart it)+- **crond** — runs `reset.sh` at the top of every hour++SQLite DB lives on a persistent Fly volume at `/app/data/lyftr.db`.+Seed snapshot lives alongside it at `/app/data/lyftr.seed.db`.diff --git a/fly/entrypoint.sh b/fly/entrypoint.shnew file mode 100644index 0000000..97ab8c7--- /dev/null+++ b/fly/entrypoint.sh@@ -0,0 +1,28 @@+#!/bin/sh+# entrypoint.sh — container init for the Lyftr demo on Fly.io+#+# Responsibilities:+# 1. Register hourly cron job to reset the demo DB (reset.sh)+# 2. Run the Go backend in a restart loop (reset.sh kills it; loop brings it back)+# 3. Start nginx as PID 1 (exec replaces this shell process)+set -e++# Register hourly reset: copies seed snapshot → live DB, then kills backend+# so the restart loop below picks it back up with fresh data.+mkdir -p /var/spool/cron/crontabs+echo "0 * * * * /app/reset.sh >> /var/log/reset.log 2>&1" > /var/spool/cron/crontabs/root+crond++# Restart loop: reset.sh uses pkill to stop lyftr-api; this loop restarts it.+# Running in background (&) so nginx can start as foreground PID 1.+while true; do+ echo "[lyftr] starting backend..."+ /app/lyftr-api || true+ echo "[lyftr] backend exited, restarting in 3s..."+ sleep 3+done &++# Brief pause so the backend is accepting connections before nginx gets traffic+sleep 2++exec nginx -g 'daemon off;'diff --git a/fly/nginx.fly.conf b/fly/nginx.fly.confnew file mode 100644index 0000000..0a9194a--- /dev/null+++ b/fly/nginx.fly.conf@@ -0,0 +1,42 @@+server {+ listen 80;+ server_name _;++ root /usr/share/nginx/html;+ index index.html;++ gzip on;+ gzip_vary on;+ gzip_min_length 1024;+ gzip_proxied any;+ gzip_types+ text/plain text/css text/javascript+ application/javascript application/json image/svg+xml;++ # API — proxy to local Go backend+ location /api/ {+ proxy_pass http://localhost:3000/api/;+ proxy_http_version 1.1;+ proxy_set_header Host $host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;+ proxy_set_header X-Forwarded-Proto $scheme;+ proxy_read_timeout 60s;+ }++ # Health check passthrough+ location /health {+ proxy_pass http://localhost:3000/health;+ }++ # SPA fallback+ location / {+ try_files $uri $uri/ /index.html;+ }++ location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {+ expires 1y;+ add_header Cache-Control "public, immutable";+ try_files $uri =404;+ }+}diff --git a/fly/reset.sh b/fly/reset.shnew file mode 100644index 0000000..2d3b04f--- /dev/null+++ b/fly/reset.sh@@ -0,0 +1,23 @@+#!/bin/sh+# reset.sh — hourly demo reset, invoked by crond inside the container+#+# Restores the live DB from a pre-seeded snapshot so the demo always shows+# realistic data. After the copy, pkill stops the backend; entrypoint.sh's+# restart loop brings it back with the fresh DB.+#+# The seed snapshot (lyftr.seed.db) is created once on first deploy:+# fly ssh console -a lyftr-demo+# cp /app/data/lyftr.db /app/data/lyftr.seed.db+SEED="/app/data/lyftr.seed.db"+LIVE="/app/data/lyftr.db"++if [ ! -f "$SEED" ]; then+ echo "[reset] $(date): no seed snapshot at $SEED — skipping"+ exit 0+fi++echo "[reset] $(date): restoring demo DB..."+cp "$SEED" "$LIVE"+# Kill backend so entrypoint restart loop picks up the fresh DB immediately+pkill lyftr-api 2>/dev/null || true+echo "[reset] $(date): done — backend will restart automatically"