Skip to content

Commit

Permalink
Automate Backend Deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Somnath-Chattaraj authored Oct 13, 2024
1 parent d1d6eaf commit 1a804e3
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,55 @@ jobs:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: somnath910/statuscode1:latest
tags: somnath910/statuscode1:latest # Replace with your Docker Hub username and repository

- name: Verify Pushed Image
run: docker pull somnath910/statuscode1:latest
run: docker pull somnath910/statuscode1:latest # Replace with your Docker Hub username and repository

---

name: Deploy to EC2 with Prisma Migrations and Cleanup

on:
push:
branches:
- master
- master # Specify your deployment branch

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2

- name: Add SSH Key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Add SSH Key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}

- name: Deploy to EC2, Clean Up Old Migrations, and Run Prisma Migrations
run: |
ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_IP }} << 'EOF'
cd /home/ubuntu/Campus-Chatter/backend # Change this to your project path on EC2
- name: Deploy to EC2, Clean Up Old Migrations, and Run Prisma Migrations
run: |
ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_IP }} << 'EOF'
cd /home/ubuntu/Campus-Chatter/backend # Change this to your project path on EC2
# Stash any local changes
git stash
# Stash any local changes
git stash
# Pull the latest changes from master
git pull origin master
# Pull the latest changes from master
git pull origin master
# Remove old migration files
rm -rf prisma/migrations
# Remove old migration files
rm -rf prisma/migrations
# Install any new dependencies
npm install
# Install any new dependencies
npm install
# Apply Prisma migrations using deploy for production (instead of dev)
npx prisma migrate deploy --force
# Apply Prisma migrations using deploy for production (instead of dev)
npx prisma migrate deploy --force
# Compile TypeScript
tsc -b
# Compile TypeScript
tsc -b
# Restart your backend service using PM2
pm2 restart dist/index.js
EOF
# Restart your backend service using PM2
pm2 restart dist/index.js
EOF

0 comments on commit 1a804e3

Please sign in to comment.