- Add separated Docker Compose architecture (astro/infrastructure/override) - Implement Directus + PostgreSQL with pinned versions (10.12.0/15.5-alpine) - Add comprehensive database safety protections and backup scripts - Configure production-ready NGINX reverse proxy setup - Add container names, labels, and enhanced healthchecks - Remove fallback environment variables for explicit production config - Include log rotation and monitoring improvements Infrastructure deployment: - npm run docker:infrastructure:up (one-time setup) - npm run docker:astro:up (regular deployments) - npm run db:backup/restore/status (database management) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
321 lines
6.9 KiB
Markdown
321 lines
6.9 KiB
Markdown
# Docker Deployment Guide
|
|
|
|
This guide covers setting up Black Canyon Tickets with separated Docker Compose files for optimal deployment workflow.
|
|
|
|
## Overview
|
|
|
|
- **Astro App**: Rebuilt on each Git deployment
|
|
- **Directus + PostgreSQL**: Persistent infrastructure, deployed once
|
|
- **NGINX**: Reverse proxy to both services
|
|
- **Certbot**: SSL certificates (existing setup)
|
|
|
|
## Server Setup (One-Time)
|
|
|
|
### 1. Install Dependencies
|
|
|
|
```bash
|
|
# Update system
|
|
sudo apt update && sudo apt upgrade -y
|
|
|
|
# Install Docker & Docker Compose
|
|
curl -fsSL https://get.docker.com -o get-docker.sh
|
|
sudo sh get-docker.sh
|
|
sudo usermod -aG docker $USER
|
|
|
|
# Log out and back in for Docker group to take effect
|
|
```
|
|
|
|
### 2. Clone Repository
|
|
|
|
```bash
|
|
cd /var/www
|
|
sudo git clone https://github.com/your-org/bct-whitelabel.git
|
|
sudo chown -R $USER:$USER bct-whitelabel
|
|
cd bct-whitelabel
|
|
```
|
|
|
|
### 3. Configure Environment
|
|
|
|
```bash
|
|
# Copy infrastructure environment template
|
|
cp .env.infrastructure .env.infrastructure.local
|
|
|
|
# Edit with your production values
|
|
nano .env.infrastructure.local
|
|
```
|
|
|
|
**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
|
|
|
|
```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
|
|
sudo cp nginx-example.conf /etc/nginx/sites-available/blackcanyontickets
|
|
|
|
# Enable site
|
|
sudo ln -s /etc/nginx/sites-available/blackcanyontickets /etc/nginx/sites-enabled/
|
|
|
|
# Test configuration
|
|
sudo nginx -t
|
|
```
|
|
|
|
### 7. Setup SSL with Certbot
|
|
|
|
```bash
|
|
# Get SSL certificate (Certbot handles NGINX config automatically)
|
|
sudo certbot --nginx -d portal.blackcanyontickets.com
|
|
|
|
# Reload NGINX with SSL
|
|
sudo systemctl reload nginx
|
|
```
|
|
|
|
## Git Deployment Script
|
|
|
|
Update your deployment script to only rebuild the Astro app:
|
|
|
|
### Simple Deploy Script
|
|
|
|
```bash
|
|
#!/bin/bash
|
|
set -e
|
|
|
|
echo "Deploying BCT Astro app..."
|
|
|
|
# Navigate to project directory
|
|
cd /var/www/bct-whitelabel
|
|
|
|
# Pull latest changes
|
|
git pull origin main
|
|
|
|
# Rebuild only Astro app (infrastructure stays running)
|
|
npm run docker:astro:up
|
|
|
|
echo "Deployment complete!"
|
|
```
|
|
|
|
**That's it!** Your infrastructure (Directus + PostgreSQL) keeps running.
|
|
|
|
## Daily Operations
|
|
|
|
### Check Service Status
|
|
|
|
```bash
|
|
# View all running containers
|
|
docker ps
|
|
|
|
# Check logs
|
|
npm run docker:astro:logs # Astro app logs
|
|
npm run docker:infrastructure:logs # Directus + PostgreSQL logs
|
|
|
|
# Health checks
|
|
curl http://localhost:3000/api/health # Astro health
|
|
curl http://localhost:8055/server/health # Directus health
|
|
```
|
|
|
|
### Restart Services
|
|
|
|
```bash
|
|
# Restart Astro app only
|
|
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
|
|
|
|
- **Main App**: https://portal.blackcanyontickets.com
|
|
- **Directus Admin**: https://portal.blackcanyontickets.com/admin
|
|
- **Directus API**: https://portal.blackcanyontickets.com/api/directus
|
|
|
|
## Backup Strategy
|
|
|
|
### Database Backup
|
|
|
|
```bash
|
|
# Create backup script
|
|
cat > backup-db.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
|
|
|
|
# Keep only last 7 days
|
|
find $BACKUP_DIR -name "directus_*.sql" -mtime +7 -delete
|
|
|
|
echo "Backup completed: $BACKUP_DIR/directus_$DATE.sql"
|
|
EOF
|
|
|
|
chmod +x backup-db.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 .
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Common Issues
|
|
|
|
1. **Services 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
|
|
|
|
# Check environment variables
|
|
echo $DIRECTUS_DB_PASSWORD
|
|
```
|
|
|
|
3. **NGINX proxy errors**
|
|
```bash
|
|
# Test NGINX config
|
|
sudo nginx -t
|
|
|
|
# Check upstream connectivity
|
|
curl http://localhost:3000
|
|
curl http://localhost:8055
|
|
```
|
|
|
|
### 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
|
|
```
|
|
|
|
## 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'
|
|
[Unit]
|
|
Description=BCT Infrastructure (Directus + PostgreSQL)
|
|
Requires=docker.service
|
|
After=docker.service
|
|
|
|
[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
|
|
TimeoutStartSec=0
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# Enable and start the service
|
|
sudo systemctl enable bct-infrastructure.service
|
|
sudo systemctl start bct-infrastructure.service
|
|
```
|
|
|
|
### One-Command Astro Redeploy
|
|
|
|
Add this to your server for quick deployments:
|
|
|
|
```bash
|
|
# Create deployment alias
|
|
echo 'alias redeploy-bct="cd /var/www/bct-whitelabel && git pull && npm run docker:astro:up"' >> ~/.bashrc
|
|
source ~/.bashrc
|
|
|
|
# Now you can simply run:
|
|
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. |