Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/deploy-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Deploy Main To EC2

on:
push:
branches:
- main
paths:
- 'backend/**'
- 'web/**'
- '.github/workflows/deploy-main.yml'

concurrency:
group: deploy-main-ec2
cancel-in-progress: true

jobs:
deploy:
name: Deploy Backend + Frontend
runs-on: ubuntu-latest

steps:
- name: Deploy over SSH
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
script_stop: true
script: |
set -euo pipefail

cd "${{ secrets.SERVER_PATH }}"

git fetch origin
git checkout main
git pull --ff-only origin main

cd backend
if [ -f package-lock.json ]; then
npm ci --omit=dev --no-audit --no-fund || npm install --omit=dev --no-audit --no-fund
else
npm install --omit=dev --no-audit --no-fund
fi

pm2 restart neph-backend || pm2 start src/server.js --name neph-backend

cd ../web
if [ -f package-lock.json ]; then
npm ci --no-audit --no-fund || npm install --no-audit --no-fund
else
npm install --no-audit --no-fund
fi

npm run build
pm2 restart neph-web || pm2 start npm --name neph-web -- start -- -p 3001

pm2 save

curl -fsS http://127.0.0.1:3000/health >/dev/null
curl -fsSI http://127.0.0.1:3001 >/dev/null