mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-04-17 20:36:00 +00:00
Docs: Update README with Proxmox deployment guide and add deployment scripts
This commit is contained in:
211
PROXMOX_DEPLOY_TEMPLATE.md
Normal file
211
PROXMOX_DEPLOY_TEMPLATE.md
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
# 🚀 Proxmox Deployment Template (TurnKey Node.js)
|
||||||
|
|
||||||
|
**Use this guide to deploy ANY Node.js application to a TurnKey Linux LXC Container.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 Prerequisites
|
||||||
|
|
||||||
|
1. **Project**: A Node.js application (Express, Next.js, etc.) in a Git repository.
|
||||||
|
2. **Server**: A Proxmox TurnKey Node.js Container.
|
||||||
|
3. **Access**: Root SSH password for the container.
|
||||||
|
4. **Domain (Optional)**: If using Cloudflare Tunnel.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ Step 1: Prepare Your Project
|
||||||
|
|
||||||
|
Ensure your project is ready for production:
|
||||||
|
|
||||||
|
1. **Port Configuration**: Ensure your app listens on a configurable port or a fixed internal port (e.g., `4001`).
|
||||||
|
```javascript
|
||||||
|
// server.js
|
||||||
|
const PORT = process.env.PORT || 4001;
|
||||||
|
app.listen(PORT, ...);
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Git Ignore**: Ensure `node_modules` and config files with secrets are ignored.
|
||||||
|
```gitignore
|
||||||
|
node_modules/
|
||||||
|
.env
|
||||||
|
config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🖥️ Step 2: One-Time Server Setup
|
||||||
|
|
||||||
|
SSH into your new container:
|
||||||
|
```bash
|
||||||
|
ssh root@<YOUR_SERVER_IP>
|
||||||
|
```
|
||||||
|
|
||||||
|
Run these commands to prepare the environment:
|
||||||
|
|
||||||
|
### 1. Install Essentials
|
||||||
|
```bash
|
||||||
|
apt-get update && apt-get install -y git
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Prepare Directory
|
||||||
|
```bash
|
||||||
|
# Standard web directory
|
||||||
|
mkdir -p /var/www/<APP_NAME>
|
||||||
|
cd /var/www/<APP_NAME>
|
||||||
|
|
||||||
|
# Clone your repo (Use Basic Auth with Token if private)
|
||||||
|
# Format: https://<USER>:<TOKEN>@github.com/<ORG>/<REPO>.git
|
||||||
|
git clone <YOUR_REPO_URL> .
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Setup Permissions
|
||||||
|
```bash
|
||||||
|
# Give ownership to www-data (Nginx user)
|
||||||
|
chown -R www-data:www-data /var/www/<APP_NAME>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚙️ Step 3: Application Configuration
|
||||||
|
|
||||||
|
### 1. Systemd Service
|
||||||
|
Create a service file to keep your app running.
|
||||||
|
|
||||||
|
Create `/etc/systemd/system/<APP_NAME>.service`:
|
||||||
|
```ini
|
||||||
|
[Unit]
|
||||||
|
Description=<APP_NAME> Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=root
|
||||||
|
# OR use 'www-data' if app doesn't need root ports
|
||||||
|
# User=www-data
|
||||||
|
WorkingDirectory=/var/www/<APP_NAME>
|
||||||
|
ExecStart=/usr/local/bin/node server.js
|
||||||
|
Restart=always
|
||||||
|
Environment=NODE_ENV=production
|
||||||
|
Environment=PORT=4001
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
Enable and start:
|
||||||
|
```bash
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable <APP_NAME>
|
||||||
|
systemctl start <APP_NAME>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Nginx Reverse Proxy
|
||||||
|
Configure Nginx to forward port 80 to your app (Port 4001).
|
||||||
|
|
||||||
|
Create `/etc/nginx/sites-available/<APP_NAME>`:
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
root /var/www/<APP_NAME>;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# Serve static files (Optional)
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Proxy API/Dynamic requests
|
||||||
|
location /api {
|
||||||
|
proxy_pass http://localhost:4001;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Enable site:
|
||||||
|
```bash
|
||||||
|
# Remove defaults
|
||||||
|
rm -f /etc/nginx/sites-enabled/default
|
||||||
|
rm -f /etc/nginx/sites-enabled/nodejs
|
||||||
|
|
||||||
|
# Link new site
|
||||||
|
ln -s /etc/nginx/sites-available/<APP_NAME> /etc/nginx/sites-enabled/
|
||||||
|
|
||||||
|
# Reload
|
||||||
|
nginx -t && systemctl reload nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ☁️ Step 4: Cloudflare Tunnel (Secure Access)
|
||||||
|
|
||||||
|
Expose your app securely without opening router ports.
|
||||||
|
|
||||||
|
### 1. Install Cloudflared
|
||||||
|
```bash
|
||||||
|
# Add Key
|
||||||
|
mkdir -p --mode=0755 /usr/share/keyrings
|
||||||
|
curl -fsSL https://pkg.cloudflare.com/cloudflare-public-v2.gpg | tee /usr/share/keyrings/cloudflare-public-v2.gpg >/dev/null
|
||||||
|
|
||||||
|
# Add Repo
|
||||||
|
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-public-v2.gpg] https://pkg.cloudflare.com/cloudflared any main' | tee /etc/apt/sources.list.d/cloudflared.list
|
||||||
|
|
||||||
|
# Install
|
||||||
|
apt-get update && apt-get install -y cloudflared
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Create Tunnel
|
||||||
|
```bash
|
||||||
|
cloudflared tunnel login
|
||||||
|
cloudflared tunnel create <TUNNEL_NAME>
|
||||||
|
# Follow on-screen instructions to map domain -> http://localhost:4001
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 Step 5: Automated Updates (PowerShell)
|
||||||
|
|
||||||
|
Create a script `deploy-remote.ps1` in your project root to automate updates.
|
||||||
|
|
||||||
|
**Pre-requisite**: Create `deploy-config.json` (Add to .gitignore!):
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"host": "<SERVER_IP>",
|
||||||
|
"username": "root",
|
||||||
|
"password": "<SSH_PASSWORD>",
|
||||||
|
"remotePath": "/var/www/<APP_NAME>"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Script `deploy-remote.ps1`**:
|
||||||
|
```powershell
|
||||||
|
# Reads config and updates remote server
|
||||||
|
$Config = Get-Content "deploy-config.json" | ConvertFrom-Json
|
||||||
|
$User = $Config.username; $HostName = $Config.host; $Pass = $Config.password
|
||||||
|
$RemotePath = $Config.remotePath
|
||||||
|
|
||||||
|
# Commands to run remotely
|
||||||
|
$Cmds = "
|
||||||
|
cd $RemotePath
|
||||||
|
echo '⬇️ Pulling code...'
|
||||||
|
git pull
|
||||||
|
echo '📦 Installing deps...'
|
||||||
|
npm install
|
||||||
|
echo '🚀 Restarting service...'
|
||||||
|
systemctl restart <APP_NAME>
|
||||||
|
systemctl status <APP_NAME> --no-pager
|
||||||
|
"
|
||||||
|
|
||||||
|
echo y | plink -ssh -t -pw $Pass "$User@$HostName" $Cmds
|
||||||
|
```
|
||||||
|
|
||||||
|
**Usage**: Just run `./deploy-remote.ps1` to deploy!
|
||||||
54
README.md
54
README.md
@@ -156,34 +156,54 @@ The server will start on **http://localhost:3000**
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🚀 Production Deployment
|
## 🚀 Production Deployment (Proxmox + TurnKey Linux)
|
||||||
|
|
||||||
We support **Zero-Downtime Reliability** and **Auto-Start**.
|
We recommend using a **Proxmox TurnKey Node.js Container** for production.
|
||||||
|
|
||||||
### 1. Automated Deployment
|
### ✅ 1. One-Click Remote Deployment (Windows)
|
||||||
Use our deployment script to setup Nginx/Apache and Node.js automatically:
|
Easily deploy from your local Windows machine to the remote server using the included PowerShell script.
|
||||||
|
|
||||||
```bash
|
**Pre-requisite:** Create `deploy-config.json` in your project root (this file is ignored by git):
|
||||||
sudo bash deploy.sh
|
```json
|
||||||
|
{
|
||||||
|
"host": "172.16.69.214",
|
||||||
|
"username": "root",
|
||||||
|
"password": "YOUR_SSH_PASSWORD",
|
||||||
|
"remotePath": "/var/www/connect5",
|
||||||
|
"gitToken": "YOUR_GITHUB_TOKEN"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. Auto-Start on Reboot (Systemd)
|
**To Deploy or Update:**
|
||||||
Never worry about server restarts again. Install the systemd service:
|
```powershell
|
||||||
|
.\deploy-remote.ps1
|
||||||
```bash
|
|
||||||
sudo bash setup-auto-start.sh
|
|
||||||
```
|
```
|
||||||
*This ensures the app starts automatically and waits for the database to be ready.*
|
*This script automatically updates code, installs dependencies, and restarts the service.*
|
||||||
|
|
||||||
### 3. Auto-Deploy (Git Hooks)
|
### 🔄 2. Automated Updates (Cron Job)
|
||||||
Enable automatic updates when you `git pull`:
|
The server is configured to **automatically pull updates from GitHub every 5 minutes**.
|
||||||
|
- **No changes?** Nothing happens.
|
||||||
|
- **New code?** The server pulls changes, runs `npm install`, and restarts the app using the `post-merge` hook.
|
||||||
|
|
||||||
|
### 🛡️ 3. Cloudflare Tunnel (Secure Access)
|
||||||
|
The application is securely exposed using a Cloudflare Tunnel, eliminating the need to open router ports.
|
||||||
|
|
||||||
|
**Service Status:**
|
||||||
```bash
|
```bash
|
||||||
bash setup-auto-deploy.sh
|
systemctl status connect5
|
||||||
```
|
```
|
||||||
*This installs a hook to restart the service automatically after code changes.*
|
|
||||||
|
|
||||||
See [DEPLOYMENT.md](DEPLOYMENT.md) for full details.
|
**Logs:**
|
||||||
|
```bash
|
||||||
|
journalctl -u connect5 -f
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔒 4. Security & Configuration
|
||||||
|
- **Systemd**: The app runs as a `systemd` service (`connect5`), ensuring it auto-starts on boot.
|
||||||
|
- **Nginx**: Configured as a reverse proxy on Port 80.
|
||||||
|
- **Secrets**: Database credentials are stored in `db.config.js` and excluded from source control.
|
||||||
|
|
||||||
|
See [PROXMOX_DEPLOY_TEMPLATE.md](PROXMOX_DEPLOY_TEMPLATE.md) for the manual setup guide.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
53
deploy-remote.ps1
Normal file
53
deploy-remote.ps1
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Automated Update Script for Vendor Inventory (Remote)
|
||||||
|
.DESCRIPTION
|
||||||
|
Reads configuration from deploy-config.json.
|
||||||
|
Connects to the remote server, pulls the latest code, installs dependencies, and restarts the service.
|
||||||
|
#>
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$ConfigPath = Join-Path $PSScriptRoot "deploy-config.json"
|
||||||
|
|
||||||
|
if (-not (Test-Path $ConfigPath)) {
|
||||||
|
Write-Error "Configuration file not found: $ConfigPath"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$Config = Get-Content $ConfigPath | ConvertFrom-Json
|
||||||
|
$HostName = $Config.host
|
||||||
|
$User = $Config.username
|
||||||
|
$Password = $Config.password
|
||||||
|
$RemotePath = $Config.remotePath
|
||||||
|
|
||||||
|
Write-Host "Connecting to $User@$HostName for update..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# Check for plink
|
||||||
|
if (-not (Get-Command "plink" -ErrorAction SilentlyContinue)) {
|
||||||
|
Write-Error "Plink (PuTTY Link) is required but not found. Please install PuTTY."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Commands to run on remote
|
||||||
|
$RemoteCommands = "
|
||||||
|
echo '📂 Navigating to $RemotePath...'
|
||||||
|
cd $RemotePath
|
||||||
|
|
||||||
|
echo '⬇️ Pulling latest changes...'
|
||||||
|
git pull
|
||||||
|
|
||||||
|
echo '📦 Installing dependencies...'
|
||||||
|
npm install
|
||||||
|
|
||||||
|
echo '🚀 Restarting Service...'
|
||||||
|
systemctl restart connect5
|
||||||
|
|
||||||
|
echo '✅ Status Check:'
|
||||||
|
systemctl status connect5 --no-pager
|
||||||
|
"
|
||||||
|
|
||||||
|
# Execute
|
||||||
|
$RemoteCommands = $RemoteCommands -replace "`r`n", "`n"
|
||||||
|
echo y | plink -ssh -P 22 -t -pw $Password "$User@$HostName" $RemoteCommands
|
||||||
|
|
||||||
|
Write-Host "`nUpdate Sequence Completed." -ForegroundColor Green
|
||||||
125
initial-deploy.ps1
Normal file
125
initial-deploy.ps1
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
|
||||||
|
# Initial Deployment Script for Connect-5
|
||||||
|
# Usage: ./initial-deploy.ps1
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Load Configuration
|
||||||
|
$ConfigPath = Join-Path $PSScriptRoot "deploy-config.json"
|
||||||
|
if (-not (Test-Path $ConfigPath)) { Write-Error "Config file not found"; exit 1 }
|
||||||
|
$Config = Get-Content $ConfigPath | ConvertFrom-Json
|
||||||
|
|
||||||
|
$HostName = $Config.host
|
||||||
|
$User = $Config.username
|
||||||
|
$Password = $Config.password
|
||||||
|
$RemotePath = $Config.remotePath
|
||||||
|
$GitToken = $Config.gitToken
|
||||||
|
$GitRepo = "https://${GitToken}@github.com/DeNNiiInc/Connect-5.git"
|
||||||
|
$DBPassword = "SecurePassword123!" # Hardcoded secure password for automation
|
||||||
|
|
||||||
|
Write-Host "🚀 Starting Remote Deployment to $User@$HostName..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# Check for plink
|
||||||
|
if (-not (Get-Command "plink" -ErrorAction SilentlyContinue)) {
|
||||||
|
Write-Error "Plink not found. Please install PuTTY."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Construct the massive command string
|
||||||
|
# We use a heredoc for the remote bash script
|
||||||
|
$RemoteScript = @"
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo '📦 Step 1: Installing System Dependencies...'
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y git postgresql postgresql-contrib
|
||||||
|
|
||||||
|
echo '📂 Step 2: Preparing Directory...'
|
||||||
|
mkdir -p $RemotePath
|
||||||
|
chown -R root:root $RemotePath
|
||||||
|
|
||||||
|
echo '⬇️ Step 3: Cloning Repository...'
|
||||||
|
if [ -d "$RemotePath/.git" ]; then
|
||||||
|
echo "Repo already exists, pulling..."
|
||||||
|
cd $RemotePath
|
||||||
|
git pull
|
||||||
|
else
|
||||||
|
git clone "$GitRepo" "$RemotePath"
|
||||||
|
cd "$RemotePath"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo '📦 Step 4: Installing Node Modules...'
|
||||||
|
npm install
|
||||||
|
|
||||||
|
echo '🔐 Step 5: Configuring Database...'
|
||||||
|
systemctl start postgresql
|
||||||
|
systemctl enable postgresql
|
||||||
|
|
||||||
|
# Create DB Config File
|
||||||
|
cat > db.config.js <<EOF
|
||||||
|
module.exports = {
|
||||||
|
HOST: 'localhost',
|
||||||
|
USER: 'postgres',
|
||||||
|
PASSWORD: '$DBPassword',
|
||||||
|
DB: 'connect5',
|
||||||
|
dialect: 'postgres',
|
||||||
|
pool: { max: 5, min: 0, acquire: 30000, idle: 10000 }
|
||||||
|
};
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Setup Postgres User and DB (Idempotent)
|
||||||
|
su - postgres -c "psql -c \"ALTER USER postgres WITH PASSWORD '$DBPassword';\""
|
||||||
|
su - postgres -c "psql -c \"CREATE DATABASE connect5;\" || true"
|
||||||
|
# Import Schema
|
||||||
|
su - postgres -c "psql -d connect5 -f $RemotePath/postgres-schema.sql"
|
||||||
|
|
||||||
|
echo '⚙️ Step 6: Setting up Service...'
|
||||||
|
bash setup-auto-start.sh
|
||||||
|
|
||||||
|
echo '🌐 Step 7: Configuring Nginx Reverse Proxy...'
|
||||||
|
# Remove default sites (including TurnKey default)
|
||||||
|
rm -f /etc/nginx/sites-enabled/default
|
||||||
|
rm -f /etc/nginx/sites-enabled/nodejs
|
||||||
|
|
||||||
|
# Create Nginx Config
|
||||||
|
cat > /etc/nginx/sites-available/connect5 <<'NGINX'
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
root $RemotePath;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /socket.io/ {
|
||||||
|
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_set_header X-Real-IP `$remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NGINX
|
||||||
|
|
||||||
|
# Enable Site
|
||||||
|
ln -sf /etc/nginx/sites-available/connect5 /etc/nginx/sites-enabled/
|
||||||
|
nginx -t
|
||||||
|
systemctl restart nginx
|
||||||
|
|
||||||
|
echo '✅ Deployment Complete!'
|
||||||
|
"@
|
||||||
|
|
||||||
|
|
||||||
|
# Execute via Plink
|
||||||
|
# We echo 'y' to accept the host key (blindly, for automation)
|
||||||
|
# Fix CRLF to LF for Linux compatibility
|
||||||
|
$RemoteScript = $RemoteScript -replace "`r`n", "`n"
|
||||||
|
plink -batch -P 22 -ssh -pw $Password "$User@$HostName" $RemoteScript
|
||||||
|
|
||||||
|
Write-Host "Done!" -ForegroundColor Green
|
||||||
90
setup.sh
Normal file
90
setup.sh
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
DB_PASSWORD="SecurePassword123!"
|
||||||
|
REMOTE_PATH="/var/www/connect5"
|
||||||
|
GIT_TOKEN="${GIT_TOKEN}" # Ensure this is passed as an env var or replaced before running
|
||||||
|
GIT_REPO="https://${GIT_TOKEN}@github.com/DeNNiiInc/Connect-5.git"
|
||||||
|
|
||||||
|
echo '📦 Step 1: Installing System Dependencies...'
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y git postgresql postgresql-contrib
|
||||||
|
|
||||||
|
echo '📂 Step 2: Preparing Directory...'
|
||||||
|
mkdir -p $REMOTE_PATH
|
||||||
|
chown -R root:root $REMOTE_PATH
|
||||||
|
|
||||||
|
echo '⬇️ Step 3: Cloning Repository...'
|
||||||
|
if [ -d "$REMOTE_PATH/.git" ]; then
|
||||||
|
echo "Repo already exists, pulling..."
|
||||||
|
cd $REMOTE_PATH
|
||||||
|
git pull
|
||||||
|
else
|
||||||
|
git clone "$GIT_REPO" "$REMOTE_PATH"
|
||||||
|
cd "$REMOTE_PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo '📦 Step 4: Installing Node Modules...'
|
||||||
|
npm install
|
||||||
|
|
||||||
|
echo '🔐 Step 5: Configuring Database...'
|
||||||
|
systemctl start postgresql
|
||||||
|
systemctl enable postgresql
|
||||||
|
|
||||||
|
# Create DB Config File
|
||||||
|
cat > db.config.js <<EOF
|
||||||
|
module.exports = {
|
||||||
|
HOST: 'localhost',
|
||||||
|
USER: 'postgres',
|
||||||
|
PASSWORD: '$DB_PASSWORD',
|
||||||
|
DB: 'connect5',
|
||||||
|
dialect: 'postgres',
|
||||||
|
pool: { max: 5, min: 0, acquire: 30000, idle: 10000 }
|
||||||
|
};
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Setup Postgres User and DB
|
||||||
|
su - postgres -c "psql -c \"ALTER USER postgres WITH PASSWORD '$DB_PASSWORD';\""
|
||||||
|
su - postgres -c "psql -c \"CREATE DATABASE connect5;\" || true"
|
||||||
|
# Import Schema
|
||||||
|
su - postgres -c "psql -d connect5 -f $REMOTE_PATH/postgres-schema.sql"
|
||||||
|
|
||||||
|
echo '⚙️ Step 6: Setting up Service...'
|
||||||
|
bash setup-auto-start.sh
|
||||||
|
|
||||||
|
echo '🌐 Step 7: Configuring Nginx Reverse Proxy...'
|
||||||
|
rm -f /etc/nginx/sites-enabled/default
|
||||||
|
rm -f /etc/nginx/sites-enabled/nodejs
|
||||||
|
|
||||||
|
cat > /etc/nginx/sites-available/connect5 <<NGINX
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
root $REMOTE_PATH;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /socket.io {
|
||||||
|
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_set_header X-Real-IP \$remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NGINX
|
||||||
|
|
||||||
|
ln -sf /etc/nginx/sites-available/connect5 /etc/nginx/sites-enabled/
|
||||||
|
nginx -t
|
||||||
|
systemctl restart nginx
|
||||||
|
|
||||||
|
echo '✅ Deployment Complete!'
|
||||||
Reference in New Issue
Block a user