Merge pull request #109 from nilotpal-n7/master #141
Workflow file for this run
This file contains hidden or 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
| name: Deploy HAB Backend Server | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: SSH into EC2 and deploy | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_KEY }} | |
| script: | | |
| # Go to project directory | |
| cd ~/iitgHABapp | |
| # Pull latest changes | |
| git reset --hard | |
| git pull origin master | |
| # Stop and remove any existing PM2 processes | |
| pm2 stop all || true | |
| pm2 delete all || true | |
| pm2 unstartup || true | |
| # Install dependencies | |
| cd server | |
| npm install | |
| # Update environment variables | |
| rm -f .env | |
| cat <<EOF > .env | |
| ${{ secrets.EC2_ENV }} | |
| EOF | |
| # Start backend server | |
| pm2 start index.js --name hab-backend |