Skip to content

Merge pull request #35 from chingu-voyages/database-connection #38

Merge pull request #35 from chingu-voyages/database-connection

Merge pull request #35 from chingu-voyages/database-connection #38

name: Build and Deploy Server
on:
push:
branches: ["main"]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
env:
SSH_USER: ec2-user
SSH_HOST: ec2-54-177-26-87.us-west-1.compute.amazonaws.com
WEB_ROOT: /home/www
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci --prefix server
- name: Copy server files to EC2 server
uses: burnett01/[email protected]
with:
switches: --verbose --human-readable --archive --delete
path: server/
remote_user: ${{ env.SSH_USER }}
remote_host: ${{ env.SSH_HOST }}
remote_path: ${{ env.WEB_ROOT}}
remote_key: ${{ secrets.SERVER_DEPLOYMENT_KEY }}
- name: Execute commands on server
uses: appleboy/[email protected]
with:
username: ${{ env.SSH_USER }}
host: ${{ env.SSH_HOST }}
key: ${{ secrets.SERVER_DEPLOYMENT_KEY }}
script: |
echo "Checking if pm2 installed"
if [ ! "$(which pm2 2>/dev/null)" ]; then
echo "Not found. Installing pm2"
sudo npm i -g pm2
fi
echo "Deleting node server if exists"
pm2 delete ${{ env.WEB_ROOT}}/src/app.js 2> /dev/null
echo "Starting node server"
PORT=4000 DATABASE_CONNECTION_STRING='${{ secrets.DATABASE_CONNECTION_STRING }}' pm2 start ${{ env.WEB_ROOT}}/src/app.js