Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhrumil-Gohil committed Sep 3, 2024
1 parent 3c68f3c commit d22820e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 23 deletions.
103 changes: 82 additions & 21 deletions .github/workflows/deployapp.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,65 @@
# name: Deploy React App to EC2

# on:
# push:
# branches:
# - main # Adjust this if you want to deploy from a different branch

# jobs:
# deploy:
# name: Deploy to EC2
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Set up Node.js
# uses: actions/setup-node@v3
# with:
# node-version: '18.x' # Match the node version in your package.json

# - name: Install dependencies
# run: npm install

# - name: Build the React app
# run: npm run build

# - name: Upload build artifacts
# uses: actions/upload-artifact@v3
# with:
# name: build-artifact
# path: build/

# - name: Download build artifact
# uses: actions/download-artifact@v3
# with:
# name: build-artifact

# - name: Deploy to EC2
# env:
# EC2_HOST: ${{ secrets.EC2_HOST }} # Add your EC2 public IP or domain as a secret in GitHub
# EC2_USER: ${{ secrets.EC2_USER }} # Add your EC2 user (e.g., 'ec2-user') as a secret in GitHub
# EC2_KEY: ${{ secrets.EC2_KEY }} # Add your private key for SSH as a secret in GitHub
# run: |
# echo "${{ secrets.EC2_KEY }}" > ~/ec2-key.pem
# chmod 600 ~/ec2-key.pem

# # Transfer build artifacts and SSH key to bastion host
# ssh -o StrictHostKeyChecking=no -i ~/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "mkdir /tmp/react"
# scp -o StrictHostKeyChecking=no -i ~/ec2-key.pem -r build/* ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/tmp/react
# scp -o StrictHostKeyChecking=no -i ~/ec2-key.pem ~/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/tmp/react

# # SSH into bastion host and transfer to private instance
# ssh -o StrictHostKeyChecking=no -i ~/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
# ssh -o StrictHostKeyChecking=no -i /tmp/react/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_PVT_HOST }} "mkdir /tmp/react"
# scp -o StrictHostKeyChecking=no -i /tmp/react/ec2-key.pem -r /tmp/react/* ${{ secrets.EC2_USER }}@${{ secrets.EC2_PVT_HOST }}:/tmp/react
# ssh -o StrictHostKeyChecking=no -i /tmp/react/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_PVT_HOST }} << 'INNER_EOF'
# sudo cp -r /tmp/react/* /var/www/html/
# sudo systemctl restart nginx
# INNER_EOF
# rm -f /tmp/ec2-key.pem
# EOF
name: Deploy React App to EC2

on:
Expand All @@ -22,41 +84,40 @@ jobs:
- name: Install dependencies
run: npm install

- name: Build the React app
run: npm run build

- name: Upload build artifacts
- name: Upload source code
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: build/
name: source-code
path: ./

- name: Download build artifact
- name: Download source code
uses: actions/download-artifact@v3
with:
name: build-artifact
name: source-code

- name: Deploy to EC2
- name: Deploy to EC2 and start server
env:
EC2_HOST: ${{ secrets.EC2_HOST }} # Add your EC2 public IP or domain as a secret in GitHub
EC2_USER: ${{ secrets.EC2_USER }} # Add your EC2 user (e.g., 'ec2-user') as a secret in GitHub
EC2_KEY: ${{ secrets.EC2_KEY }} # Add your private key for SSH as a secret in GitHub
EC2_HOST: ${{ secrets.EC2_HOST }} # Public IP or domain of your EC2 instance
EC2_USER: ${{ secrets.EC2_USER }} # User to SSH into EC2 instance (e.g., 'ec2-user')
EC2_KEY: ${{ secrets.EC2_KEY }} # SSH private key as a secret in GitHub
EC2_PVT_HOST: ${{ secrets.EC2_PVT_HOST }} # Private IP or hostname of the EC2 instance if behind a bastion
run: |
echo "${{ secrets.EC2_KEY }}" > ~/ec2-key.pem
chmod 600 ~/ec2-key.pem
# Transfer build artifacts and SSH key to bastion host
ssh -o StrictHostKeyChecking=no -i ~/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "mkdir /tmp/react"
scp -o StrictHostKeyChecking=no -i ~/ec2-key.pem -r build/* ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/tmp/react
scp -o StrictHostKeyChecking=no -i ~/ec2-key.pem ~/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/tmp/react
# Transfer source code to EC2
ssh -o StrictHostKeyChecking=no -i ~/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "mkdir -p /tmp/react-app"
scp -o StrictHostKeyChecking=no -i ~/ec2-key.pem -r ./* ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/tmp/react-app
# SSH into bastion host and transfer to private instance
ssh -o StrictHostKeyChecking=no -i ~/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
ssh -o StrictHostKeyChecking=no -i /tmp/react/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_PVT_HOST }} "mkdir /tmp/react"
scp -o StrictHostKeyChecking=no -i /tmp/react/ec2-key.pem -r /tmp/react/* ${{ secrets.EC2_USER }}@${{ secrets.EC2_PVT_HOST }}:/tmp/react
ssh -o StrictHostKeyChecking=no -i /tmp/react/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_PVT_HOST }} << 'INNER_EOF'
sudo cp -r /tmp/react/* /var/www/html/
sudo systemctl restart nginx
if pgrep -f "docusaurus serve"; then
pkill -f "docusaurus serve"
fi
cd /tmp/react-app
yarn install
yarn start &
INNER_EOF
rm -f /tmp/ec2-key.pem
EOF
EOF
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"stop": "docusaurus stop",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
Expand Down
2 changes: 1 addition & 1 deletion src/components/HomepageFeatures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styles from './styles.module.css';

const FeatureList = [
{
title: 'Easy to Use',
title: 'to Use',
description: (
<>
Docusaurus was designed from the ground up to be easily installed and
Expand Down
2 changes: 1 addition & 1 deletion src/components/HomepageFeatures/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const FeatureList: FeatureItem[] = [
link: "https://inductiveuniversity.com/",
description: (
<>
Take our <a href="https://inductiveuniversity.com/">Inductive University courses</a> to earn your IU Credential or expand your knowledge through Elective Studies.
Take our <a href="https://inductiveuniversity.com/">Inductive University </a> to earn your IU Credential or expand your knowledge through Elective Studies.
</>
),
},
Expand Down

0 comments on commit d22820e

Please sign in to comment.