Coder Social home page Coder Social logo

ga_resume_on_ec2's Introduction

GA_Resume_on_EC2

Host Your Resume on AWS EC2 with a CI/CD Setup Using GitHub Actions

This article helps you understand how you can automatically deploy your code to AWS EC2 from GitHub. Deployed Resume can be viewed here - http://ec2-13-60-15-196.eu-north-1.compute.amazonaws.com/

Step 1: Create an EC2 Instance and Download the Key Pair.

Step 2: Create Secrets in GitHub for the Repository

Step 3: Creating your first workflow

Creating your first workflow

  1. Create a .github/workflows directory in your repository on GitHub if this directory does not already exist.

  2. In the .github/workflows directory, create a file named github-actions-ec2.yml.

  3. Start your file by defining jobs:

    jobs:
      deploy:
        name: Deploy to EC2
        runs-on: ubuntu-latest
  4. Checkout the files:

      steps:
        - name: Checkout the files
          uses: actions/checkout@v2
  5. Deploy the code to the server:

        - name: Deploy to Server 1
          uses: easingthemes/ssh-deploy@main
          env:
            SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
            REMOTE_HOST: ${{ secrets.HOST_DNS }}
            REMOTE_USER: ${{ secrets.USERNAME }}
            TARGET: ${{ secrets.TARGET_DIR }}
    • You need to fill in the secrets using GitHub Secrets that you can add in your repo, read GitHub Secrets

      • EC2_SSH_KEY: This will be your .pem file which you will use to login to the instance

      • HOST_DNS: Public DNS record of the instance, it will look something like this ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com

      • USERNAME: Will be the username of the EC2 instance, usually ubuntu

      • TARGET_DIR: Is where you want to deploy your code.

  6. Once you add all these information your repo will look like thisGitHub Secrets

    GitHub Secrets

  7. Trigger deployment only on push to master branch:

    on:
      push:
        branches:
          - main
  8. The final .github/workflows/github-actions-ec2.yml should look like the following:

    name: Push-to-EC2
    
    # Trigger deployment only on push to main branch
    on:
      push:
        branches:
          - main
    
    jobs:
      deploy:
        name: Deploy to EC2 on master branch push
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout the files
            uses: actions/checkout@v2
    
          - name: Deploy to Server 1
            uses: easingthemes/ssh-deploy@main
            env:
              SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
              REMOTE_HOST: ${{ secrets.HOST_DNS }}
              REMOTE_USER: ${{ secrets.USERNAME }}
              TARGET: ${{ secrets.TARGET_DIR }}
    
          - name: Executing remote ssh commands using ssh key
            uses: appleboy/ssh-action@master
            with:
              host: ${{ secrets.HOST_DNS }}
              username: ${{ secrets.USERNAME }}
              key: ${{ secrets.EC2_SSH_KEY }}
              script: |
                sudo apt-get -y update
                sudo apt-get install -y apache2
                sudo systemctl start apache2
                sudo systemctl enable apache2
                cd home
                sudo mv * /var/www/html
    

ga_resume_on_ec2's People

Contributors

sreedhargs89 avatar prem1sai avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

prem1sai

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.