change
cicd.mp4
The Dockerfile for the Node.js app is included in the repository.
The following AWS resources are set up using Terraform:
-
EC2 Instances:
nodejsappjenkinsmonitoring
-
RDS Instance:
- mysql
-
Key Pairs:
jenkinsnodejsapp
-
Security Groups:
jenkinsnodejsapprdsmonitoring
The Terraform templates provision the required infrastructure on AWS. The following files are included in the repository:
backend.tf: Configures the backend for Terraform state storage.instances.tf: Defines the EC2 instances for Jenkins, monitoring, and the Node.js app.keypairs.tf: Defines the key pairs for SSH access to the instances.providers.tf: Configures the providers required for the AWS resources.rds.tf: Defines the RDS instance for the MySQL database.secgrp.tf: Defines the security groups for Jenkins, monitoring, Node.js app, and RDS.vars.tf: Defines the variables used in the Terraform configuration.
Monitoring is set up using Prometheus and Grafana. These services are deployed on a separate EC2 instance.
-
Prometheus Configuration:
- Scrape configurations for the Node.js app and other services are added to `prometheus.yml`.
-
Grafana Configuration:
- Prometheus is added as a data source in Grafana.
- Dashboards are created to visualize key metrics.
The Jenkinsfile for setting up the CI/CD pipeline is included in the repository.
-
Created an S3 Bucket for Terraform State File:
- I started by creating an S3 bucket to store the Terraform state file. This bucket is essential for managing the state of the Terraform deployment and ensuring consistent provisioning of resources.
-
Provisioned Resources Using Terraform:
- I used Terraform from my local computer to provision the necessary AWS resources. This involved:
- Initializing Terraform with
terraform init. - Validating the configuration with
terraform validate. - Planning the deployment with
terraform plan. - Applying the configuration with
terraform apply.
- Initializing Terraform with
- I used Terraform from my local computer to provision the necessary AWS resources. This involved:
-
Configured Each Instance:
-
Jenkins Server:
- I installed Jenkins on the designated server.
- I added the required plugins, to facilitate secure operations.
- I configured credentials within Jenkins, including the GitHub access token, Docker credentials, and SSH access to EC2.
- I created a Jenkins pipeline and prepared it for the CI/CD process.
- I installed Docker on the Jenkins instance to handle containerization tasks.
-
Node.js Instance:
- I installed Docker on the Node.js instance to support containerized applications.
- I set up Node Exporter to collect and expose metrics for monitoring purposes.
-
Monitoring Instance:
- I set up Prometheus on the monitoring instance to scrape and store metrics from various sources.
- I installed and configured Grafana to visualize the metrics collected by Prometheus.
-
-
Created a Webhook on GitHub:
- To automate the build process, I created a webhook on the GitHub repository. This webhook triggers the Jenkins pipeline automatically whenever new code is pushed to the repository.
By following these steps, I successfully set up the necessary infrastructure, configured each instance properly, and ensured that the CI/CD pipeline is ready to handle automated deployments triggered by GitHub webhooks.
-
Cleaning Up Old Builds:
- Too many builds were eating up disk space with old Docker images, which could crash the server. I added a stage in the Jenkins pipeline to clean up these old images and builds.
-
Security Groups:
- Setting up security groups to keep the network communication secure and functional was tricky. I had to make sure the rules allowed the necessary traffic while keeping everything safe.
-
Handling Credentials:
- Keeping all the credentials (GitHub tokens, Docker creds, SSH keys) secure and correctly set up in Jenkins was a bit of a headache. I had to double-check everything to make sure it was all good.
-
Terraform Dependencies:
- Making sure Terraform created resources in the right order was a challenge. I had to keep validating the config to avoid messing things up.
-
Monitoring Setup:
- Getting Prometheus and Grafana up and running took some effort. I had to configure them to collect and show the right metrics and make sure Node Exporter was working on the Node.js instance.
-
Setting Up Webhooks:
- Setting up the GitHub webhook to automatically trigger Jenkins builds was a bit fiddly. I had to make sure it pointed to the right place and handled

