# Pre-Deployment Checklist for Screenshare Bot

**Purpose**: Comprehensive checklist to ensure all prerequisites are met before deploying to Railway.

**Status**: Use this checklist before every production deployment.

---

## Table of Contents

1. [Environment Preparation](#environment-preparation)
2. [Technical Validation](#technical-validation)
3. [Documentation Review](#documentation-review)
4. [Rollback Preparation](#rollback-preparation)
5. [Deployment Readiness Sign-Off](#deployment-readiness-sign-off)

---

## Environment Preparation

### Railway Project Access

- [ ] Railway account access confirmed
- [ ] Project `slide-system` accessible in Railway dashboard
- [ ] Railway CLI installed (`npm install -g @railway/cli`)
- [ ] Railway CLI authenticated (`railway login`)
- [ ] Railway CLI linked to project (`railway link`)

**Verification**:
```bash
railway status --service slide-system
# Should show: Status: RUNNING (or similar)
```

---

### API Keys and Credentials

All required API keys must be available and valid:

- [ ] **PIPECAT_API_KEY** - Pipecat API key obtained from dashboard
- [ ] **DAILY_PIPECAT_API_KEY** - Daily.co Pipecat integration key
- [ ] **DAILY_API_KEY** - Daily.co API key for room management
- [ ] **SUPABASE_URL** - Supabase project URL (format: `https://xxx.supabase.co`)
- [ ] **SUPABASE_SERVICE_KEY** - Supabase service role key (starts with `eyJ`)

**Where to Get Keys**:
- Pipecat: https://dashboard.pipecat.ai (if applicable)
- Daily.co: https://dashboard.daily.co > Developers > API Keys
- Supabase: https://app.supabase.com > Project > Settings > API

**Verification**:
```bash
# Test Daily API key
curl -H "Authorization: Bearer $DAILY_API_KEY" https://api.daily.co/v1/rooms

# Test Supabase connection
curl -H "apikey: $SUPABASE_SERVICE_KEY" $SUPABASE_URL/rest/v1/
```

---

### Dockerfile Updated

- [ ] Dockerfile includes screenshare bot dependency installation
- [ ] Dockerfile includes Playwright browser installation
- [ ] Dockerfile installs from `pyproject.toml` (includes pipecat-ai)

**Required Dockerfile Sections** (from DOCKERFILE-VALIDATION.md):
```dockerfile
# Install Python bot dependencies (for Screenshare bot)
RUN cd bots/screenshare-bot && \
    python3 -m venv .venv && \
    uv pip install --python .venv/bin/python .

# Install Playwright browsers (Chromium for screenshot capture)
RUN cd bots/screenshare-bot && \
    .venv/bin/playwright install --with-deps chromium
```

**Verification**:
```bash
# Check Dockerfile contains required sections
grep -A 2 "screenshare-bot" /Users/lars/mycode/buzztrail/epic-pipecat-based-screenshare-bot/apps/slide-system/Dockerfile
```

---

### Code Quality

- [ ] All changes committed to git
- [ ] No uncommitted changes in working directory
- [ ] Code merged to `main` branch (or target deployment branch)
- [ ] Latest code pulled from remote (`git pull origin main`)
- [ ] Code reviewed and approved (if applicable)

**Verification**:
```bash
git status
# Expected: nothing to commit, working tree clean

git branch
# Expected: * main (or deployment branch)

git log --oneline -5
# Review recent commits
```

---

## Technical Validation

### Environment Variables in Railway

All required environment variables must be set in Railway:

- [ ] `PIPECAT_API_KEY` set in Railway
- [ ] `DAILY_PIPECAT_API_KEY` set in Railway
- [ ] `DAILY_API_KEY` set in Railway
- [ ] `SUPABASE_URL` set in Railway
- [ ] `SUPABASE_SERVICE_KEY` set in Railway

**Optional Variables** (with defaults):
- [ ] `BOT_TIMEOUT_MINUTES` (default: 30)
- [ ] `MAX_CONCURRENT_BOTS` (default: 5, recommend starting with 1)
- [ ] `FRAME_RATE` (default: 10)
- [ ] `LOG_LEVEL` (default: INFO)
- [ ] `DEBUG_MODE` (default: false)

**Verification**:
```bash
# Check variables are set
railway vars --service slide-system | grep -E "PIPECAT|DAILY|SUPABASE"

# Expected output (values redacted):
# PIPECAT_API_KEY=***
# DAILY_PIPECAT_API_KEY=***
# DAILY_API_KEY=***
# SUPABASE_URL=https://***
# SUPABASE_SERVICE_KEY=eyJ***
```

**Set Missing Variables**:
```bash
railway vars --service slide-system set PIPECAT_API_KEY=your_key_here
railway vars --service slide-system set DAILY_PIPECAT_API_KEY=your_key_here
railway vars --service slide-system set DAILY_API_KEY=your_key_here
railway vars --service slide-system set SUPABASE_URL=your_url_here
railway vars --service slide-system set SUPABASE_SERVICE_KEY=your_key_here
```

---

### Run Validation Script

- [ ] Environment validation script passes locally

**Run Script**:
```bash
cd /Users/lars/mycode/buzztrail/epic-pipecat-based-screenshare-bot/apps/slide-system/bots/screenshare-bot
python scripts/validate_railway_config.py

# Expected: All checks pass ✅
```

**If Script Fails**:
- Review error messages
- Fix missing dependencies or configuration
- Re-run until all checks pass

---

### Run Pre-Deployment Check Script

- [ ] Pre-deployment check script passes

**Run Script**:
```bash
cd /Users/lars/mycode/buzztrail/epic-pipecat-based-screenshare-bot/apps/slide-system/bots/screenshare-bot
./scripts/pre_deployment_check.sh

# Expected: All checks pass
```

**What This Script Validates**:
- Dockerfile correctness
- Environment variables presence
- Dependencies installation
- Python/Playwright availability
- Bot script executability

---

### Test Suite Passes

- [ ] All unit tests pass
- [ ] All integration tests pass (if applicable)
- [ ] No test failures or warnings

**Run Tests**:
```bash
cd /Users/lars/mycode/buzztrail/epic-pipecat-based-screenshare-bot/apps/slide-system/bots/screenshare-bot

# If using pytest
pytest tests/ -v

# If using unittest
python -m unittest discover -s tests -v

# Expected: All tests pass, 0 failures
```

---

### Dependencies Verified

- [ ] Python dependencies up to date (`requirements.txt` or `pyproject.toml`)
- [ ] All dependencies have pinned versions (for reproducibility)
- [ ] No security vulnerabilities in dependencies

**Verification**:
```bash
# Check for security vulnerabilities
cd /Users/lars/mycode/buzztrail/epic-pipecat-based-screenshare-bot/apps/slide-system/bots/screenshare-bot
pip install safety
safety check -r requirements.txt

# Or check pyproject.toml dependencies
pip-audit
```

---

## Documentation Review

### Operational Documentation

- [ ] **RUNBOOK.md** reviewed and up to date
- [ ] **DEPLOYMENT.md** reviewed and understood
- [ ] **MONITORING.md** reviewed and monitoring plan ready
- [ ] **RAILWAY-CONFIG.md** reviewed for Railway configuration

**Review Checklist**:
- Understand incident response procedures (RUNBOOK.md)
- Know deployment steps (DEPLOYMENT.md)
- Understand monitoring metrics (MONITORING.md)
- Railway configuration validated (RAILWAY-CONFIG.md)

**Documentation Locations**:
```
apps/slide-system/bots/screenshare-bot/
├── RUNBOOK.md           # Incident response
├── DEPLOYMENT.md        # Deployment procedures
├── MONITORING.md        # Monitoring guide
├── RAILWAY-CONFIG.md    # Railway configuration
├── DOCKERFILE-VALIDATION.md  # Dockerfile requirements
```

---

### Team Training

- [ ] Team members trained on bot operations
- [ ] On-call engineer briefed on deployment
- [ ] Incident response procedures reviewed
- [ ] Escalation path confirmed

**Training Topics**:
1. How to check bot status
2. How to spawn/kill bots manually
3. How to read Railway logs
4. How to identify common issues
5. When to rollback deployment

---

## Rollback Preparation

### Previous Deployment Noted

- [ ] Current production deployment ID recorded
- [ ] Previous deployment verified as stable

**Capture Current Deployment**:
```bash
# Get current deployment ID
railway deployments --service slide-system | head -5

# Example output:
# ID              Status    Created             Branch
# dep-abc123      ACTIVE    2025-10-12 10:00    main
# dep-xyz789      SUCCESS   2025-10-11 14:00    main

# Record ACTIVE deployment ID for rollback if needed
export ROLLBACK_DEPLOYMENT_ID=dep-abc123
echo "Rollback target: $ROLLBACK_DEPLOYMENT_ID"
```

- [ ] Rollback deployment ID saved: `________________`

---

### Rollback Procedure Documented

- [ ] Rollback procedure reviewed and understood
- [ ] Rollback can be executed in < 5 minutes
- [ ] Team knows who can authorize rollback

**Quick Rollback Command** (for reference):
```bash
# Emergency rollback
railway rollback --service slide-system $ROLLBACK_DEPLOYMENT_ID

# Verify rollback
railway status --service slide-system
railway logs --service slide-system --tail
```

---

### Emergency Contacts Confirmed

- [ ] On-call engineer contact information current
- [ ] Team Slack/Discord channels active (#ops-alerts)
- [ ] Escalation contacts available

**Emergency Contact List**:
```
On-Call Engineer: ________________
Team Lead: ________________
DevOps Lead: ________________

Channels:
- #ops-alerts (Slack/Discord)
- #engineering
- Emergency phone: ________________
```

---

## Deployment Readiness Sign-Off

### Final Checks

- [ ] All sections above completed
- [ ] No blocking issues identified
- [ ] Deployment window scheduled
- [ ] Stakeholders notified of deployment

**Deployment Window**:
- Date: `________________`
- Time: `________________`
- Duration: `________________`
- Backup window: `________________`

---

### Decision Gates

**Proceed with Deployment if**:
- ✅ All checklist items marked complete
- ✅ All validation scripts pass
- ✅ All tests pass
- ✅ Documentation reviewed
- ✅ Rollback plan ready

**DO NOT Deploy if**:
- ❌ Any critical checklist item incomplete
- ❌ Validation scripts fail
- ❌ Tests failing
- ❌ Dockerfile not updated
- ❌ Environment variables missing
- ❌ Rollback plan not ready

---

### Sign-Off

**Deployment Authorized By**:

- Deployer Name: `________________`
- Signature/Approval: `________________`
- Date/Time: `________________`

**On-Call Engineer Acknowledgment**:

- Engineer Name: `________________`
- Acknowledgment: `________________`
- Date/Time: `________________`

---

## Post-Deployment Actions

After deployment completes:

1. [ ] Run smoke tests (see PRODUCTION-VALIDATION.md)
2. [ ] Monitor Railway dashboard for 30 minutes
3. [ ] Check logs for errors
4. [ ] Verify bot spawn works
5. [ ] Update deployment log
6. [ ] Notify team of successful deployment

**Deployment Log Entry**:
```
Deployment ID: ________________
Date: ________________
Status: [ ] Success  [ ] Failed  [ ] Rolled Back
Notes: ________________________________________________
```

---

## Quick Reference Commands

```bash
# Check Railway status
railway status --service slide-system

# View environment variables
railway vars --service slide-system

# Run validation
python scripts/validate_railway_config.py

# Run pre-deployment check
./scripts/pre_deployment_check.sh

# Deploy to Railway
git push origin main  # If auto-deploy enabled
# OR
railway up --service slide-system  # Manual deploy

# Monitor deployment
railway logs --service slide-system --tail

# Rollback if needed
railway rollback --service slide-system $ROLLBACK_DEPLOYMENT_ID
```

---

## Appendix: Common Pre-Deployment Issues

### Issue: Dockerfile Missing Screenshare Bot Installation

**Symptom**: Pre-deployment check fails with "Screenshare bot not found in Dockerfile"

**Fix**: Update Dockerfile with required RUN commands (see DOCKERFILE-VALIDATION.md)

---

### Issue: Missing Environment Variables

**Symptom**: Validation script reports missing env vars

**Fix**: Set all required variables in Railway dashboard or CLI

---

### Issue: Playwright Browser Not Found

**Symptom**: "Chromium executable not found" error

**Fix**: Ensure Dockerfile includes `playwright install --with-deps chromium`

---

### Issue: Import Errors (pipecat, daily, etc.)

**Symptom**: "ModuleNotFoundError: No module named 'pipecat'"

**Fix**: Ensure Dockerfile installs from `pyproject.toml` using `uv pip install .`

---

**Document Version**: 1.0
**Last Updated**: 2025-10-12
**Owner**: Stream C - Production Validation & Rollout
**Related Documents**: DOCKERFILE-VALIDATION.md, RAILWAY-CONFIG.md, DEPLOYMENT.md, RUNBOOK.md
