mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 07:51:09 -05:00
Add Road Trip Planner template with interactive map and trip management features
- Implemented a new HTML template for the Road Trip Planner. - Integrated Leaflet.js for interactive mapping and routing. - Added functionality for searching and selecting parks to include in a trip. - Enabled drag-and-drop reordering of selected parks. - Included trip optimization and route calculation features. - Created a summary display for trip statistics. - Added functionality to save trips and manage saved trips. - Enhanced UI with responsive design and dark mode support.
This commit is contained in:
387
docs/UNRAID_COMPLETE_AUTOMATION.md
Normal file
387
docs/UNRAID_COMPLETE_AUTOMATION.md
Normal file
@@ -0,0 +1,387 @@
|
||||
# ThrillWiki Complete Unraid Automation Guide
|
||||
|
||||
This guide provides **complete automation** for ThrillWiki deployment on Unraid, including VM creation, configuration, and CI/CD setup. Everything is automated with a single command.
|
||||
|
||||
## 🚀 One-Command Complete Setup
|
||||
|
||||
Run this single command to automate everything:
|
||||
|
||||
```bash
|
||||
./scripts/unraid/setup-complete-automation.sh
|
||||
```
|
||||
|
||||
This will:
|
||||
1. ✅ Create and configure VM on Unraid
|
||||
2. ✅ Install Ubuntu Server with all dependencies
|
||||
3. ✅ Configure PostgreSQL database
|
||||
4. ✅ Deploy ThrillWiki application
|
||||
5. ✅ Set up systemd services
|
||||
6. ✅ Configure SSH access
|
||||
7. ✅ Set up webhook listener
|
||||
8. ✅ Test the entire system
|
||||
|
||||
## System Architecture
|
||||
|
||||
```
|
||||
GitHub Push → Webhook → Local Listener → SSH → Unraid VM → Deploy & Restart
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Local Machine
|
||||
- Python 3.8+
|
||||
- SSH client
|
||||
- Internet connection
|
||||
|
||||
### Unraid Server
|
||||
- Unraid 6.8+ with VM support enabled
|
||||
- SSH access to Unraid server
|
||||
- Sufficient resources (4GB RAM, 50GB disk minimum)
|
||||
- Ubuntu Server 22.04 ISO in `/mnt/user/isos/`
|
||||
|
||||
## Automated Components
|
||||
|
||||
### 1. VM Manager (`scripts/unraid/vm-manager.py`)
|
||||
- Creates VM with proper specifications
|
||||
- Configures networking and storage
|
||||
- Manages VM lifecycle (start/stop/status)
|
||||
- Retrieves VM IP addresses
|
||||
|
||||
### 2. Complete Automation (`scripts/unraid/setup-complete-automation.sh`)
|
||||
- Orchestrates entire setup process
|
||||
- Handles SSH key generation and distribution
|
||||
- Configures all services automatically
|
||||
- Performs end-to-end testing
|
||||
|
||||
### 3. VM Configuration
|
||||
- Ubuntu Server 22.04 LTS
|
||||
- PostgreSQL database
|
||||
- UV package manager
|
||||
- Systemd services for ThrillWiki
|
||||
- Nginx (optional)
|
||||
|
||||
## Step-by-Step Process
|
||||
|
||||
### Phase 1: Initial Setup
|
||||
The automation script will prompt for:
|
||||
- Unraid server IP address
|
||||
- Unraid credentials
|
||||
- VM specifications (memory, CPU, disk)
|
||||
- GitHub repository URL
|
||||
- Webhook secret
|
||||
|
||||
### Phase 2: SSH Key Setup
|
||||
- Generates SSH keys for VM access
|
||||
- Generates SSH keys for Unraid access
|
||||
- Configures SSH client settings
|
||||
- Tests connectivity
|
||||
|
||||
### Phase 3: VM Creation
|
||||
- Creates VM XML configuration
|
||||
- Creates virtual disk (QCOW2 format)
|
||||
- Defines VM in libvirt
|
||||
- Starts VM with Ubuntu installation
|
||||
|
||||
### Phase 4: VM Configuration
|
||||
- Installs Ubuntu Server 22.04
|
||||
- Configures user account with SSH keys
|
||||
- Installs required packages:
|
||||
- Python 3.8+
|
||||
- UV package manager
|
||||
- PostgreSQL
|
||||
- Git
|
||||
- Build tools
|
||||
|
||||
### Phase 5: ThrillWiki Deployment
|
||||
- Clones repository
|
||||
- Installs Python dependencies with UV
|
||||
- Creates database and user
|
||||
- Runs initial migrations
|
||||
- Configures systemd services
|
||||
- Starts ThrillWiki service
|
||||
|
||||
### Phase 6: CI/CD Setup
|
||||
- Configures webhook listener
|
||||
- Tests deployment pipeline
|
||||
- Verifies all services
|
||||
|
||||
## Configuration Files Generated
|
||||
|
||||
### `***REMOVED***.unraid`
|
||||
```bash
|
||||
UNRAID_HOST=192.168.1.100
|
||||
UNRAID_USER=root
|
||||
VM_NAME=thrillwiki-vm
|
||||
VM_MEMORY=4096
|
||||
VM_VCPUS=2
|
||||
VM_DISK_SIZE=50
|
||||
SSH_PUBLIC_KEY=ssh-rsa AAAAB3...
|
||||
```
|
||||
|
||||
### `***REMOVED***.webhook`
|
||||
```bash
|
||||
WEBHOOK_PORT=9000
|
||||
WEBHOOK_SECRET=your_secret
|
||||
VM_HOST=192.168.1.101
|
||||
VM_USER=ubuntu
|
||||
VM_KEY_PATH=/home/user/.ssh/thrillwiki_vm
|
||||
VM_PROJECT_PATH=/home/ubuntu/thrillwiki
|
||||
REPO_URL=https://github.com/user/repo.git
|
||||
DEPLOY_BRANCH=main
|
||||
```
|
||||
|
||||
### SSH Configuration
|
||||
```
|
||||
Host thrillwiki-vm
|
||||
HostName 192.168.1.101
|
||||
User ubuntu
|
||||
IdentityFile ~/.ssh/thrillwiki_vm
|
||||
StrictHostKeyChecking no
|
||||
|
||||
Host unraid
|
||||
HostName 192.168.1.100
|
||||
User root
|
||||
IdentityFile ~/.ssh/unraid_access
|
||||
StrictHostKeyChecking no
|
||||
```
|
||||
|
||||
## VM Specifications
|
||||
|
||||
### Default Configuration
|
||||
- **OS**: Ubuntu Server 22.04 LTS
|
||||
- **Memory**: 4GB RAM
|
||||
- **vCPUs**: 2
|
||||
- **Storage**: 50GB (expandable)
|
||||
- **Network**: Bridge mode (br0)
|
||||
- **Boot**: UEFI with OVMF
|
||||
|
||||
### Customizable Options
|
||||
All specifications can be customized during setup:
|
||||
- Memory allocation
|
||||
- CPU cores
|
||||
- Disk size
|
||||
- VM name
|
||||
- Network configuration
|
||||
|
||||
## Services Installed
|
||||
|
||||
### On VM
|
||||
- **ThrillWiki Django App**: Port 8000
|
||||
- **PostgreSQL Database**: Port 5432
|
||||
- **SSH Server**: Port 22
|
||||
- **Systemd Services**: Auto-start on boot
|
||||
|
||||
### On Local Machine
|
||||
- **Webhook Listener**: Configurable port (default 9000)
|
||||
- **SSH Client**: Configured for VM access
|
||||
|
||||
## Management Commands
|
||||
|
||||
### VM Management
|
||||
```bash
|
||||
# Check VM status
|
||||
python3 scripts/unraid/vm-manager.py status
|
||||
|
||||
# Start VM
|
||||
python3 scripts/unraid/vm-manager.py start
|
||||
|
||||
# Stop VM
|
||||
python3 scripts/unraid/vm-manager.py stop
|
||||
|
||||
# Get VM IP
|
||||
python3 scripts/unraid/vm-manager.py ip
|
||||
|
||||
# Complete VM setup
|
||||
python3 scripts/unraid/vm-manager.py setup
|
||||
```
|
||||
|
||||
### Service Management
|
||||
```bash
|
||||
# Connect to VM
|
||||
ssh thrillwiki-vm
|
||||
|
||||
# Check ThrillWiki service
|
||||
sudo systemctl status thrillwiki
|
||||
|
||||
# Restart service
|
||||
sudo systemctl restart thrillwiki
|
||||
|
||||
# View logs
|
||||
journalctl -u thrillwiki -f
|
||||
|
||||
# Manual deployment
|
||||
cd thrillwiki && ./scripts/vm-deploy.sh
|
||||
```
|
||||
|
||||
### Webhook Management
|
||||
```bash
|
||||
# Start webhook listener
|
||||
./start-webhook.sh
|
||||
|
||||
# Or manually
|
||||
source ***REMOVED***.webhook && python3 scripts/webhook-listener.py
|
||||
|
||||
# Test webhook
|
||||
curl -X GET http://localhost:9000/health
|
||||
```
|
||||
|
||||
## Automated Testing
|
||||
|
||||
The setup includes comprehensive testing:
|
||||
|
||||
### Connectivity Tests
|
||||
- SSH access to Unraid server
|
||||
- SSH access to VM
|
||||
- Network connectivity
|
||||
|
||||
### Service Tests
|
||||
- ThrillWiki application startup
|
||||
- Database connectivity
|
||||
- Web server response
|
||||
|
||||
### Deployment Tests
|
||||
- Git repository access
|
||||
- Deployment script execution
|
||||
- Service restart verification
|
||||
|
||||
## Security Features
|
||||
|
||||
### SSH Security
|
||||
- Dedicated SSH keys for each connection
|
||||
- No password authentication
|
||||
- Key-based access only
|
||||
|
||||
### Network Security
|
||||
- VM isolated in bridge network
|
||||
- Firewall rules (configurable)
|
||||
- SSH key rotation support
|
||||
|
||||
### Service Security
|
||||
- Non-root service execution
|
||||
- Systemd security features
|
||||
- Log rotation and monitoring
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **VM Creation Fails**
|
||||
```bash
|
||||
# Check Unraid VM support
|
||||
ssh unraid "virsh list --all"
|
||||
|
||||
# Verify ISO exists
|
||||
ssh unraid "ls -la /mnt/user/isos/*.iso"
|
||||
```
|
||||
|
||||
2. **VM Won't Start**
|
||||
```bash
|
||||
# Check VM configuration
|
||||
python3 scripts/unraid/vm-manager.py status
|
||||
|
||||
# Check Unraid logs
|
||||
ssh unraid "tail -f /var/log/libvirt/qemu/thrillwiki-vm.log"
|
||||
```
|
||||
|
||||
3. **Can't Connect to VM**
|
||||
```bash
|
||||
# Check VM IP
|
||||
python3 scripts/unraid/vm-manager.py ip
|
||||
|
||||
# Test SSH key
|
||||
ssh -i ~/.ssh/thrillwiki_vm ubuntu@VM_IP
|
||||
```
|
||||
|
||||
4. **Service Won't Start**
|
||||
```bash
|
||||
# Check service logs
|
||||
ssh thrillwiki-vm "journalctl -u thrillwiki --no-pager"
|
||||
|
||||
# Manual start
|
||||
ssh thrillwiki-vm "cd thrillwiki && ./scripts/ci-start.sh"
|
||||
```
|
||||
|
||||
### Log Locations
|
||||
|
||||
- **Setup logs**: `logs/unraid-automation.log`
|
||||
- **VM logs**: SSH to VM, then `journalctl -u thrillwiki`
|
||||
- **Webhook logs**: `logs/webhook.log`
|
||||
- **Deployment logs**: On VM at `~/thrillwiki/logs/deploy.log`
|
||||
|
||||
## Advanced Configuration
|
||||
|
||||
### Custom VM Specifications
|
||||
Edit variables in the automation script:
|
||||
```bash
|
||||
VM_MEMORY=8192 # 8GB RAM
|
||||
VM_VCPUS=4 # 4 CPU cores
|
||||
VM_DISK_SIZE=100 # 100GB disk
|
||||
```
|
||||
|
||||
### Network Configuration
|
||||
For static IP assignment, modify the VM XML template in `vm-manager.py`.
|
||||
|
||||
### Storage Configuration
|
||||
The automation uses QCOW2 format for efficient storage. For better performance, consider:
|
||||
- Raw disk format
|
||||
- NVMe storage on Unraid
|
||||
- Dedicated SSD for VM
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
### Recommended Settings
|
||||
- **Memory**: 4GB minimum, 8GB recommended
|
||||
- **CPU**: 2 cores minimum, 4 cores for production
|
||||
- **Storage**: SSD recommended for database
|
||||
- **Network**: 1Gbps for fast deployments
|
||||
|
||||
### Production Considerations
|
||||
- Use dedicated hardware for database
|
||||
- Configure backup strategies
|
||||
- Monitor resource usage
|
||||
- Set up log rotation
|
||||
|
||||
## Backup and Recovery
|
||||
|
||||
### Automated Backups
|
||||
The deployment script automatically creates backups before each deployment in `~/thrillwiki/backups/`.
|
||||
|
||||
### VM Snapshots
|
||||
```bash
|
||||
# Create VM snapshot
|
||||
ssh unraid "virsh snapshot-create-as thrillwiki-vm snapshot-name"
|
||||
|
||||
# List snapshots
|
||||
ssh unraid "virsh snapshot-list thrillwiki-vm"
|
||||
|
||||
# Restore snapshot
|
||||
ssh unraid "virsh snapshot-revert thrillwiki-vm snapshot-name"
|
||||
```
|
||||
|
||||
### Database Backups
|
||||
```bash
|
||||
# Manual database backup
|
||||
ssh thrillwiki-vm "pg_dump thrillwiki > backup.sql"
|
||||
|
||||
# Automated backup (add to cron)
|
||||
ssh thrillwiki-vm "crontab -e"
|
||||
# Add: 0 2 * * * pg_dump thrillwiki > /home/ubuntu/db-backup-$(date +\%Y\%m\%d).sql
|
||||
```
|
||||
|
||||
## Monitoring
|
||||
|
||||
### Health Checks
|
||||
The system includes built-in health checks:
|
||||
- VM status monitoring
|
||||
- Service health verification
|
||||
- Network connectivity tests
|
||||
- Application response checks
|
||||
|
||||
### Alerts (Optional)
|
||||
Configure alerts for:
|
||||
- Service failures
|
||||
- Resource exhaustion
|
||||
- Deployment failures
|
||||
- Network issues
|
||||
|
||||
This complete automation provides a production-ready ThrillWiki deployment with minimal manual intervention. The entire process from VM creation to application deployment is handled automatically.
|
||||
359
docs/VM_DEPLOYMENT_SETUP.md
Normal file
359
docs/VM_DEPLOYMENT_SETUP.md
Normal file
@@ -0,0 +1,359 @@
|
||||
# ThrillWiki VM Deployment Setup Guide
|
||||
|
||||
This guide explains how to set up a local CI/CD system that automatically deploys ThrillWiki to a Linux VM when commits are pushed to GitHub.
|
||||
|
||||
## System Overview
|
||||
|
||||
The deployment system consists of three main components:
|
||||
|
||||
1. **Local CI Start Script** (`scripts/ci-start.sh`) - Starts the Django server locally
|
||||
2. **GitHub Webhook Listener** (`scripts/webhook-listener.py`) - Listens for GitHub push events
|
||||
3. **VM Deployment Script** (`scripts/vm-deploy.sh`) - Deploys code changes to the Linux VM
|
||||
|
||||
## Architecture Flow
|
||||
|
||||
```
|
||||
GitHub Push → Webhook → Local Listener → SSH to VM → Deploy Script → Restart Server
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Local Machine (Webhook Listener Host)
|
||||
- Python 3.8+
|
||||
- SSH access to the Linux VM
|
||||
- Git repository with webhook access
|
||||
|
||||
### Linux VM (Deployment Target)
|
||||
- Ubuntu 20.04+ (recommended)
|
||||
- Python 3.8+
|
||||
- UV package manager
|
||||
- Git
|
||||
- PostgreSQL (if using database)
|
||||
- SSH server running
|
||||
- Sudo access for the deployment user
|
||||
|
||||
## Step 1: Linux VM Setup
|
||||
|
||||
### 1.1 Create Deployment User
|
||||
|
||||
```bash
|
||||
# On the Linux VM
|
||||
sudo adduser ubuntu
|
||||
sudo usermod -aG sudo ubuntu
|
||||
su - ubuntu
|
||||
```
|
||||
|
||||
### 1.2 Install Required Software
|
||||
|
||||
```bash
|
||||
# Update system
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
# Install essential packages
|
||||
sudo apt install -y git curl build-essential python3-pip python3-venv postgresql postgresql-contrib nginx
|
||||
|
||||
# Install UV package manager
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
source ~/.cargo/env
|
||||
```
|
||||
|
||||
### 1.3 Set up SSH Keys
|
||||
|
||||
```bash
|
||||
# Generate SSH key on local machine
|
||||
ssh-keygen -t rsa -b 4096 -f ~/.ssh/thrillwiki_vm
|
||||
|
||||
# Copy public key to VM
|
||||
ssh-copy-id -i ~/.ssh/thrillwiki_vm.pub ubuntu@VM_IP_ADDRESS
|
||||
```
|
||||
|
||||
### 1.4 Clone Repository
|
||||
|
||||
```bash
|
||||
# On the VM
|
||||
cd /home/ubuntu
|
||||
git clone https://github.com/YOUR_USERNAME/thrillwiki_django_no_react.git thrillwiki
|
||||
cd thrillwiki
|
||||
```
|
||||
|
||||
### 1.5 Install Dependencies
|
||||
|
||||
```bash
|
||||
# Install Python dependencies
|
||||
uv sync
|
||||
|
||||
# Create required directories
|
||||
mkdir -p logs backups
|
||||
```
|
||||
|
||||
## Step 2: Configure Services
|
||||
|
||||
### 2.1 Install Systemd Services
|
||||
|
||||
```bash
|
||||
# Copy service files to systemd directory
|
||||
sudo cp scripts/systemd/thrillwiki.service /etc/systemd/system/
|
||||
sudo cp scripts/systemd/thrillwiki-webhook.service /etc/systemd/system/
|
||||
|
||||
# Edit service files to match your paths
|
||||
sudo nano /etc/systemd/system/thrillwiki.service
|
||||
sudo nano /etc/systemd/system/thrillwiki-webhook.service
|
||||
|
||||
# Reload systemd and enable services
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable thrillwiki.service
|
||||
sudo systemctl enable thrillwiki-webhook.service
|
||||
```
|
||||
|
||||
### 2.2 Configure Environment Variables
|
||||
|
||||
Create `/home/ubuntu/thrillwiki/***REMOVED***`:
|
||||
|
||||
```bash
|
||||
# Database configuration
|
||||
DATABASE_URL=[DATABASE-URL-REMOVED]
|
||||
|
||||
# Django settings
|
||||
DJANGO_SECRET_KEY=your_secret_key_here
|
||||
DJANGO_DEBUG=False
|
||||
DJANGO_ALLOWED_HOSTS=your_domain.com,VM_IP_ADDRESS
|
||||
|
||||
# Webhook configuration
|
||||
WEBHOOK_SECRET=your_github_webhook_secret
|
||||
WEBHOOK_PORT=9000
|
||||
VM_HOST=localhost
|
||||
VM_USER=ubuntu
|
||||
VM_PROJECT_PATH=/home/ubuntu/thrillwiki
|
||||
REPO_URL=https://github.com/YOUR_USERNAME/thrillwiki_django_no_react.git
|
||||
```
|
||||
|
||||
## Step 3: Local Machine Setup
|
||||
|
||||
### 3.1 Configure Webhook Listener
|
||||
|
||||
Create a configuration file for the webhook listener:
|
||||
|
||||
```bash
|
||||
# Create environment file
|
||||
cat > ***REMOVED***.webhook << EOF
|
||||
WEBHOOK_PORT=9000
|
||||
WEBHOOK_SECRET=your_github_webhook_secret
|
||||
VM_HOST=VM_IP_ADDRESS
|
||||
VM_PORT=22
|
||||
VM_USER=ubuntu
|
||||
VM_KEY_PATH=/home/your_user/.ssh/thrillwiki_vm
|
||||
VM_PROJECT_PATH=/home/ubuntu/thrillwiki
|
||||
REPO_URL=https://github.com/YOUR_USERNAME/thrillwiki_django_no_react.git
|
||||
DEPLOY_BRANCH=main
|
||||
EOF
|
||||
```
|
||||
|
||||
### 3.2 Set up GitHub Webhook
|
||||
|
||||
1. Go to your GitHub repository
|
||||
2. Navigate to Settings → Webhooks
|
||||
3. Click "Add webhook"
|
||||
4. Configure:
|
||||
- **Payload URL**: `http://YOUR_PUBLIC_IP:9000/webhook`
|
||||
- **Content type**: `application/json`
|
||||
- **Secret**: Your webhook secret
|
||||
- **Events**: Select "Just the push event"
|
||||
|
||||
## Step 4: Database Setup
|
||||
|
||||
### 4.1 PostgreSQL Configuration
|
||||
|
||||
```bash
|
||||
# On the VM
|
||||
sudo -u postgres psql
|
||||
|
||||
-- Create database and user
|
||||
CREATE DATABASE thrillwiki;
|
||||
CREATE USER thrillwiki_user WITH ENCRYPTED PASSWORD 'your_password';
|
||||
GRANT ALL PRIVILEGES ON DATABASE thrillwiki TO thrillwiki_user;
|
||||
\q
|
||||
|
||||
# Install PostGIS (if using geographic features)
|
||||
sudo apt install -y postgresql-postgis postgresql-postgis-scripts
|
||||
sudo -u postgres psql -d thrillwiki -c "CREATE EXTENSION postgis;"
|
||||
```
|
||||
|
||||
### 4.2 Run Initial Migration
|
||||
|
||||
```bash
|
||||
# On the VM
|
||||
cd /home/ubuntu/thrillwiki
|
||||
uv run manage.py migrate
|
||||
uv run manage.py collectstatic --noinput
|
||||
uv run manage.py createsuperuser
|
||||
```
|
||||
|
||||
## Step 5: Start Services
|
||||
|
||||
### 5.1 Start VM Services
|
||||
|
||||
```bash
|
||||
# On the VM
|
||||
sudo systemctl start thrillwiki
|
||||
sudo systemctl start thrillwiki-webhook
|
||||
sudo systemctl status thrillwiki
|
||||
sudo systemctl status thrillwiki-webhook
|
||||
```
|
||||
|
||||
### 5.2 Start Local Webhook Listener
|
||||
|
||||
```bash
|
||||
# On local machine
|
||||
source ***REMOVED***.webhook
|
||||
python3 scripts/webhook-listener.py
|
||||
```
|
||||
|
||||
## Step 6: Testing
|
||||
|
||||
### 6.1 Test Local Server
|
||||
|
||||
```bash
|
||||
# Start local development server
|
||||
./scripts/ci-start.sh
|
||||
|
||||
# Check if server is running
|
||||
curl http://localhost:8000/health
|
||||
```
|
||||
|
||||
### 6.2 Test VM Deployment
|
||||
|
||||
```bash
|
||||
# On the VM, test deployment script
|
||||
./scripts/vm-deploy.sh
|
||||
|
||||
# Check service status
|
||||
./scripts/vm-deploy.sh status
|
||||
|
||||
# View logs
|
||||
journalctl -u thrillwiki -f
|
||||
```
|
||||
|
||||
### 6.3 Test Webhook
|
||||
|
||||
```bash
|
||||
# Test webhook endpoint
|
||||
curl -X GET http://localhost:9000/health
|
||||
|
||||
# Make a test commit and push to trigger deployment
|
||||
git add .
|
||||
git commit -m "Test deployment"
|
||||
git push origin main
|
||||
```
|
||||
|
||||
## Monitoring and Logs
|
||||
|
||||
### Service Logs
|
||||
|
||||
```bash
|
||||
# View service logs
|
||||
journalctl -u thrillwiki -f
|
||||
journalctl -u thrillwiki-webhook -f
|
||||
|
||||
# View deployment logs
|
||||
tail -f /home/ubuntu/thrillwiki/logs/deploy.log
|
||||
tail -f /home/ubuntu/thrillwiki/logs/webhook.log
|
||||
```
|
||||
|
||||
### Health Checks
|
||||
|
||||
```bash
|
||||
# Check services status
|
||||
systemctl status thrillwiki
|
||||
systemctl status thrillwiki-webhook
|
||||
|
||||
# Manual health check
|
||||
curl http://localhost:8000/health
|
||||
curl http://localhost:9000/health
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Permission Denied**
|
||||
```bash
|
||||
# Fix file permissions
|
||||
chmod +x scripts/*.sh
|
||||
chown ubuntu:ubuntu -R /home/ubuntu/thrillwiki
|
||||
```
|
||||
|
||||
2. **Service Won't Start**
|
||||
```bash
|
||||
# Check service logs
|
||||
journalctl -u thrillwiki --no-pager
|
||||
|
||||
# Verify paths in service files
|
||||
sudo systemctl edit thrillwiki
|
||||
```
|
||||
|
||||
3. **Webhook Not Triggering**
|
||||
```bash
|
||||
# Check webhook listener logs
|
||||
tail -f logs/webhook.log
|
||||
|
||||
# Verify GitHub webhook configuration
|
||||
# Check firewall settings for port 9000
|
||||
```
|
||||
|
||||
4. **Database Connection Issues**
|
||||
```bash
|
||||
# Test database connection
|
||||
uv run manage.py dbshell
|
||||
|
||||
# Check PostgreSQL status
|
||||
sudo systemctl status postgresql
|
||||
```
|
||||
|
||||
### Rollback Procedure
|
||||
|
||||
If deployment fails, you can rollback:
|
||||
|
||||
```bash
|
||||
# On the VM
|
||||
./scripts/vm-deploy.sh
|
||||
# The script automatically handles rollback on failure
|
||||
|
||||
# Manual rollback to specific commit
|
||||
cd /home/ubuntu/thrillwiki
|
||||
git reset --hard COMMIT_HASH
|
||||
./scripts/vm-deploy.sh restart
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
1. **SSH Keys**: Use dedicated SSH keys for deployment
|
||||
2. **Webhook Secret**: Use a strong, unique webhook secret
|
||||
3. **Firewall**: Only open necessary ports (22, 8000, 9000)
|
||||
4. **User Permissions**: Use dedicated deployment user with minimal privileges
|
||||
5. **Environment Variables**: Store sensitive data in environment files, not in code
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Regular Tasks
|
||||
|
||||
1. **Update Dependencies**: Run `uv sync` regularly
|
||||
2. **Log Rotation**: Set up logrotate for application logs
|
||||
3. **Backup Database**: Schedule regular database backups
|
||||
4. **Monitor Disk Space**: Ensure sufficient space for logs and backups
|
||||
|
||||
### Cleanup Old Backups
|
||||
|
||||
```bash
|
||||
# The deployment script automatically cleans old backups
|
||||
# Manual cleanup if needed:
|
||||
find /home/ubuntu/thrillwiki/backups -name "backup_*.commit" -mtime +30 -delete
|
||||
```
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
1. **Use Production WSGI Server**: Consider using Gunicorn instead of development server
|
||||
2. **Reverse Proxy**: Set up Nginx as reverse proxy
|
||||
3. **Database Optimization**: Configure PostgreSQL for production
|
||||
4. **Static Files**: Serve static files through Nginx
|
||||
|
||||
This setup provides a robust CI/CD pipeline for automatic deployment of ThrillWiki to your Linux VM whenever code is pushed to GitHub.
|
||||
Reference in New Issue
Block a user