Skip to content

Build and Deploy Server #28

Build and Deploy Server

Build and Deploy Server #28

name: Build and Deploy Server
on:
push:
branches: ["main"]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
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: ec2-user
remote_host: ec2-54-177-26-87.us-west-1.compute.amazonaws.com
remote_path: /home/www
remote_key: ${{ secrets.SERVER_DEPLOYMENT_KEY }}
- name: Execute commands on server
uses: appleboy/[email protected]
with:
username: ec2-user
host: ec2-54-177-26-87.us-west-1.compute.amazonaws.com
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 /home/www/src/app.js 2> /dev/null
echo "Starting node server"
port=4000 pm2 start /home/www/src/app.js