π Deployment Guide
This guide will help you deploy your Fantasy Football Newsletter application to your domain using Kamal.
Prerequisites
- Domain Name - You need a domain name pointing to your server
- VPS/Server - A server with Docker installed (Ubuntu 20.04+ recommended)
- Docker Hub Account - For storing your Docker images
- SSH Access - To your server
Step 1: Prepare Your Domain
- Point your domain to your server:
- Add an A record pointing your domain to your serverβs IP address
- Example:
yourdomain.com
βYOUR_SERVER_IP
- Wait for DNS propagation (can take up to 48 hours, usually much faster)
Step 2: Update Configuration
- Edit
config/deploy.yml
:# Replace YOUR_DOMAIN_HERE.com with your actual domain proxy: ssl: true host: yourdomain.com # Replace your-dockerhub-username with your actual Docker Hub username image: your-dockerhub-username/newsletter username: your-dockerhub-username
- Update server IP:
# Replace 192.168.0.1 with your actual server IP servers: web: - YOUR_SERVER_IP
Step 3: Set Up Docker Hub
- Create a Docker Hub account (if you donβt have one)
- Create an access token:
- Go to Docker Hub β Account Settings β Security
- Create a new access token
- Copy the token
- Set the environment variable:
export KAMAL_REGISTRY_PASSWORD=your_docker_hub_access_token
Step 4: Prepare Your Server
- SSH into your server:
ssh root@YOUR_SERVER_IP
- Install Docker:
curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh
- Install Kamal:
curl -fsSL https://raw.githubusercontent.com/basecamp/kamal/main/bin/kamal | bash
- Set up SSH keys (if not already done):
# On your local machine ssh-copy-id root@YOUR_SERVER_IP
Step 5: Deploy Your Application
- Build and deploy:
# Build the Docker image and push to registry bin/kamal deploy
- Monitor the deployment:
# Check deployment status bin/kamal status # View logs bin/kamal logs
Step 6: Set Up Database
- Run database migrations:
bin/kamal app exec bin/rails db:migrate
- Seed the database:
bin/kamal app exec bin/rails db:seed
Step 7: Verify Deployment
- Visit your domain:
https://yourdomain.com
- Check SSL certificate - Letβs Encrypt should automatically provision SSL
- Test all features - Make sure everything works as expected
Troubleshooting
Common Issues
- SSL Certificate Issues:
# Check SSL status bin/kamal app exec openssl s_client -connect localhost:443
- Database Issues:
# Access Rails console bin/kamal console # Check database connection bin/kamal app exec bin/rails dbconsole
- Logs and Debugging:
# View application logs bin/kamal logs # Access server shell bin/kamal shell
Useful Commands
# Restart the application
bin/kamal restart
# Rollback to previous version
bin/kamal rollback
# Update environment variables
bin/kamal env set RAILS_LOG_LEVEL=debug
# Access Rails console
bin/kamal console
# View server status
bin/kamal status
Environment Variables
You can set additional environment variables in config/deploy.yml
:
env:
clear:
RAILS_LOG_LEVEL: info
WEB_CONCURRENCY: 2
JOB_CONCURRENCY: 1
Security Considerations
- Keep your
config/master.key
secure - Never commit it to git - Use strong passwords for your Docker Hub access token
- Regular updates - Keep your server and application updated
- Backup your database regularly
Monitoring
- Set up monitoring for your application
- Monitor server resources (CPU, memory, disk)
- Set up alerts for downtime or errors
Next Steps
- Set up automated backups
- Configure monitoring and alerts
- Set up CI/CD pipeline for automatic deployments
- Optimize performance based on usage patterns
Your application should now be live at https://yourdomain.com
! π