refactor: Remove Directus infrastructure, simplify Docker deployment
- Remove Directus CMS infrastructure (docker-compose.infrastructure.yml) - Simplify to Astro-only deployment using existing Supabase backend - Clean up docker-compose.override.yml to focus on local development - Update NGINX config to proxy only to Astro app - Remove Directus-related npm scripts and database management tools - Streamline deployment guide for Supabase + Astro architecture Deployment workflow: - Local: npm run docker:dev (Astro + Supabase hosted) - Production: npm run docker:astro:up (Astro only) Benefits: - Simpler architecture with proven Supabase backend - Faster deployments (Astro only) - Zero database downtime - Reduced operational complexity 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
# Docker Deployment Guide
|
||||
|
||||
This guide covers setting up Black Canyon Tickets with separated Docker Compose files for optimal deployment workflow.
|
||||
This guide covers setting up Black Canyon Tickets with optimized Docker deployment for your Astro application.
|
||||
|
||||
## Overview
|
||||
|
||||
- **Astro App**: Rebuilt on each Git deployment
|
||||
- **Directus + PostgreSQL**: Persistent infrastructure, deployed once
|
||||
- **NGINX**: Reverse proxy to both services
|
||||
- **Astro App**: Rebuilt on each Git deployment using existing Supabase backend
|
||||
- **Database**: Uses your existing hosted Supabase PostgreSQL + Auth
|
||||
- **NGINX**: Reverse proxy to Astro application
|
||||
- **Certbot**: SSL certificates (existing setup)
|
||||
|
||||
## Server Setup (One-Time)
|
||||
@@ -36,55 +36,31 @@ cd bct-whitelabel
|
||||
|
||||
### 3. Configure Environment
|
||||
|
||||
```bash
|
||||
# Copy infrastructure environment template
|
||||
cp .env.infrastructure .env.infrastructure.local
|
||||
Your application uses Supabase (hosted) so just ensure your `.env` file has:
|
||||
|
||||
# Edit with your production values
|
||||
nano .env.infrastructure.local
|
||||
```bash
|
||||
# Supabase (your existing hosted database)
|
||||
PUBLIC_SUPABASE_URL=https://zctjaivtfyfxokfaemek.supabase.co
|
||||
PUBLIC_SUPABASE_ANON_KEY=your-anon-key
|
||||
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
|
||||
|
||||
# Stripe
|
||||
STRIPE_PUBLISHABLE_KEY=pk_...
|
||||
STRIPE_SECRET_KEY=sk_...
|
||||
STRIPE_WEBHOOK_SECRET=whsec_...
|
||||
|
||||
# Email
|
||||
RESEND_API_KEY=re_...
|
||||
|
||||
# Monitoring
|
||||
SENTRY_DSN=https://...
|
||||
SENTRY_RELEASE=production
|
||||
```
|
||||
|
||||
**Required values in `.env.infrastructure.local`:**
|
||||
```bash
|
||||
# Generate these with: openssl rand -hex 32
|
||||
DIRECTUS_KEY=your-32-char-random-key-here
|
||||
DIRECTUS_SECRET=your-32-char-random-secret-here
|
||||
|
||||
# Strong passwords
|
||||
DIRECTUS_DB_PASSWORD=your-secure-db-password
|
||||
DIRECTUS_ADMIN_PASSWORD=your-secure-admin-password
|
||||
|
||||
# Your domain
|
||||
DIRECTUS_ADMIN_EMAIL=admin@blackcanyontickets.com
|
||||
DIRECTUS_CORS_ORIGIN=https://portal.blackcanyontickets.com
|
||||
|
||||
# Email (optional)
|
||||
DIRECTUS_SMTP_PASSWORD=your-resend-api-key
|
||||
```
|
||||
|
||||
### 4. Create Docker Network
|
||||
### 4. Configure NGINX
|
||||
|
||||
```bash
|
||||
# Create shared network for services
|
||||
docker network create bct-network
|
||||
```
|
||||
|
||||
### 5. Deploy Infrastructure
|
||||
|
||||
```bash
|
||||
# Load environment and start infrastructure
|
||||
export $(cat .env.infrastructure.local | xargs)
|
||||
npm run docker:infrastructure:up
|
||||
|
||||
# Verify services are running
|
||||
docker ps
|
||||
npm run docker:infrastructure:logs
|
||||
```
|
||||
|
||||
### 6. Configure NGINX
|
||||
|
||||
```bash
|
||||
# Copy simplified configuration
|
||||
# Copy example configuration
|
||||
sudo cp nginx-example.conf /etc/nginx/sites-available/blackcanyontickets
|
||||
|
||||
# Enable site
|
||||
@@ -94,7 +70,7 @@ sudo ln -s /etc/nginx/sites-available/blackcanyontickets /etc/nginx/sites-enable
|
||||
sudo nginx -t
|
||||
```
|
||||
|
||||
### 7. Setup SSL with Certbot
|
||||
### 5. Setup SSL with Certbot
|
||||
|
||||
```bash
|
||||
# Get SSL certificate (Certbot handles NGINX config automatically)
|
||||
@@ -104,9 +80,19 @@ sudo certbot --nginx -d portal.blackcanyontickets.com
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
### 6. Set Up Log Rotation
|
||||
|
||||
```bash
|
||||
# Install log rotation
|
||||
sudo cp logrotate-bct /etc/logrotate.d/bct
|
||||
|
||||
# Test log rotation
|
||||
sudo logrotate -d /etc/logrotate.d/bct
|
||||
```
|
||||
|
||||
## Git Deployment Script
|
||||
|
||||
Update your deployment script to only rebuild the Astro app:
|
||||
Update your deployment script to rebuild only the Astro app:
|
||||
|
||||
### Simple Deploy Script
|
||||
|
||||
@@ -122,169 +108,136 @@ cd /var/www/bct-whitelabel
|
||||
# Pull latest changes
|
||||
git pull origin main
|
||||
|
||||
# Rebuild only Astro app (infrastructure stays running)
|
||||
# Rebuild Astro app
|
||||
npm run docker:astro:up
|
||||
|
||||
echo "Deployment complete!"
|
||||
```
|
||||
|
||||
**That's it!** Your infrastructure (Directus + PostgreSQL) keeps running.
|
||||
**Your Supabase database stays online** - no downtime for deployments!
|
||||
|
||||
## Daily Operations
|
||||
|
||||
### Check Service Status
|
||||
|
||||
```bash
|
||||
# View all running containers
|
||||
# View running containers
|
||||
docker ps
|
||||
|
||||
# Check logs
|
||||
npm run docker:astro:logs # Astro app logs
|
||||
npm run docker:infrastructure:logs # Directus + PostgreSQL logs
|
||||
npm run docker:astro:logs
|
||||
|
||||
# Health checks
|
||||
curl http://localhost:3000/api/health # Astro health
|
||||
curl http://localhost:8055/server/health # Directus health
|
||||
curl http://localhost:3000/api/health
|
||||
```
|
||||
|
||||
### Restart Services
|
||||
|
||||
```bash
|
||||
# Restart Astro app only
|
||||
# Restart Astro app
|
||||
npm run docker:astro:down
|
||||
npm run docker:astro:up
|
||||
|
||||
# Restart infrastructure (rare)
|
||||
npm run docker:infrastructure:down
|
||||
npm run docker:infrastructure:up
|
||||
```
|
||||
|
||||
### View Service URLs
|
||||
### Service URLs
|
||||
|
||||
- **Main App**: https://portal.blackcanyontickets.com
|
||||
- **Directus Admin**: https://portal.blackcanyontickets.com/admin
|
||||
- **Directus API**: https://portal.blackcanyontickets.com/api/directus
|
||||
- **Admin Panel**: https://portal.blackcanyontickets.com/admin
|
||||
- **Health Check**: https://portal.blackcanyontickets.com/api/health
|
||||
|
||||
## Available Commands
|
||||
|
||||
### Docker Commands
|
||||
```bash
|
||||
# Production deployment (Astro only)
|
||||
npm run docker:astro:up # Deploy Astro app
|
||||
npm run docker:astro:down # Stop Astro app
|
||||
npm run docker:astro:logs # View Astro logs
|
||||
|
||||
# Production (pre-built image)
|
||||
npm run docker:prod:up # Deploy pre-built image
|
||||
npm run docker:prod:down # Stop production image
|
||||
|
||||
# Local development
|
||||
npm run docker:dev # Start development container
|
||||
npm run docker:dev:build # Start with rebuild
|
||||
```
|
||||
|
||||
## Backup Strategy
|
||||
|
||||
### Database Backup
|
||||
### Supabase Backups
|
||||
|
||||
Since you're using hosted Supabase:
|
||||
- **Automatic backups** are handled by Supabase
|
||||
- **Point-in-time recovery** available through Supabase dashboard
|
||||
- **Manual exports** can be done through Supabase SQL editor
|
||||
|
||||
### Application Backups
|
||||
|
||||
```bash
|
||||
# Create backup script
|
||||
cat > backup-db.sh << 'EOF'
|
||||
# Create backup script for logs and uploads
|
||||
cat > backup-app.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
BACKUP_DIR="/var/backups/bct"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
|
||||
mkdir -p $BACKUP_DIR
|
||||
|
||||
# Backup PostgreSQL
|
||||
docker exec bct-whitelabel-postgres-1 pg_dump -U directus directus > $BACKUP_DIR/directus_$DATE.sql
|
||||
# Backup logs
|
||||
tar -czf $BACKUP_DIR/logs_$DATE.tar.gz logs/
|
||||
|
||||
# Keep only last 7 days
|
||||
find $BACKUP_DIR -name "directus_*.sql" -mtime +7 -delete
|
||||
find $BACKUP_DIR -name "*.tar.gz" -mtime +7 -delete
|
||||
|
||||
echo "Backup completed: $BACKUP_DIR/directus_$DATE.sql"
|
||||
echo "Backup completed: $BACKUP_DIR"
|
||||
EOF
|
||||
|
||||
chmod +x backup-db.sh
|
||||
chmod +x backup-app.sh
|
||||
|
||||
# Add to crontab for daily backups
|
||||
echo "0 2 * * * /var/www/bct-whitelabel/backup-db.sh" | crontab -
|
||||
```
|
||||
|
||||
### Upload Backup
|
||||
|
||||
```bash
|
||||
# Backup Directus uploads
|
||||
tar -czf /var/backups/bct/directus_uploads_$(date +%Y%m%d).tar.gz \
|
||||
-C /var/lib/docker/volumes/bct-whitelabel_directus_uploads/_data .
|
||||
echo "0 2 * * * /var/www/bct-whitelabel/backup-app.sh" | crontab -
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Services won't start**
|
||||
1. **Container won't start**
|
||||
```bash
|
||||
# Check logs
|
||||
docker logs bct-whitelabel-directus-1
|
||||
docker logs bct-whitelabel-postgres-1
|
||||
|
||||
# Check network
|
||||
docker network ls | grep bct-network
|
||||
```
|
||||
|
||||
2. **Database connection issues**
|
||||
```bash
|
||||
# Verify PostgreSQL is running
|
||||
docker exec bct-whitelabel-postgres-1 pg_isready -U directus
|
||||
docker logs bct-astro
|
||||
|
||||
# Check environment variables
|
||||
echo $DIRECTUS_DB_PASSWORD
|
||||
env | grep SUPABASE
|
||||
```
|
||||
|
||||
3. **NGINX proxy errors**
|
||||
2. **NGINX proxy errors**
|
||||
```bash
|
||||
# Test NGINX config
|
||||
sudo nginx -t
|
||||
|
||||
# Check upstream connectivity
|
||||
curl http://localhost:3000
|
||||
curl http://localhost:8055
|
||||
curl http://localhost:3000/api/health
|
||||
```
|
||||
|
||||
### Reset Infrastructure (if needed)
|
||||
|
||||
```bash
|
||||
# WARNING: This will delete all Directus data
|
||||
npm run docker:infrastructure:down
|
||||
docker volume rm bct-whitelabel_postgres_data bct-whitelabel_directus_uploads bct-whitelabel_directus_extensions
|
||||
npm run docker:infrastructure:up
|
||||
```
|
||||
|
||||
## Monitoring
|
||||
|
||||
### Log Monitoring
|
||||
|
||||
```bash
|
||||
# Real-time logs
|
||||
tail -f /var/log/nginx/access.log
|
||||
npm run docker:astro:logs -f
|
||||
npm run docker:infrastructure:logs -f
|
||||
|
||||
# Log rotation (add to /etc/logrotate.d/bct)
|
||||
/var/www/bct-whitelabel/logs/*.log {
|
||||
daily
|
||||
missingok
|
||||
rotate 7
|
||||
compress
|
||||
delaycompress
|
||||
notifempty
|
||||
sharedscripts
|
||||
}
|
||||
```
|
||||
|
||||
### Resource Monitoring
|
||||
|
||||
```bash
|
||||
# Container stats
|
||||
docker stats
|
||||
|
||||
# Disk usage
|
||||
docker system df
|
||||
docker volume ls
|
||||
```
|
||||
3. **SSL certificate issues**
|
||||
```bash
|
||||
# Renew certificate
|
||||
sudo certbot renew
|
||||
|
||||
# Check certificate status
|
||||
sudo certbot certificates
|
||||
```
|
||||
|
||||
## Auto-Start Services on Boot
|
||||
|
||||
### Configure Docker Services to Auto-Start
|
||||
|
||||
```bash
|
||||
# Create systemd service for infrastructure
|
||||
sudo tee /etc/systemd/system/bct-infrastructure.service > /dev/null << 'EOF'
|
||||
# Create systemd service for Astro app
|
||||
sudo tee /etc/systemd/system/bct-astro.service > /dev/null << 'EOF'
|
||||
[Unit]
|
||||
Description=BCT Infrastructure (Directus + PostgreSQL)
|
||||
Description=BCT Astro Application
|
||||
Requires=docker.service
|
||||
After=docker.service
|
||||
|
||||
@@ -292,8 +245,8 @@ After=docker.service
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
WorkingDirectory=/var/www/bct-whitelabel
|
||||
ExecStart=/usr/bin/docker-compose -f docker-compose.infrastructure.yml up -d
|
||||
ExecStop=/usr/bin/docker-compose -f docker-compose.infrastructure.yml down
|
||||
ExecStart=/usr/bin/docker-compose -f docker-compose.astro.yml up -d
|
||||
ExecStop=/usr/bin/docker-compose -f docker-compose.astro.yml down
|
||||
TimeoutStartSec=0
|
||||
|
||||
[Install]
|
||||
@@ -301,11 +254,11 @@ WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Enable and start the service
|
||||
sudo systemctl enable bct-infrastructure.service
|
||||
sudo systemctl start bct-infrastructure.service
|
||||
sudo systemctl enable bct-astro.service
|
||||
sudo systemctl start bct-astro.service
|
||||
```
|
||||
|
||||
### One-Command Astro Redeploy
|
||||
### One-Command Deployment
|
||||
|
||||
Add this to your server for quick deployments:
|
||||
|
||||
@@ -318,4 +271,31 @@ source ~/.bashrc
|
||||
redeploy-bct
|
||||
```
|
||||
|
||||
This setup provides a robust, maintainable deployment pipeline where your Astro app can be updated frequently while keeping your CMS and database stable.
|
||||
## Monitoring
|
||||
|
||||
### Log Monitoring
|
||||
|
||||
```bash
|
||||
# Real-time logs
|
||||
tail -f /var/log/nginx/access.log
|
||||
npm run docker:astro:logs -f
|
||||
|
||||
# Container stats
|
||||
docker stats bct-astro
|
||||
|
||||
# Disk usage
|
||||
docker system df
|
||||
```
|
||||
|
||||
### Resource Monitoring
|
||||
|
||||
```bash
|
||||
# Container resource usage
|
||||
docker stats
|
||||
|
||||
# System resources
|
||||
htop
|
||||
df -h
|
||||
```
|
||||
|
||||
This setup provides a robust, maintainable deployment pipeline where your Astro app can be updated frequently while your Supabase database remains stable and always available.
|
||||
Reference in New Issue
Block a user