name: Deploy to EC2
on:
push:
branches:
- integration-view-add-supplier #This is the github repo where i push the
code
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v2
# Step 2: Set up Node.js
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
# Step 3: Install dependencies
- name: Install dependencies
run: npm install --legacy-peer-deps
# Step 4: Build the React app
- name: Build the React app
run: |
unset CI
npm run build
# Step 5: Remove old build folder on EC2 if it exists
- name: Remove the build folder on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
port: 22
script_stop: true
debug: true
script: |
if [ -d "/var/www/html/nct-frontend-registration-build" ]; then
sudo rm -rf /var/www/html/nct-frontend-registration-build
fi
# Step 6: Transfer new build files to EC2 using SCP
- name: SCP to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
port: 22
source: "./nct-frontend-registration-build/*"
target: "/var/www/html"
# Step 7: Restart Nginx to reflect changes
- name: Restart Nginx on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
port: 22
script_stop: true
debug: true
script: |
sudo systemctl restart nginx