0% found this document useful (0 votes)
10 views2 pages

Workflow of Github

This document outlines a GitHub Actions workflow for deploying a React application to an EC2 instance. It includes steps for checking out code, setting up Node.js, installing dependencies, building the app, removing old build files, transferring new files to EC2, and restarting Nginx. The workflow is triggered on pushes to the 'integration-view-add-supplier' branch of the repository.

Uploaded by

HYPER Rishabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Workflow of Github

This document outlines a GitHub Actions workflow for deploying a React application to an EC2 instance. It includes steps for checking out code, setting up Node.js, installing dependencies, building the app, removing old build files, transferring new files to EC2, and restarting Nginx. The workflow is triggered on pushes to the 'integration-view-add-supplier' branch of the repository.

Uploaded by

HYPER Rishabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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

You might also like