Day 80: Streamlining CI/CD Pipelines for Dockerized Apps on AWS EC2 Instances with Jenkins

Vedant ThavkarVedant Thavkar
2 min read

Are you looking to automate your deployment process for Docker applications hosted on AWS EC2 instances? In this guide, we'll walk through the steps to set up a seamless CI/CD pipeline using Jenkins, integrating GitHub webhooks, and ensuring your application updates go live effortlessly.

Let's dive in:

  1. AWS Setup:

    • Head to the AWS portal and create a new EC2 instance:

      • Name: jenkins-server

      • AMI: Ubuntu

      • Instance type: t2.micro

      • Key pair login: Create > docker.pem

      • Allow HTTP and HTTPS access

  2. SSH Connection:

    • Connect to your EC2 instance via SSH using the generated key pair.
  3. Jenkins Installation:

    • Install Jenkins and Java. Follow the official Jenkins documentation for Linux installation.

  4. Docker Installation:

    • Install Docker on the EC2 instance using:

        sudo apt install docker.io
      
  5. Security Group Configuration:

    • Allow inbound traffic on ports 8080 and 8001 in the EC2 instance's security group.

  6. Access Jenkins:

    • Access Jenkins by navigating to the EC2 instance's public IP address followed by port 8080 in your browser

  7. Initial Setup:

    • Retrieve the initial admin password from the Jenkins server.

    • Install suggested plugins and set up the admin user.

  8. CI/CD Pipeline Setup:

    • Create a new item in Jenkins for your project (e.g., todo-app).

    • Configure source code management to connect to your GitHub repository.

    • Add build steps to build Docker images and run containers.

  9. GitHub Integration:

    • Install the Git Integration plugin in Jenkins.

    • Add an SSH key to your GitHub account for authentication.

    • Configure a webhook in your GitHub repository settings, pointing to your Jenkins server's webhook URL.

  10. Automated Deployment:

    • Enable GitHub webhook trigger for GitScm polling in your Jenkins project settings.

  11. Test Deployment:

    • Make changes to your code, commit, and push to GitHub.

    • GitHub webhook triggers Jenkins to run the pipeline automatically.

    • Your updated application is deployed seamlessly to your EC2 instance.

By following these steps, you can establish a robust CI/CD pipeline for deploying Docker applications on AWS EC2 instances using Jenkins. This automation ensures that every code change you make is swiftly reflected in your live web application, streamlining your development and deployment workflow.

11
Subscribe to my newsletter

Read articles from Vedant Thavkar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vedant Thavkar
Vedant Thavkar

"DevOps enthusiast and aspiring engineer. Currently honing skills in streamlining development workflows and automating infrastructure. Learning AWS, Docker, Kubernetes, Python, and Ansible. Eager to contribute and grow within the DevOps community."