DEV Community

Mohana Priya
Mohana Priya

Posted on

🚀 Automate Your Resume Hosting with CI/CD and AWS EC2 🌐

Introduction:

CI/CD is a method used in modern software development to automate the process of integrating code changes, testing them, and deploying applications. This approach ensures that code changes are continuously tested and deployed, leading to faster development cycles and more reliable applications.

In this project, we utilize CI/CD to host a personal resume website on an EC2 instance using GitHub Actions. By automating the deployment process, any updates made to the resume repository are automatically reflected on the live website. This not only reduces manual effort but also ensures that the resume is always current and available to potential employers or collaborators.By integrating GitHub Actions with AWS, you can achieve continuous deployment, ensuring that any changes made to your resume are automatically reflected online.

This article helps you understand how you can automatically deploy your code to AWS EC2 from GitHub.

Step-1: Launch an EC2 instance with the Ubuntu server. Modify the security group inbound rules to allow SSH (port 22), HTTP (port 80), and HTTPS (port 443).

Image description

Step-2: Create a public repository on GitHub for example Host-Resume-on-ec2-githubactions.
Add an index.html file containing the code for your resume website.
Add a CSS file for styling your resume.

Image description

Step-3: Add secrets to the repository for secure information storage.

EC2_SSH_KEY: Your key pair file for SSH access.
HOST_DNS: The public DNS of your EC2 instance.
USERNAME: The username for SSH (e.g., ubuntu).
TARGET_DIR: The target directory on the EC2 instance (e.g., home).

Image description

Step-4: Create a .github/workflows directory in your repository.
Add a YAML file (e.g., github-actions-ec2.yml) with the following code to automate deployment:

Add the following code so that your actions only run when you push to main branch.



# 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


Enter fullscreen mode Exit fullscreen mode

Once done with this your workflow will be created and using the public IP address if the EC2 instance you can view the resume.

If any update was done in your main branch you can able to view by refreshing the page.

Image description

Conclusion:

Hosting a resume on an EC2 instance using GitHub Actions combines the power of cloud infrastructure with the automation of CI/CD workflows. This method ensures that your resume is always up-to-date and accessible, demonstrating technical skills and modern development practices. This approach can be extended to various applications, making it a versatile solution for web hosting needs.

Top comments (0)