Skip to content

Latest commit

 

History

History
executable file
·
264 lines (213 loc) · 4.93 KB

DEPLOYMENT.md

File metadata and controls

executable file
·
264 lines (213 loc) · 4.93 KB

Deployment Guide

This guide provides step-by-step instructions for deploying the LeadsFire Voice AI System to a Vultr VPS.

Prerequisites

  • Vultr VPS (1 CPU, 1GB RAM, 25GB NVMe)
  • Domain name (leadsfire.com) pointed to server IP (155.138.252.182)
  • GitHub repository access
  • All API keys and credentials from .env file

Initial Server Setup

  1. SSH into your server:
ssh chris@155.138.252.182
  1. Update system and install required packages:
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3.12 python3.12-venv python3.12-dev build-essential nginx git nodejs npm certbot python3-certbot-nginx ufw
  1. Install PM2:
sudo npm install -g pm2

Firewall Configuration

  1. Set up UFW firewall:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw enable
  1. Allow specific IPs for admin access:
sudo ufw allow from 162.157.115.237 to any port 80,443
sudo ufw allow from 144.202.70.89 to any port 80,443

SSL Certificate Setup

  1. Install SSL certificate:
sudo certbot --nginx -d leadsfire.com -d www.leadsfire.com

Application Deployment

  1. Create application directory:
sudo mkdir -p /var/www/leadsfire
sudo chown chris:chris /var/www/leadsfire
  1. Clone repository:
cd /var/www/leadsfire
git clone https://github.com/clicksmartmedia/leadsfire.com.git .
  1. Set up Python virtual environment:
python3.12 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  1. Create and configure .env file:
cp .env.example .env
nano .env
# Add your production credentials

Nginx Configuration

  1. Create Nginx configuration:
sudo nano /etc/nginx/sites-available/leadsfire.com
  1. Add the following configuration:
server {
    listen 80;
    server_name leadsfire.com www.leadsfire.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name leadsfire.com www.leadsfire.com;

    ssl_certificate /etc/letsencrypt/live/leadsfire.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/leadsfire.com/privkey.pem;

    access_log /var/log/nginx/leadsfire.access.log;
    error_log /var/log/nginx/leadsfire.error.log;

    location / {
        proxy_pass http://127.0.0.1:5001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Allow Twilio webhooks
    location /voice/ {
        proxy_pass http://127.0.0.1:5001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        allow all;
    }

    # Restrict admin endpoints
    location /logs {
        proxy_pass http://127.0.0.1:5001;
        proxy_set_header Host $host;
        allow 162.157.115.237;
        allow 144.202.70.89;
        deny all;
    }
}
  1. Enable the site:
sudo ln -s /etc/nginx/sites-available/leadsfire.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

PM2 Configuration

  1. Create PM2 ecosystem file:
cd /var/www/leadsfire
nano ecosystem.config.js
  1. Add the following configuration:
module.exports = {
  apps: [{
    name: "leadsfire",
    script: "/var/www/leadsfire/venv/bin/python",
    args: "app.py",
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: "750M",
    env: {
      NODE_ENV: "production",
      FLASK_ENV: "production"
    }
  }]
}
  1. Start the application:
pm2 start ecosystem.config.js
pm2 save
pm2 startup

Log Rotation

  1. Create logrotate configuration:
sudo nano /etc/logrotate.d/leadsfire
  1. Add the following configuration:
/var/log/nginx/leadsfire.*.log {
    daily
    rotate 30
    compress
    delaycompress
    notifempty
    create 0640 www-data adm
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

Deployment Updates

To update the application:

  1. Pull latest changes:
cd /var/www/leadsfire
git pull origin main
  1. Install any new dependencies:
source venv/bin/activate
pip install -r requirements.txt
  1. Restart the application:
pm2 restart leadsfire

Monitoring

  1. View application logs:
pm2 logs leadsfire
  1. Monitor application status:
pm2 monit
  1. View Nginx access logs:
sudo tail -f /var/log/nginx/leadsfire.access.log

Backup

MongoDB Atlas handles database backups. For application files:

sudo tar -czf /backup/leadsfire-$(date +%Y%m%d).tar.gz /var/www/leadsfire

Troubleshooting

  1. Check application status:
pm2 status
  1. View error logs:
pm2 logs leadsfire --err
  1. Test Nginx configuration:
sudo nginx -t
  1. Check SSL certificate:
sudo certbot certificates