Skip to content

jetani-ravi/github-action-ssh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

github-action-ssh

Configure SSH into aws ec2

  • How to handle SSH keys with EC2-github actions Learn more

Declare these git secrets

  • SSH_PRIVATE_KEY
  • HOST_NAME / IP_ADDRESS
  • USER_NAME
name: Deploy

on:
push:
branches: [dev]

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

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Build & Deploy
        env:
          PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
          HOSTNAME: ${{ secrets.SSH_HOST }}
          USER_NAME: ${{ secrets.USER_NAME }}

        run: |
          echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
          ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '

            # Now we have access to EC2, let's start the deployment.
            cd /home/ubuntu/<PROJECT_DIRECTORY> &&
            git checkout dev &&
            git fetch --all &&
            git reset --hard origin/dev &&
            git pull origin dev &&
            sudo npm ci --production &&
            sudo pm2 restart ./dist/index.js
          '

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors