A community based topic aggregation platform built on atproto
1#!/bin/bash
2# Coves Production Setup Script
3# Run this once on a fresh server to set up everything
4#
5# Prerequisites:
6# - Docker and docker-compose installed
7# - Git installed
8# - .env.prod file configured
9
10set -e
11
12SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
13PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
14
15# Colors
16GREEN='\033[0;32m'
17YELLOW='\033[1;33m'
18RED='\033[0;31m'
19NC='\033[0m'
20
21log() { echo -e "${GREEN}[SETUP]${NC} $1"; }
22warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
23error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
24
25cd "$PROJECT_DIR"
26
27# Check prerequisites
28log "Checking prerequisites..."
29
30if ! command -v docker &> /dev/null; then
31 error "Docker is not installed. Install with: curl -fsSL https://get.docker.com | sh"
32fi
33
34if ! docker compose version &> /dev/null; then
35 error "docker compose is not available. Install with: apt install docker-compose-plugin"
36fi
37
38# Check for .env.prod
39if [ ! -f ".env.prod" ]; then
40 error ".env.prod not found! Copy from .env.prod.example and configure secrets."
41fi
42
43# Load environment
44set -a
45source .env.prod
46set +a
47
48# Create required directories
49log "Creating directories..."
50mkdir -p backups
51mkdir -p static/.well-known
52
53# Check for did.json
54if [ ! -f "static/.well-known/did.json" ]; then
55 warn "static/.well-known/did.json not found!"
56 warn "Run ./scripts/generate-did-keys.sh to create it."
57fi
58
59# Note: Caddy logs are written to Docker volume (caddy-data)
60# If you need host-accessible logs, uncomment and run as root:
61# mkdir -p /var/log/caddy && chown 1000:1000 /var/log/caddy
62
63# Pull Docker images
64log "Pulling Docker images..."
65docker compose -f docker-compose.prod.yml pull postgres pds caddy
66
67# Build AppView
68log "Building AppView..."
69docker compose -f docker-compose.prod.yml build appview
70
71# Start services
72log "Starting services..."
73docker compose -f docker-compose.prod.yml up -d
74
75# Wait for PostgreSQL
76log "Waiting for PostgreSQL to be ready..."
77until docker compose -f docker-compose.prod.yml exec -T postgres pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" > /dev/null 2>&1; do
78 sleep 2
79done
80log "PostgreSQL is ready!"
81
82# Run migrations
83log "Running database migrations..."
84# The AppView runs migrations on startup, but you can also run them manually:
85# docker compose -f docker-compose.prod.yml exec appview /app/coves-server migrate
86
87# Final status
88log ""
89log "============================================"
90log " Coves Production Setup Complete!"
91log "============================================"
92log ""
93log "Services running:"
94docker compose -f docker-compose.prod.yml ps
95log ""
96log "Next steps:"
97log " 1. Configure DNS for coves.social and coves.me"
98log " 2. Run ./scripts/generate-did-keys.sh to create DID keys"
99log " 3. Test health endpoints:"
100log " curl https://coves.social/xrpc/_health"
101log " curl https://coves.me/xrpc/_health"
102log ""
103log "Useful commands:"
104log " View logs: docker compose -f docker-compose.prod.yml logs -f"
105log " Deploy update: ./scripts/deploy.sh appview"
106log " Backup DB: ./scripts/backup.sh"