added deployment scripts
This commit is contained in:
parent
afb40fdc87
commit
e0fdc1d93d
|
|
@ -0,0 +1,60 @@
|
|||
# Root .gitignore for Chitfund Project
|
||||
|
||||
# OS Generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
Desktop.ini
|
||||
|
||||
# IDE and Editor files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
*.code-workspace
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Temporary files
|
||||
*.tmp
|
||||
*.temp
|
||||
*.bak
|
||||
*.backup
|
||||
*~
|
||||
|
||||
# Environment files
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Build directories (general)
|
||||
dist/
|
||||
build/
|
||||
out/
|
||||
|
||||
# Documentation generated files (except committed docs)
|
||||
*.pdf
|
||||
|
||||
# Database files
|
||||
*.db
|
||||
*.sqlite
|
||||
*.sqlite3
|
||||
|
||||
# Archives
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
*.7z
|
||||
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
╔══════════════════════════════════════════════════════════════════════════════╗
|
||||
║ LUCKYCHIT PROXMOX DEPLOYMENT CHEATSHEET ║
|
||||
╚══════════════════════════════════════════════════════════════════════════════╝
|
||||
|
||||
📦 CREATED FILES
|
||||
================================================================================
|
||||
START_HERE.md ← Read this first!
|
||||
PROXMOX_DEPLOYMENT_GUIDE.md ← Complete detailed guide (30-45 min)
|
||||
QUICK_DEPLOY.md ← Quick commands reference
|
||||
DEPLOYMENT_README.md ← Overview & comparison
|
||||
deploy.sh ← Automated setup script
|
||||
CHEATSHEET.txt ← This file!
|
||||
|
||||
|
||||
🚀 FASTEST DEPLOYMENT (3 Commands)
|
||||
================================================================================
|
||||
# 1. On Proxmox host - Create container:
|
||||
pct create 100 local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \
|
||||
--hostname luckychit --memory 2048 --cores 2 --rootfs local-lvm:8 \
|
||||
--net0 name=eth0,bridge=vmbr0,ip=dhcp
|
||||
|
||||
pct start 100 && pct enter 100
|
||||
|
||||
# 2. Inside container - Upload deploy.sh then run:
|
||||
chmod +x deploy.sh && sudo ./deploy.sh
|
||||
|
||||
# 3. Upload your code and deploy:
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
npm install --production && node create-db.js
|
||||
pm2 start src/server.js --name luckychit-api && pm2 save
|
||||
|
||||
cd ../luckychit
|
||||
flutter build web --release
|
||||
sudo cp -r build/web/* /var/www/luckychit/
|
||||
|
||||
|
||||
🔑 IMPORTANT PATHS
|
||||
================================================================================
|
||||
Backend Code: /home/luckychit/apps/chitfund/backend
|
||||
Frontend Code: /home/luckychit/apps/chitfund/luckychit
|
||||
Web Files: /var/www/luckychit
|
||||
Nginx Config: /etc/nginx/sites-available/luckychit
|
||||
Environment: /home/luckychit/apps/chitfund/backend/.env
|
||||
Logs: /home/luckychit/logs/
|
||||
Backups: /home/luckychit/backups/
|
||||
|
||||
|
||||
⚡ ESSENTIAL COMMANDS
|
||||
================================================================================
|
||||
STATUS CHECKS:
|
||||
pm2 status # App status
|
||||
sudo systemctl status nginx # Nginx status
|
||||
sudo systemctl status postgresql # Database status
|
||||
pm2 logs # View app logs
|
||||
curl http://localhost:3000/health # Test API
|
||||
|
||||
RESTART SERVICES:
|
||||
pm2 restart luckychit-api # Restart app
|
||||
sudo systemctl restart nginx # Restart Nginx
|
||||
sudo systemctl restart postgresql # Restart database
|
||||
|
||||
UPDATE APP:
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
git pull && npm install --production && pm2 reload luckychit-api
|
||||
|
||||
cd ../luckychit
|
||||
git pull && flutter build web --release
|
||||
sudo cp -r build/web/* /var/www/luckychit/
|
||||
|
||||
DATABASE:
|
||||
pg_dump -U luckychit -h localhost luckychit > backup.sql # Backup
|
||||
psql -U luckychit -d luckychit -h localhost < backup.sql # Restore
|
||||
sudo -u postgres psql # Admin access
|
||||
|
||||
|
||||
🔍 TROUBLESHOOTING
|
||||
================================================================================
|
||||
Can't access app:
|
||||
sudo ufw status # Check firewall
|
||||
sudo netstat -tulpn | grep 80 # Check if Nginx listening
|
||||
pm2 logs # Check app errors
|
||||
|
||||
Backend won't start:
|
||||
pm2 logs luckychit-api # Check logs
|
||||
cat /home/luckychit/apps/chitfund/backend/.env # Verify config
|
||||
node test-db-connection.js # Test database
|
||||
|
||||
Nginx errors:
|
||||
sudo nginx -t # Test config
|
||||
sudo tail -f /var/log/nginx/error.log # View errors
|
||||
|
||||
Database issues:
|
||||
sudo systemctl status postgresql # Check status
|
||||
sudo -u postgres psql # Connect as admin
|
||||
|
||||
|
||||
📱 ACCESS URLS
|
||||
================================================================================
|
||||
Frontend: http://YOUR_SERVER_IP
|
||||
API: http://YOUR_SERVER_IP/api
|
||||
Health: http://YOUR_SERVER_IP/health
|
||||
|
||||
|
||||
🔐 SECURITY REMINDERS
|
||||
================================================================================
|
||||
✓ Change DB password in .env
|
||||
✓ Use strong JWT_SECRET (32+ chars)
|
||||
✓ Enable firewall: sudo ufw enable
|
||||
✓ Setup SSL: sudo certbot --nginx -d yourdomain.com
|
||||
✓ Never commit .env to git!
|
||||
✓ Test backups: /home/luckychit/backup-db.sh
|
||||
|
||||
|
||||
⏱️ TOTAL DEPLOYMENT TIME: 15-45 minutes (depending on method)
|
||||
|
||||
📖 For detailed instructions, see START_HERE.md
|
||||
|
||||
Good luck! 🚀
|
||||
|
||||
|
|
@ -0,0 +1,382 @@
|
|||
# 📦 LuckyChit Deployment Files
|
||||
|
||||
This directory contains everything you need to deploy your LuckyChit application on Proxmox LXC.
|
||||
|
||||
## 📚 Documentation Files
|
||||
|
||||
### 1. **PROXMOX_DEPLOYMENT_GUIDE.md** ⭐ Main Guide
|
||||
- **Comprehensive step-by-step deployment guide**
|
||||
- Covers everything from LXC creation to production deployment
|
||||
- Includes troubleshooting, security checklist, and maintenance
|
||||
- **Time Required:** 30-45 minutes
|
||||
- **Recommended for:** First-time deployments
|
||||
|
||||
### 2. **QUICK_DEPLOY.md** ⚡ Quick Reference
|
||||
- **Quick command reference for experienced users**
|
||||
- One-liner commands for common operations
|
||||
- Useful paths and troubleshooting commands
|
||||
- **Time Required:** 20-30 minutes
|
||||
- **Recommended for:** Quick deployments or reference
|
||||
|
||||
### 3. **deploy.sh** 🤖 Automated Script
|
||||
- **Automated deployment script**
|
||||
- Installs all prerequisites automatically
|
||||
- Sets up database, users, and configuration
|
||||
- **Time Required:** 10-15 minutes + manual code deployment
|
||||
- **Recommended for:** Fastest deployment
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Which Method Should You Use?
|
||||
|
||||
### Option 1: Automated Script (Fastest) ⚡
|
||||
|
||||
**Best for:** Quick setup, first-time Linux users
|
||||
|
||||
```bash
|
||||
# 1. Create Ubuntu 22.04 LXC on Proxmox
|
||||
# 2. Enter the container
|
||||
pct enter <container-id>
|
||||
|
||||
# 3. Download and run the script
|
||||
curl -o deploy.sh https://raw.githubusercontent.com/YOUR_REPO/deploy.sh
|
||||
chmod +x deploy.sh
|
||||
sudo ./deploy.sh
|
||||
|
||||
# 4. Upload your code and deploy
|
||||
# Follow the on-screen instructions
|
||||
```
|
||||
|
||||
**Pros:**
|
||||
- ✅ Fastest method
|
||||
- ✅ Less room for error
|
||||
- ✅ Automatically configures everything
|
||||
|
||||
**Cons:**
|
||||
- ❌ Less learning opportunity
|
||||
- ❌ Requires internet connection
|
||||
|
||||
---
|
||||
|
||||
### Option 2: Manual Deployment (Learning & Control) 📖
|
||||
|
||||
**Best for:** Understanding the system, custom configurations
|
||||
|
||||
```bash
|
||||
# Follow PROXMOX_DEPLOYMENT_GUIDE.md step-by-step
|
||||
```
|
||||
|
||||
**Pros:**
|
||||
- ✅ Full control over every step
|
||||
- ✅ Better understanding of the system
|
||||
- ✅ Easy to customize
|
||||
- ✅ Learn server administration
|
||||
|
||||
**Cons:**
|
||||
- ❌ Takes longer
|
||||
- ❌ More typing
|
||||
|
||||
---
|
||||
|
||||
### Option 3: Quick Commands (Experienced Users) ⚡
|
||||
|
||||
**Best for:** Experienced admins, subsequent deployments
|
||||
|
||||
```bash
|
||||
# Use QUICK_DEPLOY.md for rapid deployment
|
||||
# Copy-paste command blocks
|
||||
```
|
||||
|
||||
**Pros:**
|
||||
- ✅ Fast for experienced users
|
||||
- ✅ Good for reference
|
||||
- ✅ Flexible
|
||||
|
||||
**Cons:**
|
||||
- ❌ Requires Linux experience
|
||||
- ❌ Easy to miss steps if not careful
|
||||
|
||||
---
|
||||
|
||||
## 🗂️ Project Structure After Deployment
|
||||
|
||||
```
|
||||
/home/luckychit/
|
||||
├── apps/
|
||||
│ └── chitfund/
|
||||
│ ├── backend/ # Node.js backend
|
||||
│ │ ├── src/
|
||||
│ │ ├── .env # Environment variables (KEEP SECURE!)
|
||||
│ │ └── package.json
|
||||
│ └── luckychit/ # Flutter frontend
|
||||
│ ├── lib/
|
||||
│ ├── build/web/ # Built web files
|
||||
│ └── pubspec.yaml
|
||||
├── logs/ # Application logs
|
||||
├── backups/ # Database backups
|
||||
└── backup-db.sh # Backup script
|
||||
|
||||
/var/www/luckychit/ # Nginx web root (Flutter web)
|
||||
/etc/nginx/sites-available/ # Nginx configuration
|
||||
/var/log/nginx/ # Nginx logs
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📋 Deployment Checklist
|
||||
|
||||
### Pre-Deployment
|
||||
- [ ] Proxmox LXC container created (Ubuntu 22.04)
|
||||
- [ ] Container has network access
|
||||
- [ ] You have root/sudo access
|
||||
- [ ] You have your code ready (Git repo or files to upload)
|
||||
|
||||
### During Deployment
|
||||
- [ ] System updated
|
||||
- [ ] Node.js installed (v20)
|
||||
- [ ] PostgreSQL installed and configured
|
||||
- [ ] Nginx installed
|
||||
- [ ] PM2 installed
|
||||
- [ ] Flutter installed (for web build)
|
||||
- [ ] Firewall configured
|
||||
- [ ] Database created with secure password
|
||||
- [ ] Backend code deployed
|
||||
- [ ] Frontend built and deployed
|
||||
- [ ] PM2 configured to auto-start
|
||||
- [ ] Nginx configured correctly
|
||||
|
||||
### Post-Deployment
|
||||
- [ ] Test health endpoint: `curl http://localhost:3000/health`
|
||||
- [ ] Test frontend: Visit `http://YOUR_IP`
|
||||
- [ ] Test API: Try login from frontend
|
||||
- [ ] Check logs: `pm2 logs`
|
||||
- [ ] Setup SSL certificate (Let's Encrypt)
|
||||
- [ ] Configure automated backups
|
||||
- [ ] Document your credentials (securely!)
|
||||
- [ ] Test from external network
|
||||
|
||||
---
|
||||
|
||||
## 🔐 Important Security Notes
|
||||
|
||||
### Immediately After Deployment:
|
||||
|
||||
1. **Change Default Passwords**
|
||||
```bash
|
||||
# PostgreSQL password
|
||||
sudo -u postgres psql
|
||||
ALTER USER luckychit WITH PASSWORD 'new_secure_password';
|
||||
|
||||
# Update .env file accordingly
|
||||
nano /home/luckychit/apps/chitfund/backend/.env
|
||||
```
|
||||
|
||||
2. **Secure JWT Secret**
|
||||
- Generate a strong random secret (32+ characters)
|
||||
- Never commit .env to Git
|
||||
- Use different secrets for dev/staging/production
|
||||
|
||||
3. **Setup SSL/HTTPS**
|
||||
```bash
|
||||
sudo apt install certbot python3-certbot-nginx
|
||||
sudo certbot --nginx -d yourdomain.com
|
||||
```
|
||||
|
||||
4. **Enable Fail2Ban** (Optional but recommended)
|
||||
```bash
|
||||
sudo apt install fail2ban
|
||||
sudo systemctl enable fail2ban
|
||||
sudo systemctl start fail2ban
|
||||
```
|
||||
|
||||
5. **Regular Updates**
|
||||
```bash
|
||||
# Create update script
|
||||
echo '#!/bin/bash' > ~/update-system.sh
|
||||
echo 'apt update && apt upgrade -y' >> ~/update-system.sh
|
||||
chmod +x ~/update-system.sh
|
||||
|
||||
# Run weekly via crontab
|
||||
# 0 3 * * 0 /root/update-system.sh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Common Post-Deployment Tasks
|
||||
|
||||
### Update Application Code
|
||||
|
||||
```bash
|
||||
# Backend
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
git pull
|
||||
npm install --production
|
||||
pm2 reload luckychit-api
|
||||
|
||||
# Frontend
|
||||
cd /home/luckychit/apps/chitfund/luckychit
|
||||
git pull
|
||||
flutter pub get
|
||||
flutter build web --release
|
||||
sudo cp -r build/web/* /var/www/luckychit/
|
||||
```
|
||||
|
||||
### View Logs
|
||||
|
||||
```bash
|
||||
# PM2 logs (backend)
|
||||
pm2 logs luckychit-api
|
||||
|
||||
# Nginx access logs
|
||||
sudo tail -f /var/log/nginx/access.log
|
||||
|
||||
# Nginx error logs
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
|
||||
# PostgreSQL logs
|
||||
sudo tail -f /var/log/postgresql/postgresql-14-main.log
|
||||
```
|
||||
|
||||
### Database Backup & Restore
|
||||
|
||||
```bash
|
||||
# Manual backup
|
||||
pg_dump -U luckychit -h localhost luckychit > backup.sql
|
||||
|
||||
# Restore
|
||||
psql -U luckychit -h localhost luckychit < backup.sql
|
||||
|
||||
# Automated backups are already setup (runs daily at 2 AM)
|
||||
# Check /home/luckychit/backups/
|
||||
```
|
||||
|
||||
### Monitor Resources
|
||||
|
||||
```bash
|
||||
# System resources
|
||||
htop
|
||||
|
||||
# PM2 monitoring
|
||||
pm2 monit
|
||||
|
||||
# Disk space
|
||||
df -h
|
||||
|
||||
# Memory
|
||||
free -h
|
||||
|
||||
# Network connections
|
||||
sudo netstat -tulpn
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🆘 Troubleshooting Quick Guide
|
||||
|
||||
### Backend Won't Start
|
||||
```bash
|
||||
pm2 logs luckychit-api # Check logs
|
||||
node /home/luckychit/apps/chitfund/backend/test-db-connection.js # Test DB
|
||||
cat /home/luckychit/apps/chitfund/backend/.env # Verify config
|
||||
```
|
||||
|
||||
### Can't Access from Browser
|
||||
```bash
|
||||
sudo ufw status # Check firewall
|
||||
sudo systemctl status nginx # Check Nginx
|
||||
sudo nginx -t # Test Nginx config
|
||||
curl http://localhost:3000/health # Test backend locally
|
||||
```
|
||||
|
||||
### Database Connection Issues
|
||||
```bash
|
||||
sudo systemctl status postgresql # Check PostgreSQL
|
||||
sudo -u postgres psql # Try connecting
|
||||
# Inside psql: \l # List databases
|
||||
# Inside psql: \du # List users
|
||||
```
|
||||
|
||||
### Out of Disk Space
|
||||
```bash
|
||||
df -h # Check space
|
||||
du -sh /home/luckychit/* | sort -h # Find large directories
|
||||
pm2 flush # Clear PM2 logs
|
||||
sudo journalctl --vacuum-time=3d # Clear system logs
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📞 Support Resources
|
||||
|
||||
- **Full Guide:** `PROXMOX_DEPLOYMENT_GUIDE.md`
|
||||
- **Quick Commands:** `QUICK_DEPLOY.md`
|
||||
- **Automated Script:** `deploy.sh`
|
||||
|
||||
### External Resources
|
||||
- [Proxmox Documentation](https://pve.proxmox.com/wiki/Main_Page)
|
||||
- [Node.js Documentation](https://nodejs.org/en/docs/)
|
||||
- [Flutter Documentation](https://docs.flutter.dev/)
|
||||
- [PostgreSQL Documentation](https://www.postgresql.org/docs/)
|
||||
- [Nginx Documentation](https://nginx.org/en/docs/)
|
||||
- [PM2 Documentation](https://pm2.keymetrics.io/)
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Success Criteria
|
||||
|
||||
Your deployment is successful when:
|
||||
|
||||
- ✅ Frontend loads in browser: `http://YOUR_IP`
|
||||
- ✅ Health endpoint responds: `http://YOUR_IP/health`
|
||||
- ✅ Can login and use the application
|
||||
- ✅ PM2 shows app running: `pm2 status`
|
||||
- ✅ Nginx is running: `sudo systemctl status nginx`
|
||||
- ✅ Database is accessible: `psql -U luckychit -d luckychit -h localhost`
|
||||
- ✅ Application survives reboot (test with `sudo reboot`)
|
||||
- ✅ Firewall is enabled: `sudo ufw status`
|
||||
- ✅ Automated backups are scheduled: `crontab -l`
|
||||
|
||||
---
|
||||
|
||||
## 📈 Next Steps After Deployment
|
||||
|
||||
1. **Setup Monitoring**
|
||||
- Install monitoring tools (Netdata, Prometheus, etc.)
|
||||
- Setup uptime monitoring (UptimeRobot, etc.)
|
||||
- Configure email alerts
|
||||
|
||||
2. **Performance Optimization**
|
||||
- Enable Nginx caching
|
||||
- Configure database connection pooling
|
||||
- Setup CDN for static assets
|
||||
|
||||
3. **Backup Strategy**
|
||||
- Test backup restoration
|
||||
- Setup off-site backups
|
||||
- Document recovery procedures
|
||||
|
||||
4. **Documentation**
|
||||
- Document your specific configuration
|
||||
- Keep credentials in password manager
|
||||
- Create runbook for common issues
|
||||
|
||||
5. **Team Access**
|
||||
- Create additional user accounts if needed
|
||||
- Setup SSH key authentication
|
||||
- Configure proper permissions
|
||||
|
||||
---
|
||||
|
||||
## 🎉 You're All Set!
|
||||
|
||||
Your LuckyChit application should now be running smoothly on Proxmox LXC.
|
||||
|
||||
**Remember:**
|
||||
- Keep your system updated
|
||||
- Monitor logs regularly
|
||||
- Test backups periodically
|
||||
- Use HTTPS in production
|
||||
- Document any custom changes
|
||||
|
||||
Good luck! 🚀
|
||||
|
||||
|
|
@ -0,0 +1,711 @@
|
|||
# 🚀 LuckyChit Deployment Guide for Proxmox LXC
|
||||
|
||||
Complete step-by-step guide to deploy your LuckyChit application on Proxmox LXC container.
|
||||
|
||||
## 📋 Table of Contents
|
||||
1. [Create LXC Container](#1-create-lxc-container)
|
||||
2. [Initial Setup](#2-initial-setup)
|
||||
3. [Install Prerequisites](#3-install-prerequisites)
|
||||
4. [Deploy Backend (Node.js API)](#4-deploy-backend-nodejs-api)
|
||||
5. [Deploy Frontend (Flutter Web)](#5-deploy-frontend-flutter-web)
|
||||
6. [Configure Nginx](#6-configure-nginx)
|
||||
7. [Setup Process Manager (PM2)](#7-setup-process-manager-pm2)
|
||||
8. [Configure Firewall](#8-configure-firewall)
|
||||
9. [Enable SSL (Optional)](#9-enable-ssl-optional)
|
||||
10. [Monitoring & Maintenance](#10-monitoring--maintenance)
|
||||
|
||||
---
|
||||
|
||||
## 1. Create LXC Container
|
||||
|
||||
### On Proxmox Host:
|
||||
|
||||
```bash
|
||||
# Create Ubuntu 22.04 LXC container
|
||||
pct create 100 local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \
|
||||
--hostname luckychit \
|
||||
--memory 2048 \
|
||||
--swap 512 \
|
||||
--cores 2 \
|
||||
--net0 name=eth0,bridge=vmbr0,ip=dhcp \
|
||||
--storage local-lvm \
|
||||
--rootfs local-lvm:8 \
|
||||
--unprivileged 1 \
|
||||
--features nesting=1
|
||||
|
||||
# Start the container
|
||||
pct start 100
|
||||
|
||||
# Enter the container
|
||||
pct enter 100
|
||||
```
|
||||
|
||||
**Note:** Adjust container ID (100), memory, and network settings based on your environment.
|
||||
|
||||
---
|
||||
|
||||
## 2. Initial Setup
|
||||
|
||||
### Update System
|
||||
|
||||
```bash
|
||||
apt update && apt upgrade -y
|
||||
apt install -y curl wget git nano ufw
|
||||
```
|
||||
|
||||
### Create Application User
|
||||
|
||||
```bash
|
||||
# Create a user for running the application
|
||||
adduser --disabled-password --gecos "" luckychit
|
||||
usermod -aG sudo luckychit
|
||||
|
||||
# Switch to the new user
|
||||
su - luckychit
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Install Prerequisites
|
||||
|
||||
### Install Node.js (v20 LTS)
|
||||
|
||||
```bash
|
||||
# Install Node.js via NodeSource
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||
sudo apt install -y nodejs
|
||||
|
||||
# Verify installation
|
||||
node --version # Should show v20.x.x
|
||||
npm --version
|
||||
```
|
||||
|
||||
### Install PostgreSQL
|
||||
|
||||
```bash
|
||||
# Install PostgreSQL
|
||||
sudo apt install -y postgresql postgresql-contrib
|
||||
|
||||
# Start and enable PostgreSQL
|
||||
sudo systemctl start postgresql
|
||||
sudo systemctl enable postgresql
|
||||
|
||||
# Verify PostgreSQL is running
|
||||
sudo systemctl status postgresql
|
||||
```
|
||||
|
||||
### Configure PostgreSQL
|
||||
|
||||
```bash
|
||||
# Switch to postgres user
|
||||
sudo -u postgres psql
|
||||
|
||||
# In PostgreSQL prompt, run:
|
||||
CREATE DATABASE luckychit;
|
||||
CREATE USER luckychit WITH PASSWORD 'your_secure_password_here';
|
||||
GRANT ALL PRIVILEGES ON DATABASE luckychit TO luckychit;
|
||||
\q
|
||||
```
|
||||
|
||||
### Install Nginx
|
||||
|
||||
```bash
|
||||
sudo apt install -y nginx
|
||||
sudo systemctl start nginx
|
||||
sudo systemctl enable nginx
|
||||
```
|
||||
|
||||
### Install PM2 (Process Manager)
|
||||
|
||||
```bash
|
||||
sudo npm install -g pm2
|
||||
```
|
||||
|
||||
### Install Flutter (for building web app)
|
||||
|
||||
```bash
|
||||
# Install Flutter dependencies
|
||||
sudo apt install -y clang cmake ninja-build pkg-config libgtk-3-dev
|
||||
|
||||
# Download Flutter
|
||||
cd /opt
|
||||
sudo git clone https://github.com/flutter/flutter.git -b stable
|
||||
sudo chown -R luckychit:luckychit /opt/flutter
|
||||
|
||||
# Add Flutter to PATH
|
||||
echo 'export PATH="$PATH:/opt/flutter/bin"' >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
|
||||
# Verify Flutter installation
|
||||
flutter doctor
|
||||
|
||||
# Enable Flutter web
|
||||
flutter config --enable-web
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Deploy Backend (Node.js API)
|
||||
|
||||
### Clone or Upload Your Project
|
||||
|
||||
```bash
|
||||
# Create application directory
|
||||
mkdir -p /home/luckychit/apps
|
||||
cd /home/luckychit/apps
|
||||
|
||||
# Option 1: Clone from Git
|
||||
git clone <your-repo-url> chitfund
|
||||
cd chitfund/backend
|
||||
|
||||
# Option 2: Upload via SCP (from your local machine)
|
||||
# scp -r C:\Users\sunde\workspace\chitfund luckychit@<container-ip>:/home/luckychit/apps/
|
||||
```
|
||||
|
||||
### Configure Backend
|
||||
|
||||
```bash
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
|
||||
# Copy environment file
|
||||
cp env.example .env
|
||||
|
||||
# Edit .env file with production settings
|
||||
nano .env
|
||||
```
|
||||
|
||||
**Edit `.env` file:**
|
||||
|
||||
```env
|
||||
# Server Configuration
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
|
||||
# Database Configuration
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_NAME=luckychit
|
||||
DB_USER=luckychit
|
||||
DB_PASSWORD=your_secure_password_here
|
||||
DATABASE_URL=postgresql://luckychit:your_secure_password_here@localhost:5432/luckychit
|
||||
|
||||
# JWT Configuration (CHANGE THIS!)
|
||||
JWT_SECRET=your-super-secure-random-jwt-secret-minimum-32-characters-long
|
||||
JWT_EXPIRES_IN=24h
|
||||
|
||||
# CORS Configuration (Update with your domain)
|
||||
ALLOWED_ORIGINS=https://yourdomain.com,http://yourdomain.com
|
||||
|
||||
# Rate Limiting
|
||||
RATE_LIMIT_WINDOW_MS=900000
|
||||
RATE_LIMIT_MAX_REQUESTS=100
|
||||
|
||||
# Logging
|
||||
LOG_LEVEL=info
|
||||
```
|
||||
|
||||
### Install Dependencies and Initialize Database
|
||||
|
||||
```bash
|
||||
# Install Node.js dependencies
|
||||
npm install --production
|
||||
|
||||
# Test database connection
|
||||
node test-db-connection.js
|
||||
|
||||
# Initialize database
|
||||
node create-db.js
|
||||
```
|
||||
|
||||
### Test Backend
|
||||
|
||||
```bash
|
||||
# Start backend temporarily
|
||||
npm start
|
||||
|
||||
# In another terminal, test the health endpoint
|
||||
curl http://localhost:3000/health
|
||||
|
||||
# If working, stop it (Ctrl+C) - we'll use PM2 next
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Deploy Frontend (Flutter Web)
|
||||
|
||||
### Build Flutter Web App
|
||||
|
||||
```bash
|
||||
cd /home/luckychit/apps/chitfund/luckychit
|
||||
|
||||
# Get dependencies
|
||||
flutter pub get
|
||||
|
||||
# Update API endpoint in your Flutter app
|
||||
# Edit lib/core/constants/api_constants.dart or similar file
|
||||
nano lib/core/network/api_client.dart
|
||||
|
||||
# Build for web
|
||||
flutter build web --release
|
||||
|
||||
# The built files will be in build/web/
|
||||
```
|
||||
|
||||
**Note:** Make sure to update the API base URL in your Flutter app to point to your server's domain or IP before building.
|
||||
|
||||
### Deploy Web Files
|
||||
|
||||
```bash
|
||||
# Create web directory
|
||||
sudo mkdir -p /var/www/luckychit
|
||||
|
||||
# Copy built files
|
||||
sudo cp -r build/web/* /var/www/luckychit/
|
||||
|
||||
# Set permissions
|
||||
sudo chown -R www-data:www-data /var/www/luckychit
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Configure Nginx
|
||||
|
||||
### Create Nginx Configuration
|
||||
|
||||
```bash
|
||||
sudo nano /etc/nginx/sites-available/luckychit
|
||||
```
|
||||
|
||||
**Add this configuration:**
|
||||
|
||||
```nginx
|
||||
# Backend API Server
|
||||
server {
|
||||
listen 80;
|
||||
server_name api.yourdomain.com; # Or use your IP
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
|
||||
# API reverse proxy
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
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;
|
||||
|
||||
# Timeouts
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 60s;
|
||||
}
|
||||
|
||||
# Health check endpoint
|
||||
location /health {
|
||||
proxy_pass http://localhost:3000/health;
|
||||
access_log off;
|
||||
}
|
||||
}
|
||||
|
||||
# Frontend Web App
|
||||
server {
|
||||
listen 80;
|
||||
server_name yourdomain.com www.yourdomain.com; # Or use your IP
|
||||
|
||||
root /var/www/luckychit;
|
||||
index index.html;
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_types text/plain text/css text/xml text/javascript
|
||||
application/x-javascript application/xml+rss
|
||||
application/javascript application/json;
|
||||
|
||||
# Flutter web app routing
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Cache static assets
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Don't cache index.html
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Enable Site and Test
|
||||
|
||||
```bash
|
||||
# Enable the site
|
||||
sudo ln -s /etc/nginx/sites-available/luckychit /etc/nginx/sites-enabled/
|
||||
|
||||
# Remove default site
|
||||
sudo rm /etc/nginx/sites-enabled/default
|
||||
|
||||
# Test Nginx configuration
|
||||
sudo nginx -t
|
||||
|
||||
# Reload Nginx
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. Setup Process Manager (PM2)
|
||||
|
||||
### Create PM2 Ecosystem File
|
||||
|
||||
```bash
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
nano ecosystem.config.js
|
||||
```
|
||||
|
||||
**Add this configuration:**
|
||||
|
||||
```javascript
|
||||
module.exports = {
|
||||
apps: [{
|
||||
name: 'luckychit-api',
|
||||
script: 'src/server.js',
|
||||
cwd: '/home/luckychit/apps/chitfund/backend',
|
||||
instances: 2, // Use 2 instances for load balancing
|
||||
exec_mode: 'cluster',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
},
|
||||
error_file: '/home/luckychit/logs/api-error.log',
|
||||
out_file: '/home/luckychit/logs/api-out.log',
|
||||
log_file: '/home/luckychit/logs/api-combined.log',
|
||||
time: true,
|
||||
autorestart: true,
|
||||
max_memory_restart: '500M',
|
||||
watch: false,
|
||||
}]
|
||||
};
|
||||
```
|
||||
|
||||
### Create Log Directory
|
||||
|
||||
```bash
|
||||
mkdir -p /home/luckychit/logs
|
||||
```
|
||||
|
||||
### Start Application with PM2
|
||||
|
||||
```bash
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
|
||||
# Start application
|
||||
pm2 start ecosystem.config.js
|
||||
|
||||
# Check status
|
||||
pm2 status
|
||||
|
||||
# View logs
|
||||
pm2 logs luckychit-api
|
||||
|
||||
# Setup PM2 to start on system boot
|
||||
pm2 startup systemd -u luckychit --hp /home/luckychit
|
||||
# Run the command it outputs
|
||||
|
||||
# Save PM2 configuration
|
||||
pm2 save
|
||||
```
|
||||
|
||||
### PM2 Useful Commands
|
||||
|
||||
```bash
|
||||
# Status
|
||||
pm2 status
|
||||
|
||||
# Logs
|
||||
pm2 logs
|
||||
pm2 logs luckychit-api --lines 100
|
||||
|
||||
# Restart
|
||||
pm2 restart luckychit-api
|
||||
|
||||
# Stop
|
||||
pm2 stop luckychit-api
|
||||
|
||||
# Monitor
|
||||
pm2 monit
|
||||
|
||||
# Reload (zero-downtime restart)
|
||||
pm2 reload luckychit-api
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. Configure Firewall
|
||||
|
||||
```bash
|
||||
# Enable UFW
|
||||
sudo ufw enable
|
||||
|
||||
# Allow SSH (IMPORTANT!)
|
||||
sudo ufw allow 22/tcp
|
||||
|
||||
# Allow HTTP and HTTPS
|
||||
sudo ufw allow 80/tcp
|
||||
sudo ufw allow 443/tcp
|
||||
|
||||
# Check status
|
||||
sudo ufw status
|
||||
|
||||
# Enable firewall
|
||||
sudo ufw enable
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. Enable SSL (Optional but Recommended)
|
||||
|
||||
### Using Let's Encrypt (Free SSL)
|
||||
|
||||
```bash
|
||||
# Install Certbot
|
||||
sudo apt install -y certbot python3-certbot-nginx
|
||||
|
||||
# Get SSL certificate (replace with your domain)
|
||||
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com -d api.yourdomain.com
|
||||
|
||||
# Test auto-renewal
|
||||
sudo certbot renew --dry-run
|
||||
```
|
||||
|
||||
The Certbot will automatically update your Nginx configuration to use HTTPS.
|
||||
|
||||
---
|
||||
|
||||
## 10. Monitoring & Maintenance
|
||||
|
||||
### Check Application Status
|
||||
|
||||
```bash
|
||||
# PM2 status
|
||||
pm2 status
|
||||
|
||||
# Nginx status
|
||||
sudo systemctl status nginx
|
||||
|
||||
# PostgreSQL status
|
||||
sudo systemctl status postgresql
|
||||
|
||||
# View backend logs
|
||||
pm2 logs luckychit-api
|
||||
|
||||
# View Nginx access logs
|
||||
sudo tail -f /var/log/nginx/access.log
|
||||
|
||||
# View Nginx error logs
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
```
|
||||
|
||||
### Database Backup Script
|
||||
|
||||
```bash
|
||||
# Create backup directory
|
||||
mkdir -p /home/luckychit/backups
|
||||
|
||||
# Create backup script
|
||||
nano /home/luckychit/backup-db.sh
|
||||
```
|
||||
|
||||
**Add this content:**
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
BACKUP_DIR="/home/luckychit/backups"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
FILENAME="luckychit_backup_$DATE.sql"
|
||||
|
||||
pg_dump -U luckychit -h localhost luckychit > "$BACKUP_DIR/$FILENAME"
|
||||
gzip "$BACKUP_DIR/$FILENAME"
|
||||
|
||||
# Keep only last 7 days of backups
|
||||
find $BACKUP_DIR -name "luckychit_backup_*.sql.gz" -mtime +7 -delete
|
||||
|
||||
echo "Backup completed: $FILENAME.gz"
|
||||
```
|
||||
|
||||
```bash
|
||||
# Make it executable
|
||||
chmod +x /home/luckychit/backup-db.sh
|
||||
|
||||
# Add to crontab for daily backups at 2 AM
|
||||
crontab -e
|
||||
|
||||
# Add this line:
|
||||
0 2 * * * /home/luckychit/backup-db.sh
|
||||
```
|
||||
|
||||
### Update Application
|
||||
|
||||
```bash
|
||||
# Navigate to backend
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
|
||||
# Pull latest changes (if using Git)
|
||||
git pull
|
||||
|
||||
# Install any new dependencies
|
||||
npm install --production
|
||||
|
||||
# Reload application with zero downtime
|
||||
pm2 reload luckychit-api
|
||||
|
||||
# For frontend updates
|
||||
cd /home/luckychit/apps/chitfund/luckychit
|
||||
git pull
|
||||
flutter pub get
|
||||
flutter build web --release
|
||||
sudo cp -r build/web/* /var/www/luckychit/
|
||||
```
|
||||
|
||||
### Monitor Resources
|
||||
|
||||
```bash
|
||||
# View system resources
|
||||
htop
|
||||
|
||||
# View disk usage
|
||||
df -h
|
||||
|
||||
# View memory usage
|
||||
free -h
|
||||
|
||||
# View PM2 monitoring
|
||||
pm2 monit
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📱 Access Your Application
|
||||
|
||||
After deployment:
|
||||
|
||||
- **Frontend:** `http://your-server-ip` or `http://yourdomain.com`
|
||||
- **Backend API:** `http://your-server-ip:3000` or `http://api.yourdomain.com`
|
||||
- **Health Check:** `http://your-server-ip/health`
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Troubleshooting
|
||||
|
||||
### Backend Not Starting
|
||||
|
||||
```bash
|
||||
# Check logs
|
||||
pm2 logs luckychit-api
|
||||
|
||||
# Check if port 3000 is in use
|
||||
sudo netstat -tulpn | grep 3000
|
||||
|
||||
# Test database connection
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
node test-db-connection.js
|
||||
|
||||
# Check .env file
|
||||
cat .env
|
||||
```
|
||||
|
||||
### Nginx Errors
|
||||
|
||||
```bash
|
||||
# Test configuration
|
||||
sudo nginx -t
|
||||
|
||||
# Check error logs
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
|
||||
# Restart Nginx
|
||||
sudo systemctl restart nginx
|
||||
```
|
||||
|
||||
### Database Issues
|
||||
|
||||
```bash
|
||||
# Check PostgreSQL status
|
||||
sudo systemctl status postgresql
|
||||
|
||||
# Restart PostgreSQL
|
||||
sudo systemctl restart postgresql
|
||||
|
||||
# Connect to database
|
||||
psql -U luckychit -d luckychit -h localhost
|
||||
|
||||
# Check database logs
|
||||
sudo tail -f /var/log/postgresql/postgresql-14-main.log
|
||||
```
|
||||
|
||||
### Can't Access from Outside
|
||||
|
||||
```bash
|
||||
# Check firewall
|
||||
sudo ufw status
|
||||
|
||||
# Check if services are listening
|
||||
sudo netstat -tulpn | grep :80
|
||||
sudo netstat -tulpn | grep :3000
|
||||
|
||||
# Check Nginx is running
|
||||
sudo systemctl status nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔐 Security Checklist
|
||||
|
||||
- ✅ Change default PostgreSQL password
|
||||
- ✅ Use strong JWT secret (32+ characters)
|
||||
- ✅ Enable UFW firewall
|
||||
- ✅ Keep .env file secure (never commit to git)
|
||||
- ✅ Enable SSL/HTTPS with Let's Encrypt
|
||||
- ✅ Regular database backups
|
||||
- ✅ Keep system updated: `sudo apt update && sudo apt upgrade`
|
||||
- ✅ Monitor logs regularly
|
||||
- ✅ Use fail2ban to prevent brute force attacks (optional)
|
||||
|
||||
---
|
||||
|
||||
## 📚 Additional Resources
|
||||
|
||||
- [Proxmox LXC Documentation](https://pve.proxmox.com/wiki/Linux_Container)
|
||||
- [PM2 Documentation](https://pm2.keymetrics.io/docs/usage/quick-start/)
|
||||
- [Nginx Documentation](https://nginx.org/en/docs/)
|
||||
- [Flutter Web Deployment](https://docs.flutter.dev/deployment/web)
|
||||
- [PostgreSQL Documentation](https://www.postgresql.org/docs/)
|
||||
|
||||
---
|
||||
|
||||
## 🆘 Need Help?
|
||||
|
||||
Common issues:
|
||||
1. **Port already in use:** Check with `sudo netstat -tulpn | grep <port>`
|
||||
2. **Permission denied:** Check file ownership and permissions
|
||||
3. **Cannot connect to database:** Verify PostgreSQL is running and credentials are correct
|
||||
4. **404 errors:** Check Nginx configuration and file paths
|
||||
|
||||
Good luck with your deployment! 🚀
|
||||
|
||||
|
|
@ -0,0 +1,223 @@
|
|||
# 🚀 Quick Deployment Reference
|
||||
|
||||
Quick commands for deploying LuckyChit on Proxmox LXC.
|
||||
|
||||
## 🎯 One-Command Setup (After LXC Creation)
|
||||
|
||||
```bash
|
||||
# Run this inside your LXC container as root
|
||||
curl -o- https://raw.githubusercontent.com/YOUR_REPO/deploy.sh | bash
|
||||
```
|
||||
|
||||
Or follow the manual steps below:
|
||||
|
||||
---
|
||||
|
||||
## ⚡ Quick Manual Setup
|
||||
|
||||
### 1. Initial Setup (5 minutes)
|
||||
|
||||
```bash
|
||||
# Update system
|
||||
apt update && apt upgrade -y
|
||||
apt install -y curl wget git nano ufw
|
||||
|
||||
# Create user
|
||||
adduser --disabled-password --gecos "" luckychit
|
||||
usermod -aG sudo luckychit
|
||||
su - luckychit
|
||||
```
|
||||
|
||||
### 2. Install Stack (10 minutes)
|
||||
|
||||
```bash
|
||||
# Node.js
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||
sudo apt install -y nodejs
|
||||
|
||||
# PostgreSQL
|
||||
sudo apt install -y postgresql postgresql-contrib nginx
|
||||
sudo npm install -g pm2
|
||||
|
||||
# Flutter
|
||||
cd /opt
|
||||
sudo git clone https://github.com/flutter/flutter.git -b stable
|
||||
sudo chown -R luckychit:luckychit /opt/flutter
|
||||
echo 'export PATH="$PATH:/opt/flutter/bin"' >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
flutter config --enable-web
|
||||
```
|
||||
|
||||
### 3. Setup Database (2 minutes)
|
||||
|
||||
```bash
|
||||
sudo -u postgres psql << EOF
|
||||
CREATE DATABASE luckychit;
|
||||
CREATE USER luckychit WITH PASSWORD 'ChangeMe123!';
|
||||
GRANT ALL PRIVILEGES ON DATABASE luckychit TO luckychit;
|
||||
\q
|
||||
EOF
|
||||
```
|
||||
|
||||
### 4. Deploy Backend (5 minutes)
|
||||
|
||||
```bash
|
||||
mkdir -p /home/luckychit/apps
|
||||
cd /home/luckychit/apps
|
||||
|
||||
# Upload your code or clone from git
|
||||
# Then:
|
||||
cd chitfund/backend
|
||||
cp env.example .env
|
||||
nano .env # Update passwords and secrets
|
||||
npm install --production
|
||||
node create-db.js
|
||||
pm2 start src/server.js --name luckychit-api
|
||||
pm2 save
|
||||
```
|
||||
|
||||
### 5. Deploy Frontend (5 minutes)
|
||||
|
||||
```bash
|
||||
cd /home/luckychit/apps/chitfund/luckychit
|
||||
flutter pub get
|
||||
flutter build web --release
|
||||
sudo mkdir -p /var/www/luckychit
|
||||
sudo cp -r build/web/* /var/www/luckychit/
|
||||
sudo chown -R www-data:www-data /var/www/luckychit
|
||||
```
|
||||
|
||||
### 6. Configure Nginx (3 minutes)
|
||||
|
||||
```bash
|
||||
sudo nano /etc/nginx/sites-available/luckychit
|
||||
# Paste config from main guide
|
||||
sudo ln -s /etc/nginx/sites-available/luckychit /etc/nginx/sites-enabled/
|
||||
sudo rm /etc/nginx/sites-enabled/default
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
### 7. Enable Firewall (1 minute)
|
||||
|
||||
```bash
|
||||
sudo ufw allow 22/tcp
|
||||
sudo ufw allow 80/tcp
|
||||
sudo ufw allow 443/tcp
|
||||
sudo ufw enable
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Common Operations
|
||||
|
||||
### Check Status
|
||||
```bash
|
||||
pm2 status # Application status
|
||||
sudo systemctl status nginx # Nginx status
|
||||
sudo systemctl status postgresql # Database status
|
||||
pm2 logs # View logs
|
||||
```
|
||||
|
||||
### Restart Services
|
||||
```bash
|
||||
pm2 restart luckychit-api # Restart API
|
||||
sudo systemctl restart nginx # Restart Nginx
|
||||
sudo systemctl restart postgresql # Restart Database
|
||||
```
|
||||
|
||||
### Update Application
|
||||
```bash
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
git pull
|
||||
npm install --production
|
||||
pm2 reload luckychit-api
|
||||
|
||||
cd /home/luckychit/apps/chitfund/luckychit
|
||||
git pull
|
||||
flutter pub get
|
||||
flutter build web --release
|
||||
sudo cp -r build/web/* /var/www/luckychit/
|
||||
```
|
||||
|
||||
### Backup Database
|
||||
```bash
|
||||
pg_dump -U luckychit -h localhost luckychit > backup_$(date +%Y%m%d).sql
|
||||
```
|
||||
|
||||
### Restore Database
|
||||
```bash
|
||||
psql -U luckychit -h localhost luckychit < backup_20241105.sql
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔍 Troubleshooting Commands
|
||||
|
||||
```bash
|
||||
# Check if services are running
|
||||
sudo netstat -tulpn | grep :80 # Check Nginx
|
||||
sudo netstat -tulpn | grep :3000 # Check API
|
||||
|
||||
# View logs
|
||||
pm2 logs luckychit-api --lines 50
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
sudo tail -f /var/log/postgresql/postgresql-14-main.log
|
||||
|
||||
# Test database connection
|
||||
psql -U luckychit -d luckychit -h localhost
|
||||
|
||||
# Test API
|
||||
curl http://localhost:3000/health
|
||||
|
||||
# Check disk space
|
||||
df -h
|
||||
|
||||
# Check memory
|
||||
free -h
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📝 Important Files & Paths
|
||||
|
||||
| Item | Path |
|
||||
|------|------|
|
||||
| Backend Code | `/home/luckychit/apps/chitfund/backend` |
|
||||
| Frontend Code | `/home/luckychit/apps/chitfund/luckychit` |
|
||||
| Web Files | `/var/www/luckychit` |
|
||||
| Nginx Config | `/etc/nginx/sites-available/luckychit` |
|
||||
| Backend Logs | `pm2 logs` or `/home/luckychit/logs/` |
|
||||
| Nginx Logs | `/var/log/nginx/` |
|
||||
| Environment | `/home/luckychit/apps/chitfund/backend/.env` |
|
||||
| Backups | `/home/luckychit/backups/` |
|
||||
|
||||
---
|
||||
|
||||
## 🔐 Security Reminders
|
||||
|
||||
```bash
|
||||
# Change these in .env:
|
||||
JWT_SECRET=<random-32-character-string>
|
||||
DB_PASSWORD=<strong-password>
|
||||
|
||||
# Never commit .env to git!
|
||||
# Always use HTTPS in production
|
||||
# Setup regular backups
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📱 Access URLs
|
||||
|
||||
After deployment:
|
||||
- Frontend: `http://YOUR_IP` or `http://yourdomain.com`
|
||||
- API: `http://YOUR_IP/api` or `http://api.yourdomain.com`
|
||||
- Health: `http://YOUR_IP/health`
|
||||
|
||||
---
|
||||
|
||||
## ⏱️ Total Setup Time: ~30 minutes
|
||||
|
||||
Good luck! 🎉
|
||||
|
||||
|
|
@ -0,0 +1,260 @@
|
|||
# 🚀 START HERE - LuckyChit Deployment
|
||||
|
||||
## 📁 What Files Were Created?
|
||||
|
||||
I've created deployment documentation for your LuckyChit app:
|
||||
|
||||
| File | Purpose | When to Use |
|
||||
|------|---------|-------------|
|
||||
| **PROXMOX_DEPLOYMENT_GUIDE.md** | Complete detailed guide | First time deployment |
|
||||
| **QUICK_DEPLOY.md** | Quick command reference | Quick reference / updates |
|
||||
| **deploy.sh** | Automated setup script | Fastest automated setup |
|
||||
| **DEPLOYMENT_README.md** | Overview & comparison | Understanding options |
|
||||
| **START_HERE.md** | This file - Quick start | Right now! |
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Choose Your Path
|
||||
|
||||
### 🤖 Option 1: Automated (Recommended for Beginners)
|
||||
|
||||
**Time: ~15 minutes**
|
||||
|
||||
1. Create Ubuntu 22.04 LXC container in Proxmox
|
||||
2. Upload `deploy.sh` to the container
|
||||
3. Run: `sudo bash deploy.sh`
|
||||
4. Upload your code and follow on-screen instructions
|
||||
|
||||
### 📖 Option 2: Manual Step-by-Step
|
||||
|
||||
**Time: ~30-45 minutes**
|
||||
|
||||
Follow **PROXMOX_DEPLOYMENT_GUIDE.md** for complete instructions
|
||||
|
||||
### ⚡ Option 3: Quick Commands (For Experts)
|
||||
|
||||
**Time: ~20 minutes**
|
||||
|
||||
Use **QUICK_DEPLOY.md** for copy-paste commands
|
||||
|
||||
---
|
||||
|
||||
## 🏃 Fastest Way to Deploy (5 Steps)
|
||||
|
||||
### Step 1: Create LXC Container on Proxmox
|
||||
|
||||
```bash
|
||||
# On Proxmox host
|
||||
pct create 100 local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \
|
||||
--hostname luckychit \
|
||||
--memory 2048 \
|
||||
--cores 2 \
|
||||
--net0 name=eth0,bridge=vmbr0,ip=dhcp \
|
||||
--rootfs local-lvm:8
|
||||
|
||||
pct start 100
|
||||
pct enter 100
|
||||
```
|
||||
|
||||
### Step 2: Upload & Run Deploy Script
|
||||
|
||||
```bash
|
||||
# Upload deploy.sh to container, then:
|
||||
chmod +x deploy.sh
|
||||
./deploy.sh
|
||||
|
||||
# Follow the prompts:
|
||||
# - Enter database password
|
||||
# - Enter JWT secret (random 32+ characters)
|
||||
# - Enter domain name (optional)
|
||||
# - Enter server IP
|
||||
```
|
||||
|
||||
### Step 3: Upload Your Code
|
||||
|
||||
```bash
|
||||
# From your Windows machine:
|
||||
scp -r C:\Users\sunde\workspace\chitfund luckychit@<container-ip>:/home/luckychit/apps/
|
||||
|
||||
# Or using Git inside container:
|
||||
cd /home/luckychit/apps
|
||||
git clone <your-repo-url> chitfund
|
||||
```
|
||||
|
||||
### Step 4: Deploy Backend
|
||||
|
||||
```bash
|
||||
cd /home/luckychit/apps/chitfund/backend
|
||||
npm install --production
|
||||
node create-db.js
|
||||
pm2 start src/server.js --name luckychit-api
|
||||
pm2 startup systemd -u luckychit --hp /home/luckychit
|
||||
pm2 save
|
||||
```
|
||||
|
||||
### Step 5: Deploy Frontend
|
||||
|
||||
```bash
|
||||
cd /home/luckychit/apps/chitfund/luckychit
|
||||
|
||||
# Update API endpoint first!
|
||||
# Edit the file that contains your API URL
|
||||
# Change it to: http://<your-server-ip>:3000 or https://api.yourdomain.com
|
||||
|
||||
flutter pub get
|
||||
flutter build web --release
|
||||
sudo cp -r build/web/* /var/www/luckychit/
|
||||
```
|
||||
|
||||
### ✅ Test Your Deployment
|
||||
|
||||
```bash
|
||||
# Check if everything is running
|
||||
pm2 status
|
||||
sudo systemctl status nginx
|
||||
curl http://localhost:3000/health
|
||||
|
||||
# Access from browser:
|
||||
# Frontend: http://<your-server-ip>
|
||||
# API Health: http://<your-server-ip>/health
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📋 What You Need Before Starting
|
||||
|
||||
### Information
|
||||
- [ ] Your Proxmox host IP/access
|
||||
- [ ] Server IP address for the LXC container
|
||||
- [ ] Domain name (optional, for SSL)
|
||||
- [ ] Strong password for database (16+ characters)
|
||||
- [ ] Random JWT secret (32+ characters)
|
||||
|
||||
### Tools (Optional - for uploading files)
|
||||
- [ ] WinSCP or FileZilla (for file transfers)
|
||||
- [ ] PuTTY or Windows Terminal (for SSH)
|
||||
|
||||
### Generate Secure Secrets
|
||||
|
||||
```powershell
|
||||
# On Windows PowerShell, generate random secrets:
|
||||
|
||||
# Database Password (16 characters)
|
||||
-join ((48..57) + (65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_})
|
||||
|
||||
# JWT Secret (32 characters)
|
||||
-join ((48..57) + (65..90) + (97..122) | Get-Random -Count 32 | % {[char]$_})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎓 Learning Path
|
||||
|
||||
### Complete Beginner?
|
||||
1. Read **DEPLOYMENT_README.md** first (understand options)
|
||||
2. Follow **PROXMOX_DEPLOYMENT_GUIDE.md** step-by-step
|
||||
3. Keep **QUICK_DEPLOY.md** for future reference
|
||||
|
||||
### Some Experience?
|
||||
1. Skim **DEPLOYMENT_README.md**
|
||||
2. Use **deploy.sh** for automated setup
|
||||
3. Reference **QUICK_DEPLOY.md** when needed
|
||||
|
||||
### Expert User?
|
||||
1. Use **QUICK_DEPLOY.md** directly
|
||||
2. Reference **PROXMOX_DEPLOYMENT_GUIDE.md** for specifics
|
||||
|
||||
---
|
||||
|
||||
## 🆘 Something Wrong?
|
||||
|
||||
### Deploy Script Fails
|
||||
- Check internet connection
|
||||
- Make sure you're running as root: `sudo bash deploy.sh`
|
||||
- Check logs for specific errors
|
||||
|
||||
### Can't Access Application
|
||||
- Check firewall: `sudo ufw status`
|
||||
- Check services: `pm2 status` and `sudo systemctl status nginx`
|
||||
- Check ports: `sudo netstat -tulpn | grep -E '(80|3000)'`
|
||||
|
||||
### Database Issues
|
||||
- Verify PostgreSQL is running: `sudo systemctl status postgresql`
|
||||
- Test connection: `psql -U luckychit -d luckychit -h localhost`
|
||||
- Check credentials in `.env` file
|
||||
|
||||
### More Help Needed?
|
||||
- See **Troubleshooting** section in **PROXMOX_DEPLOYMENT_GUIDE.md**
|
||||
- Check logs: `pm2 logs`, `sudo tail -f /var/log/nginx/error.log`
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Security Checklist
|
||||
|
||||
After deployment, verify:
|
||||
|
||||
- [ ] Firewall is enabled and configured
|
||||
- [ ] Strong database password set
|
||||
- [ ] Unique JWT secret configured
|
||||
- [ ] `.env` file has correct permissions (600)
|
||||
- [ ] SSL/HTTPS enabled (for production)
|
||||
- [ ] Regular backups scheduled
|
||||
- [ ] All default passwords changed
|
||||
|
||||
---
|
||||
|
||||
## 📞 Quick Reference
|
||||
|
||||
| Task | Command |
|
||||
|------|---------|
|
||||
| Check status | `pm2 status` |
|
||||
| View logs | `pm2 logs` |
|
||||
| Restart app | `pm2 restart luckychit-api` |
|
||||
| Update code | `git pull && npm install && pm2 reload luckychit-api` |
|
||||
| Backup DB | `/home/luckychit/backup-db.sh` |
|
||||
| Check nginx | `sudo systemctl status nginx` |
|
||||
|
||||
---
|
||||
|
||||
## 🎉 Ready to Deploy?
|
||||
|
||||
1. Pick your deployment method above
|
||||
2. Gather required information
|
||||
3. Follow the steps
|
||||
4. Test your application
|
||||
5. Setup SSL (recommended for production)
|
||||
|
||||
**Estimated Time:** 15-45 minutes depending on method
|
||||
|
||||
Good luck! Your LuckyChit app will be live soon! 🚀
|
||||
|
||||
---
|
||||
|
||||
## 📚 Documentation Structure
|
||||
|
||||
```
|
||||
START_HERE.md (You are here!)
|
||||
├── Quick overview and decision guide
|
||||
├──
|
||||
DEPLOYMENT_README.md
|
||||
│ ├── Compare deployment methods
|
||||
│ ├── Post-deployment tasks
|
||||
│ └── Troubleshooting overview
|
||||
│
|
||||
PROXMOX_DEPLOYMENT_GUIDE.md
|
||||
│ ├── Complete step-by-step guide
|
||||
│ ├── Detailed explanations
|
||||
│ ├── Troubleshooting details
|
||||
│ └── Maintenance procedures
|
||||
│
|
||||
QUICK_DEPLOY.md
|
||||
│ ├── Quick command reference
|
||||
│ ├── Common operations
|
||||
│ └── Useful paths
|
||||
│
|
||||
deploy.sh
|
||||
└── Automated deployment script
|
||||
```
|
||||
|
||||
**Tip:** Bookmark this structure for future reference!
|
||||
|
||||
|
|
@ -1,44 +1,139 @@
|
|||
# Node.js Backend .gitignore
|
||||
|
||||
# Dependencies
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Environment variables
|
||||
.env
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.*.local
|
||||
|
||||
# Logs
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids/
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov/
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage/
|
||||
*.lcov
|
||||
.nyc_output/
|
||||
|
||||
# Grunt intermediate storage
|
||||
.grunt/
|
||||
|
||||
# Bower dependency directory
|
||||
bower_components/
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons
|
||||
build/Release/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# parcel-bundler cache
|
||||
.cache/
|
||||
.parcel-cache/
|
||||
|
||||
# Next.js build output
|
||||
.next/
|
||||
out/
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt/
|
||||
dist/
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist/
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test/
|
||||
|
||||
# Database files
|
||||
*.db
|
||||
*.sqlite
|
||||
*.sqlite3
|
||||
|
||||
# OS files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
Thumbs.db
|
||||
Desktop.ini
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
# Uploads and user content (if applicable)
|
||||
uploads/
|
||||
public/uploads/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
**/doc/api/
|
||||
**/ios/Flutter/.last_build_id
|
||||
.dart_tool/
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
.pub-cache/
|
||||
.pub/
|
||||
/build/
|
||||
|
||||
# Symbolication related
|
||||
app.*.symbols
|
||||
|
||||
# Obfuscation related
|
||||
app.*.map.json
|
||||
|
||||
# Android Studio will place build artifacts here
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
/node_modules
|
||||
# Backup files
|
||||
*.bak
|
||||
*.backup
|
||||
*.tmp
|
||||
|
|
|
|||
|
|
@ -0,0 +1,334 @@
|
|||
#!/bin/bash
|
||||
|
||||
###############################################################################
|
||||
# LuckyChit Automated Deployment Script for Proxmox LXC
|
||||
# Author: LuckyChit Team
|
||||
# Description: Automates the deployment of LuckyChit app on Ubuntu LXC
|
||||
###############################################################################
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Functions
|
||||
print_info() {
|
||||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}✅ $1${NC}"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}❌ $1${NC}"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
echo ""
|
||||
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${GREEN}║ LuckyChit Deployment Script for Proxmox LXC ║${NC}"
|
||||
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
check_root() {
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
print_error "Please run as root or with sudo"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Main Installation
|
||||
###############################################################################
|
||||
|
||||
print_header
|
||||
|
||||
# Check if running as root
|
||||
check_root
|
||||
|
||||
# Get configuration from user
|
||||
print_info "Starting interactive setup..."
|
||||
echo ""
|
||||
|
||||
read -p "Enter database password for PostgreSQL: " DB_PASSWORD
|
||||
read -p "Enter JWT secret (min 32 characters): " JWT_SECRET
|
||||
read -p "Enter your domain name (or press Enter to skip): " DOMAIN_NAME
|
||||
read -p "Enter your server IP address: " SERVER_IP
|
||||
|
||||
echo ""
|
||||
print_info "Configuration received. Starting installation..."
|
||||
echo ""
|
||||
|
||||
###############################################################################
|
||||
# 1. System Update
|
||||
###############################################################################
|
||||
print_info "Step 1/10: Updating system..."
|
||||
apt update && apt upgrade -y
|
||||
apt install -y curl wget git nano ufw htop postgresql postgresql-contrib nginx
|
||||
print_success "System updated"
|
||||
|
||||
###############################################################################
|
||||
# 2. Create Application User
|
||||
###############################################################################
|
||||
print_info "Step 2/10: Creating application user..."
|
||||
if id "luckychit" &>/dev/null; then
|
||||
print_warning "User 'luckychit' already exists"
|
||||
else
|
||||
adduser --disabled-password --gecos "" luckychit
|
||||
usermod -aG sudo luckychit
|
||||
print_success "User 'luckychit' created"
|
||||
fi
|
||||
|
||||
###############################################################################
|
||||
# 3. Install Node.js
|
||||
###############################################################################
|
||||
print_info "Step 3/10: Installing Node.js v20..."
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||
apt install -y nodejs
|
||||
print_success "Node.js $(node --version) installed"
|
||||
|
||||
###############################################################################
|
||||
# 4. Install PM2
|
||||
###############################################################################
|
||||
print_info "Step 4/10: Installing PM2..."
|
||||
npm install -g pm2
|
||||
print_success "PM2 installed"
|
||||
|
||||
###############################################################################
|
||||
# 5. Setup PostgreSQL
|
||||
###############################################################################
|
||||
print_info "Step 5/10: Configuring PostgreSQL..."
|
||||
systemctl start postgresql
|
||||
systemctl enable postgresql
|
||||
|
||||
sudo -u postgres psql << EOF
|
||||
CREATE DATABASE luckychit;
|
||||
CREATE USER luckychit WITH PASSWORD '$DB_PASSWORD';
|
||||
GRANT ALL PRIVILEGES ON DATABASE luckychit TO luckychit;
|
||||
EOF
|
||||
|
||||
print_success "PostgreSQL configured"
|
||||
|
||||
###############################################################################
|
||||
# 6. Install Flutter
|
||||
###############################################################################
|
||||
print_info "Step 6/10: Installing Flutter..."
|
||||
apt install -y clang cmake ninja-build pkg-config libgtk-3-dev unzip
|
||||
|
||||
if [ ! -d "/opt/flutter" ]; then
|
||||
cd /opt
|
||||
git clone https://github.com/flutter/flutter.git -b stable
|
||||
chown -R luckychit:luckychit /opt/flutter
|
||||
print_success "Flutter installed"
|
||||
else
|
||||
print_warning "Flutter already installed"
|
||||
fi
|
||||
|
||||
# Add Flutter to PATH for all users
|
||||
if ! grep -q "flutter/bin" /etc/profile.d/flutter.sh 2>/dev/null; then
|
||||
echo 'export PATH="$PATH:/opt/flutter/bin"' > /etc/profile.d/flutter.sh
|
||||
chmod +x /etc/profile.d/flutter.sh
|
||||
fi
|
||||
|
||||
export PATH="$PATH:/opt/flutter/bin"
|
||||
flutter config --enable-web
|
||||
|
||||
print_success "Flutter configured for web"
|
||||
|
||||
###############################################################################
|
||||
# 7. Create Directory Structure
|
||||
###############################################################################
|
||||
print_info "Step 7/10: Creating directory structure..."
|
||||
mkdir -p /home/luckychit/apps
|
||||
mkdir -p /home/luckychit/logs
|
||||
mkdir -p /home/luckychit/backups
|
||||
chown -R luckychit:luckychit /home/luckychit
|
||||
|
||||
print_success "Directories created"
|
||||
|
||||
###############################################################################
|
||||
# 8. Setup Firewall
|
||||
###############################################################################
|
||||
print_info "Step 8/10: Configuring firewall..."
|
||||
ufw --force enable
|
||||
ufw allow 22/tcp
|
||||
ufw allow 80/tcp
|
||||
ufw allow 443/tcp
|
||||
print_success "Firewall configured"
|
||||
|
||||
###############################################################################
|
||||
# 9. Setup Nginx (Basic Config)
|
||||
###############################################################################
|
||||
print_info "Step 9/10: Configuring Nginx..."
|
||||
|
||||
cat > /etc/nginx/sites-available/luckychit << 'NGINX_EOF'
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://localhost:3000/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
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;
|
||||
}
|
||||
|
||||
location /health {
|
||||
proxy_pass http://localhost:3000/health;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location / {
|
||||
root /var/www/luckychit;
|
||||
index index.html;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
root /var/www/luckychit;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
NGINX_EOF
|
||||
|
||||
ln -sf /etc/nginx/sites-available/luckychit /etc/nginx/sites-enabled/
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
nginx -t && systemctl reload nginx
|
||||
print_success "Nginx configured"
|
||||
|
||||
###############################################################################
|
||||
# 10. Create .env Template
|
||||
###############################################################################
|
||||
print_info "Step 10/10: Creating environment file template..."
|
||||
|
||||
mkdir -p /home/luckychit/apps/chitfund/backend
|
||||
|
||||
cat > /home/luckychit/apps/chitfund/backend/.env << ENV_EOF
|
||||
# Server Configuration
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
|
||||
# Database Configuration
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_NAME=luckychit
|
||||
DB_USER=luckychit
|
||||
DB_PASSWORD=$DB_PASSWORD
|
||||
DATABASE_URL=postgresql://luckychit:$DB_PASSWORD@localhost:5432/luckychit
|
||||
|
||||
# JWT Configuration
|
||||
JWT_SECRET=$JWT_SECRET
|
||||
JWT_EXPIRES_IN=24h
|
||||
|
||||
# CORS Configuration
|
||||
ALLOWED_ORIGINS=http://$SERVER_IP,https://$DOMAIN_NAME
|
||||
|
||||
# Rate Limiting
|
||||
RATE_LIMIT_WINDOW_MS=900000
|
||||
RATE_LIMIT_MAX_REQUESTS=100
|
||||
|
||||
# Logging
|
||||
LOG_LEVEL=info
|
||||
ENV_EOF
|
||||
|
||||
chown luckychit:luckychit /home/luckychit/apps/chitfund/backend/.env
|
||||
chmod 600 /home/luckychit/apps/chitfund/backend/.env
|
||||
|
||||
print_success "Environment file created"
|
||||
|
||||
###############################################################################
|
||||
# Create Backup Script
|
||||
###############################################################################
|
||||
print_info "Creating backup script..."
|
||||
|
||||
cat > /home/luckychit/backup-db.sh << 'BACKUP_EOF'
|
||||
#!/bin/bash
|
||||
BACKUP_DIR="/home/luckychit/backups"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
FILENAME="luckychit_backup_$DATE.sql"
|
||||
|
||||
pg_dump -U luckychit -h localhost luckychit > "$BACKUP_DIR/$FILENAME"
|
||||
gzip "$BACKUP_DIR/$FILENAME"
|
||||
|
||||
# Keep only last 7 days of backups
|
||||
find $BACKUP_DIR -name "luckychit_backup_*.sql.gz" -mtime +7 -delete
|
||||
|
||||
echo "Backup completed: $FILENAME.gz"
|
||||
BACKUP_EOF
|
||||
|
||||
chmod +x /home/luckychit/backup-db.sh
|
||||
chown luckychit:luckychit /home/luckychit/backup-db.sh
|
||||
|
||||
# Add to crontab for luckychit user
|
||||
(crontab -u luckychit -l 2>/dev/null; echo "0 2 * * * /home/luckychit/backup-db.sh") | crontab -u luckychit -
|
||||
|
||||
print_success "Backup script created (runs daily at 2 AM)"
|
||||
|
||||
###############################################################################
|
||||
# Installation Complete
|
||||
###############################################################################
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${GREEN}║ Installation Complete! 🎉 ║${NC}"
|
||||
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
|
||||
print_success "LuckyChit infrastructure is ready!"
|
||||
echo ""
|
||||
print_info "Next Steps:"
|
||||
echo ""
|
||||
echo " 1. Upload your application code to:"
|
||||
echo " /home/luckychit/apps/chitfund/"
|
||||
echo ""
|
||||
echo " 2. Deploy the backend:"
|
||||
echo " cd /home/luckychit/apps/chitfund/backend"
|
||||
echo " npm install --production"
|
||||
echo " node create-db.js"
|
||||
echo " pm2 start src/server.js --name luckychit-api"
|
||||
echo " pm2 startup systemd -u luckychit --hp /home/luckychit"
|
||||
echo " pm2 save"
|
||||
echo ""
|
||||
echo " 3. Build and deploy the frontend:"
|
||||
echo " cd /home/luckychit/apps/chitfund/luckychit"
|
||||
echo " flutter pub get"
|
||||
echo " flutter build web --release"
|
||||
echo " sudo cp -r build/web/* /var/www/luckychit/"
|
||||
echo ""
|
||||
echo " 4. Access your application:"
|
||||
echo " Frontend: http://$SERVER_IP"
|
||||
echo " API Health: http://$SERVER_IP/health"
|
||||
echo ""
|
||||
echo " 5. (Optional) Setup SSL:"
|
||||
echo " apt install certbot python3-certbot-nginx"
|
||||
echo " certbot --nginx -d $DOMAIN_NAME"
|
||||
echo ""
|
||||
|
||||
print_warning "Important: Review and update the .env file at:"
|
||||
print_warning "/home/luckychit/apps/chitfund/backend/.env"
|
||||
echo ""
|
||||
|
||||
print_info "Documentation available at:"
|
||||
echo " - Full Guide: PROXMOX_DEPLOYMENT_GUIDE.md"
|
||||
echo " - Quick Reference: QUICK_DEPLOY.md"
|
||||
echo ""
|
||||
|
||||
print_success "Deployment script completed successfully!"
|
||||
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
# Flutter/Dart .gitignore
|
||||
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
|
|
@ -41,3 +43,96 @@ app.*.map.json
|
|||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
|
||||
# Web related
|
||||
/web/flutter_service_worker.js
|
||||
/web/manifest.json
|
||||
|
||||
# Coverage
|
||||
coverage/
|
||||
|
||||
# Exceptions to above rules (allow some Flutter generated files)
|
||||
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
|
||||
|
||||
# Environment files
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Generated files
|
||||
*.g.dart
|
||||
*.freezed.dart
|
||||
*.mocks.dart
|
||||
|
||||
# Build outputs
|
||||
*.apk
|
||||
*.aab
|
||||
*.ipa
|
||||
*.app
|
||||
|
||||
# Key files (IMPORTANT - never commit these)
|
||||
*.jks
|
||||
*.keystore
|
||||
*.p12
|
||||
*.key
|
||||
*.pem
|
||||
android/key.properties
|
||||
ios/Runner/GoogleService-Info.plist
|
||||
android/app/google-services.json
|
||||
|
||||
# Local configuration
|
||||
**/local.properties
|
||||
**/GeneratedPluginRegistrant.*
|
||||
|
||||
# iOS related
|
||||
**/ios/Pods/
|
||||
**/ios/.symlinks/
|
||||
**/ios/Flutter/Flutter.framework
|
||||
**/ios/Flutter/Flutter.podspec
|
||||
**/ios/ServiceDefinitions.json
|
||||
**/ios/Runner/GeneratedPluginRegistrant.*
|
||||
**/ios/**/*.mode1v3
|
||||
**/ios/**/*.mode2v3
|
||||
**/ios/**/*.moved-aside
|
||||
**/ios/**/*.pbxuser
|
||||
**/ios/**/*.perspectivev3
|
||||
**/ios/**/*sync/
|
||||
**/ios/.sconsign.dblite
|
||||
**/ios/.tags*
|
||||
**/ios/.vagrant/
|
||||
**/ios/DerivedData/
|
||||
**/ios/Icon?
|
||||
**/ios/Pods/
|
||||
**/ios/profile
|
||||
**/ios/xcuserdata/
|
||||
**/ios/.generated/
|
||||
|
||||
# macOS related
|
||||
**/macos/Pods/
|
||||
**/macos/Flutter/ephemeral/
|
||||
**/macos/Flutter/Flutter-Debug.xcconfig
|
||||
**/macos/Flutter/Flutter-Release.xcconfig
|
||||
**/macos/xcuserdata/
|
||||
|
||||
# Android related
|
||||
**/android/.gradle/
|
||||
**/android/captures/
|
||||
**/android/gradlew
|
||||
**/android/gradlew.bat
|
||||
**/android/local.properties
|
||||
**/android/**/GeneratedPluginRegistrant.java
|
||||
**/android/.cxx/
|
||||
|
||||
# Windows related
|
||||
**/windows/flutter/ephemeral/
|
||||
|
||||
# Linux related
|
||||
**/linux/flutter/ephemeral/
|
||||
|
||||
# Node modules (if using any JS tooling)
|
||||
node_modules/
|
||||
|
||||
# Backup files
|
||||
*.bak
|
||||
*.backup
|
||||
*.tmp
|
||||
|
|
|
|||
Loading…
Reference in New Issue