Skip to content

Commit

Permalink
test commit
Browse files Browse the repository at this point in the history
  • Loading branch information
singharaj-usai committed Oct 26, 2024
1 parent 98a35db commit 9f7d0b3
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 22 deletions.
28 changes: 10 additions & 18 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
name: Deploy Site via Git
# Create this file in your repo: .github/workflows/deploy.yml
name: Deploy

on:
push:
branches:
- main # Run this workflow whenever code is pushed to the main branch
branches: [ main ]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3

# Step 2: SSH into the VPS and pull the latest code
- name: Deploy to VPS via SSH
uses: appleboy/[email protected]
- name: Deploy to Digital Ocean
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_IP }} # Your VPS IP address stored as a secret
username: ${{ secrets.VPS_USER }} # Your VPS user stored as a secret
key: ${{ secrets.SSH_PRIVATE_KEY }} # Your SSH private key stored as a secret
host: ${{ secrets.HOST }}
username: root
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd Valkyrie/Valk.Website/AlphaBloxWeb # Navigate to your project directory
git pull origin main # Pull the latest code from GitHub
npm install # Install any new dependencies
docker-compose up --build -d app # Stop running app not webserver
cd /var/www/valkyrie
./deploy.sh
117 changes: 117 additions & 0 deletions deploy-do.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

# Create a new droplet
echo "Creating new droplet..."
doctl compute droplet create valkyrie-app \
--image ubuntu-22-04-x64 \
--size s-1vcpu-1gb \
--region nyc1 \
--ssh-keys $DO_SSH_KEY_FINGERPRINT

# Get the droplet IP
DROPLET_IP=$(doctl compute droplet get valkyrie-app --format PublicIPv4 --no-header)

# Wait for SSH to be available
until ssh -o StrictHostKeyChecking=no root@$DROPLET_IP 'exit'; do
echo "Waiting for SSH..."
sleep 5
done

# Setup the server
ssh -o StrictHostKeyChecking=no root@$DROPLET_IP << 'ENDSSH'
# Update system
apt update && apt upgrade -y
# Install Node.js 18.x
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
apt install -y nodejs
# Install PM2
npm install -g pm2
# Install Nginx
apt install -y nginx
# Create app directory
mkdir -p /var/www/valkyrie
cd /var/www/valkyrie
# Clone your repository
git clone https://github.com/yourusername/your-repo.git .
# Install dependencies
npm install
# Setup PM2 ecosystem file
cat > ecosystem.config.js << 'EOF'
module.exports = {
apps: [{
name: 'valkyrie',
script: 'server/server.js',
instances: 'max',
exec_mode: 'cluster',
env: {
NODE_ENV: 'production',
PORT: 3000
}
}]
}
EOF
# Setup Nginx configuration
cat > /etc/nginx/sites-available/valkyrie << 'EOF'
server {
listen 80;
server_name valk.fun www.valk.fun;
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 /images/ {
alias /var/www/valkyrie/images/;
expires 30d;
add_header Cache-Control "public, no-transform";
}
location /uploads/ {
alias /var/www/valkyrie/uploads/;
client_max_body_size 50M;
}
location /socket.io/ {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
EOF
# Enable the site
ln -s /etc/nginx/sites-available/valkyrie /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
# Create necessary directories
mkdir -p uploads images
chmod 755 uploads images
# Start the application with PM2
pm2 start ecosystem.config.js
pm2 save
pm2 startup
# Install SSL certificate
apt install -y certbot python3-certbot-nginx
certbot --nginx -d valk.fun -d www.valk.fun --non-interactive --agree-tos --email [email protected]
# Restart Nginx
systemctl restart nginx
ENDSSH

echo "Deployment complete! Your app is running at $DROPLET_IP"
23 changes: 23 additions & 0 deletions monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

echo "=== System Status ==="
date
echo

echo "=== Node.js Process ==="
pm2 list
pm2 logs --lines 50
echo

echo "=== System Resources ==="
df -h
free -m
top -bn1 | head -n 20
echo

echo "=== Nginx Status ==="
systemctl status nginx
echo

echo "=== SSL Certificate Status ==="
certbot certificates
8 changes: 4 additions & 4 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ app.post('/api/verify-secret-key', (req, res) => {
}
});

const uploadsDir =
process.env.NODE_ENV === 'production'
? '/tmp/uploads' // Use /tmp in production (Vercel)
: path.join(__dirname, '../uploads'); // Use local path in development
const uploadsDir = process.env.NODE_ENV === 'production'
? '/var/data/uploads' // Render's persistent storage path
: path.join(__dirname, '../uploads');


if (!fs.existsSync(uploadsDir)) {
fs.mkdirSync(uploadsDir, { recursive: true });
Expand Down
2 changes: 2 additions & 0 deletions test-commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ reste

test update 10/17/2024
brooroof

test commit 10/25/2024
13 changes: 13 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Pull latest changes
git pull origin main

# Install dependencies
npm install --production

# Restart the application
pm2 reload all

# Restart Nginx
sudo systemctl restart nginx

0 comments on commit 9f7d0b3

Please sign in to comment.