Streamlining Continuous Integration and Deployment with AWS, Jenkins, Docker, Git, and Terraform
In this blog we are going to automate installation of Jenkins and launching ec2-instance with the help of terraform
Introduction
In today's fast-paced software development environment, streamlining CI/CD pipelines is crucial for delivering high-quality software efficiently. This blog post will explore how to leverage AWS, Jenkins, Docker, Git, and Terraform to achieve this goal.
Setting Up Jenkins on AWS
Launching an EC2 Instance: To launch an EC2 instance on AWS, follow these steps using the AWS Management Console:
Log in to the AWS Management Console.
Navigate to the EC2 dashboard.
Click on "Launch Instance" and select the desired AMI, instance type, and configure security groups.
Follow the prompts to create the instance.
Installing Jenkins
Once the EC2 instance is up and running, SSH into the instance and install Jenkins using the following commands:
sudo apt update
sudo apt install default-jre -y
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins -y
After installation, start the Jenkins service:
sudo systemctl start jenkins
Access Jenkins through your browser using the instance's public IP address and port 8080.
Configuring Jenkins for Continuous Integration
Install necessary Jenkins plugins like Git plugin, Pipeline plugin, etc.
Create a new Jenkins job and configure it to pull the Medium app's code from the Git repository.
Set up build triggers to automatically start a build whenever new changes are pushed to the repository.
Building a Medium App on React
Setting Up the Medium App: Install React and create a new React app using the following commands:
npx create-react-app medium-app
cd medium-app
This will set up a basic React app structure.
Implementing CI with Git and Jenkins
Connect your Git repository to Jenkins by providing the repository URL and necessary credentials.
Configure the Jenkins job to execute build commands for the React app, such as installing dependencies and running tests.
Deploying with Docker and Terraform
Containerizing the Medium App with Docker: Create a Dockerfile in the root of the React app directory with the following content:
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]
Build and tag the Docker image:
docker build -t medium-app .
Automating Infrastructure with Terraform: Install Terraform and create a main.tf
file with the following content to provision AWS resources:
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "jenkins" {
ami = "ami-12345678"
instance_type = "t2.micro"
}
Execute terraform init
, terraform plan
, and terraform apply
to provision the resources.
Deploying the Medium App with Terraform
Integrate Terraform with Jenkins by executing Terraform commands as part of the Jenkins job. Use Terraform scripts to deploy the Dockerized Medium app onto the AWS infrastructure provisioned earlier.
Conclusion
By leveraging AWS, Jenkins, Docker, Git, and Terraform, developers can create efficient CI/CD pipelines for their projects. Continuous integration, automated deployments, and infrastructure as code methodologies streamline the software development lifecycle, resulting in faster delivery of high-quality software. Explore further optimizations and tools to enhance your CI/CD pipelines and stay ahead in the dynamic world of software development.
Connect with us:
Hashnode: https://hashnode.com/@Nehal71
Twitter : https://twitter.com/IngoleNehal