From 116fa2bdfb236a19f4cfd4da94bb0bbc3673bd37 Mon Sep 17 00:00:00 2001 From: Chandler Copeland Date: Fri, 3 Apr 2026 18:36:51 -0600 Subject: [PATCH] chore: add start.sh and seed-forms.sh deployment scripts --- teressa-copeland-homes/seed-forms.sh | 27 +++++++ teressa-copeland-homes/start.sh | 103 +++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100755 teressa-copeland-homes/seed-forms.sh create mode 100755 teressa-copeland-homes/start.sh diff --git a/teressa-copeland-homes/seed-forms.sh b/teressa-copeland-homes/seed-forms.sh new file mode 100755 index 0000000..c30b4ff --- /dev/null +++ b/teressa-copeland-homes/seed-forms.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# ============================================================ +# Re-seed the forms library after adding new PDFs. +# Drop PDFs into seeds/forms/ then run: ./seed-forms.sh +# ============================================================ + +set -e +cd "$(dirname "$0")" + +GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m' + +FORMS_COUNT=$(ls seeds/forms/*.pdf 2>/dev/null | wc -l | tr -d ' ') +if [ "$FORMS_COUNT" -eq 0 ]; then + echo -e "${YELLOW}No PDF files found in seeds/forms/ — nothing to seed.${NC}" + exit 0 +fi + +echo -e "${GREEN}▶ Seeding $FORMS_COUNT forms into database...${NC}" +DATABASE_URL="postgresql://postgres:postgres@localhost:5433/teressa" \ + npx tsx scripts/seed-forms.ts 2>&1 | tail -2 + +echo -e "${GREEN}▶ Copying forms into container...${NC}" +docker compose exec app mkdir -p /app/seeds/forms 2>/dev/null || true +docker cp seeds/forms/. "$(docker compose ps -q app)":/app/seeds/forms/ +docker compose exec app chown -R nextjs:nodejs /app/seeds/forms/ 2>/dev/null || true + +echo -e "${GREEN}✓ Done — forms available in the app.${NC}" diff --git a/teressa-copeland-homes/start.sh b/teressa-copeland-homes/start.sh new file mode 100755 index 0000000..014e057 --- /dev/null +++ b/teressa-copeland-homes/start.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# ============================================================ +# Teressa Copeland Homes — Start Script +# Run from the teressa-copeland-homes/ directory: +# chmod +x start.sh (first time only) +# ./start.sh +# ============================================================ + +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR" + +# ── Helpers ────────────────────────────────────────────────── +GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m' +info() { echo -e "${GREEN}▶ $1${NC}"; } +warn() { echo -e "${YELLOW}⚠ $1${NC}"; } +error() { echo -e "${RED}✗ $1${NC}"; exit 1; } + +# ── 1. Check prerequisites ──────────────────────────────────── +command -v docker >/dev/null 2>&1 || error "Docker not found. Install Docker Desktop first." +command -v docker compose >/dev/null 2>&1 || error "docker compose not found. Update Docker Desktop." + +# ── 2. Check .env.production exists ────────────────────────── +if [ ! -f ".env.production" ]; then + error ".env.production not found. Copy .env.production.example to .env.production and fill in your values." +fi + +# ── 3. Build the app image ──────────────────────────────────── +info "Building app image (this takes ~2 min on first run)..." +docker compose build app + +# ── 4. Start everything ─────────────────────────────────────── +info "Starting database and app..." +docker compose up -d + +# ── 5. Wait for database to be healthy ─────────────────────── +info "Waiting for database..." +for i in $(seq 1 30); do + if docker compose exec db pg_isready -U postgres -q 2>/dev/null; then + break + fi + sleep 1 +done + +# ── 6. Run migrations ───────────────────────────────────────── +info "Running database migrations..." +DATABASE_URL="postgresql://postgres:postgres@localhost:5433/teressa" \ + npx drizzle-kit migrate 2>&1 | tail -3 + +# ── 7. Seed agent account (safe to re-run — skips if exists) ── +info "Seeding agent account..." +DATABASE_URL="postgresql://postgres:postgres@localhost:5433/teressa" \ +AGENT_EMAIL="teressa@tcopelandhomes.com" \ +AGENT_PASSWORD="AgentPortal2024!" \ + npx tsx scripts/seed.ts 2>&1 | tail -3 + +# ── 8. Seed forms library ───────────────────────────────────── +FORMS_COUNT=$(ls seeds/forms/*.pdf 2>/dev/null | wc -l | tr -d ' ') +if [ "$FORMS_COUNT" -gt 0 ]; then + info "Seeding $FORMS_COUNT PDF forms into library..." + DATABASE_URL="postgresql://postgres:postgres@localhost:5433/teressa" \ + npx tsx scripts/seed-forms.ts 2>&1 | tail -2 + + info "Copying forms into container..." + docker compose exec app mkdir -p /app/seeds/forms 2>/dev/null || true + docker cp seeds/forms/. "$(docker compose ps -q app)":/app/seeds/forms/ + docker compose exec app chown -R nextjs:nodejs /app/seeds/forms/ 2>/dev/null || true +else + warn "No PDF forms found in seeds/forms/ — skipping forms seed." + warn "See below for how to add your forms." +fi + +# ── 9. Health check ─────────────────────────────────────────── +info "Checking app health..." +sleep 3 +HEALTH=$(curl -s http://localhost:3001/api/health 2>/dev/null || echo "unreachable") +if echo "$HEALTH" | grep -q '"ok":true'; then + echo "" + echo -e "${GREEN}════════════════════════════════════════${NC}" + echo -e "${GREEN} ✓ App is running!${NC}" + echo -e "${GREEN} Open: http://localhost:3001/agent/login${NC}" + echo -e "${GREEN} Email: teressa@tcopelandhomes.com${NC}" + echo -e "${GREEN} Password: AgentPortal2024!${NC}" + echo -e "${GREEN}════════════════════════════════════════${NC}" + echo "" +else + warn "Health check inconclusive (app may still be starting). Try: http://localhost:3001/api/health" +fi + +# ── 10. Where to put forms ──────────────────────────────────── +echo "" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " 📄 ADDING PDF FORMS TO THE LIBRARY" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " Drop PDF files into:" +echo " teressa-copeland-homes/seeds/forms/" +echo "" +echo " Then run:" +echo " ./seed-forms.sh" +echo " (or just re-run ./start.sh)" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo ""