This file contains 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 to EC2 | |
on: | |
push: | |
branches: | |
- production_branch | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the repository code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: SSH into EC2 and deploy | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@v0.1.7 | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
# Navigate to the project directory | |
cd app | |
# Pull the latest changes | |
git pull origin production_branch | |
# Install dependencies | |
npm install | |
# Build the project (if applicable) | |
# npm run build | |
# Restart the application using PM2 | |
pm2 restart all |