Skip to content

Instantly share code, notes, and snippets.

@fardeen9983
Created April 17, 2022 14:25
Show Gist options
  • Save fardeen9983/edca2d309505470cbab08a09989a3557 to your computer and use it in GitHub Desktop.
Save fardeen9983/edca2d309505470cbab08a09989a3557 to your computer and use it in GitHub Desktop.
Github action
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Deploy in EC2
env:
PRIVATE_KEY: ${{ secrets.EC2_PRIVATE_KEY }}
HOSTNAME : ${{ secrets.HOSTNAME }}
USER_NAME : ${{ secrets.USER }}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
#Now we have got the access of EC2 and we will start the deploy .
DIR="/home/ec2-user/server"
pm2 delete all
cd /home/ec2-user
if [ ! -d $DIR ]
then
mkdir server &&
git clone https://github.com/CodePanthers/node-aws-ec2-github-actions.git server &&
cd server &&
npm i
else
cd server
fi
git checkout master &&
git fetch --all &&
git reset --hard origin/master &&
git pull origin master &&
pm2 start app.js
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment