#90daysofdevops-Day-81:Project-2

#90daysofdevops-Day-81:Project-2

Project Description

The project is about automating the deployment process of a web application using Jenkins and its declarative syntax. The pipeline includes stages like building, testing, and deploying to a staging environment. It also includes running acceptance tests and deploying to production if all tests pass.

Pre-requisites

  1. Create an EC2 instance in the AWS management console with the required storage.

  2. Install Jenkins and Docker in the EC2 instance.

    Refer to my last project to find the details of the pre-requisites:-

    linkedin.com/feed/update/urn:li:activity:70..

Project Steps

  1. Navigate to the Jenkins dashboard and go to the new item. Then select Pipeline and create the project.

  2. In the general section provide the project description and also insert the GitHub project URL.

  3. In the build trigger section select the GitHub webhook trigger option.

    Ensure the webhook is configured in GitHub.

  4. Ensure the project has a Docker file in GitHub.

  5. Write the declarative pipeline code which is a groovy syntax code to set up the project pipeline.

    agent:- Agent is the different servers that are linked to the master Jenkins server. An agent can be set up in the pipeline to run the pipelines in different agents. In this project, we are going with the default agent.

    Stages:- Stages contain different steps to be executed as part of the project pipeline.

    In this project we have 3 stages:-

    • Code:- The code stage pulls the code from Github to build and execute the pipeline in further steps.

    • Build and Test:- This stage builds the image of the app code from the docker file.

    • Run:- This stage runs the container in the server and makes the application up.

COPY

    pipeline {
        agent any
        stages{
            stage('Code'){
                steps{
                    git url: 'https://github.com/Bandank/node-todo-cicd.git', branch: 'master' 
                }
            }
            stage('Build and Test'){
                steps{
                    sh 'sudo docker build -t webapp .'
                    echo "build and ttest completed"
                }
            }
            stage('Run'){
                steps{
                    sh "sudo docker run -d -p 8000:8000 webapp"
                }
            }
        }       
        }
  1. After writing the detailed pipeline groovy scrip in the project configuration apply and save the project.

  2. Now, navigate to the project and click on Build Now to execute the project.

    1. We can see the successful console output and the stages that are completed in its stage executions as shown in the above and below screenshots.

  3. Ensure to open the port 8000 in the security group associated with the EC2 instance.

  4. Finally, navigate to the web-app URL and we can see the application is up & running.