This project is containerized with Docker and supports automatic failover to a cloud VPS when the Cloudflare Tunnel goes offline.
- Primary Hosting: Home server with Cloudflare Tunnel
- Failover Hosting: AWS t3.micro VPS
- Container Registry: AWS ECR (Elastic Container Registry)
- Container Runtime: Docker + Docker Compose
- CI/CD: GitHub Actions for automated builds and deployments
- Failover System: Automatic detection and recovery
- Docker and Docker Compose
- Node.js 20+ (for local development)
- Python 3.11+ (for local development)
- AWS CLI (configured with appropriate permissions)
# Install dependencies
npm install
# Run in development mode
npm run dev
# In a separate terminal, run the Python backend
python run.py --devdocker build -t mindofshaun:latest .docker-compose up -dThe application is automatically built and deployed through GitHub Actions when changes are pushed to the main branch.
# Login to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <your-aws-account-id>.dkr.ecr.us-east-1.amazonaws.com
# Pull the latest image
docker pull <your-aws-account-id>.dkr.ecr.us-east-1.amazonaws.com/mindofshaun:latest
# Start the container
docker-compose up -dscripts/monitor.sh: Monitors the Cloudflare tunnel statusscripts/failover.sh: Triggers failover to AWS when tunnel is downscripts/recovery.sh: Recovers back to primary server when tunnel is restored
- Copy the scripts to
/opt/mindofshaun/scripts/on both primary and failover servers - Make the scripts executable:
chmod +x /opt/mindofshaun/scripts/*.sh - Install the systemd service:
cp scripts/cloudflare-monitor.service /etc/systemd/system/ systemctl daemon-reload systemctl enable cloudflare-monitor systemctl start cloudflare-monitor
Create a configuration file at /etc/failover.conf with the following variables:
# AWS Configuration
AWS_INSTANCE_ID="i-xxxxxxxxxxxxx"
AWS_REGION="us-east-1"
ECR_REGISTRY="<your-aws-account-id>.dkr.ecr.us-east-1.amazonaws.com"
ECR_REPOSITORY="mindofshaun"
# Cloudflare Configuration
CLOUDFLARE_ZONE_ID="your_zone_id"
CLOUDFLARE_API_TOKEN="your_api_token"
DNS_RECORD_ID="your_dns_record_id"
TUNNEL_HOSTNAME="your_tunnel_hostname"
# SSH Configuration
SSH_KEY_PATH="/path/to/ssh/key"To set up the AWS ECR repository:
-
Create an ECR repository:
aws ecr create-repository --repository-name mindofshaun --region us-east-1
-
Set up an IAM user or role with appropriate permissions:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage", "ecr:BatchCheckLayerAvailability", "ecr:PutImage", "ecr:InitiateLayerUpload", "ecr:UploadLayerPart", "ecr:CompleteLayerUpload" ], "Resource": "arn:aws:ecr:us-east-1:*:repository/mindofshaun" }, { "Effect": "Allow", "Action": "ecr:GetAuthorizationToken", "Resource": "*" } ] } -
Add these credentials to your GitHub repository secrets:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_REGION
- ECR_REPOSITORY
The application exposes a health check endpoint at /health that returns the service status.
This project is licensed under the MIT License - see the LICENSE file for details.