Day 81: Deploying a Web App with Jenkins CI/CD Declarative Pipeline on AWS

Day 81: Deploying a Web App with Jenkins CI/CD Declarative Pipeline on AWS

In this tutorial, we'll walk through the process of deploying a web application using Jenkins CI/CD declarative pipeline on Amazon Web Services (AWS). This step-by-step guide will cover setting up an AWS EC2 instance, installing Jenkins, configuring Docker, creating a Jenkins pipeline, and deploying the application.

Step 1: Create an EC2 Instance on AWS

  1. Go to the AWS portal and log in.

  2. Navigate to EC2 and click on "Launch Instance".

  3. Choose an appropriate AMI (Amazon Machine Image) like Ubuntu, select the instance type as t2.micro, and configure security settings to allow HTTP and HTTPS traffic.

  4. Create a new key pair or use an existing one and download the .pem file.

Step 2: Configure Security Groups

  1. Find the security group associated with your EC2 instance and add inbound rules to allow ports 8080 and 8001.

Step 3: Connect to the EC2 Instance

  1. Use SSH to connect to the EC2 instance by copying the SSH command from the server description.

  2. Open a terminal in the directory where the .pem file is located and paste the SSH command to connect.

Step 4: Install Jenkins

  1. Follow the instructions here to install Jenkins on your EC2 instance.

Step 5: Install Docker

  1. Run the command sudo apt-install docker.io to install Docker on your EC2 instance.

Step 6: Verify Installation

  1. Check if Jenkins and Docker are installed by running jenkins --version and docker --version respectively.

Step 7: Create a Jenkins Pipeline

  1. Go to the Jenkins dashboard and click on "New Item".

  2. Name the project as "declarative_pipeline" and select "Pipeline" as the project type.

  3. Add a description for the project and click on "OK".

  4. In the pipeline script, define stages for checking out the code, testing, building Docker image, and running the container.

Step 8: Save and Build the Pipeline

  1. Click on "Save" to save the pipeline configuration.

  2. Click on "Build Now" to trigger the pipeline execution.

Step 9: Monitor Pipeline Progress

  1. View the pipeline progress by clicking on "Stage View" to check the status of each stage.

Step 10: Access the Deployed Application

  1. Once the pipeline execution is successful, search for the public IP address of the EC2 instance followed by port 8001 in your browser to access the deployed web application.

Congratulations! You have successfully deployed a web application using Jenkins CI/CD declarative pipeline on AWS. This process automates the deployment process, making it efficient and reliable. Happy coding!