-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98a35db
commit 9f7d0b3
Showing
6 changed files
with
169 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ reste | |
|
||
test update 10/17/2024 | ||
brooroof | ||
|
||
test commit 10/25/2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |