Design an advanced CI/CD pipeline for the project with the following steps:
-
Triggering the Pipeline
- The pipeline is triggered whenever code is pushed or a pull request is merged directly into the master branch.
-
Pipeline Steps
- The pipeline consists of multiple steps and environments (development, staging, and production):
-
Pull the Code
- Fetch the latest code from the repository.
-
Install Dependencies
- Install all necessary dependencies for the project.
-
Lint the Code Base
- Run linting tools to ensure code quality.
-
Test the Code Base
- Execute tests, including SonarQube analysis for code quality and security.
-
Build Docker Image
- If previous steps pass, build the project as a Docker image.
- Scan the Docker image with
trivy
. - Push the Docker image to a private registry.
- Serve test coverage files located at
./coverage/*.html
as a static site using Nginx on the development machine. - Host the development environment using Terraform.
-
Output IP for Coverage Files
- Provide the IP address to access the coverage files served on the instance.
- Temporarily run the built project on the development machine, reverse proxying with Nginx (port 80 -> 3000).
-
Approval for Staging Deployment
- Prompt for approval to ship the built image to the staging environment.
- If approved, proceed to the next steps; otherwise, fail the CI build.
-
Deploy to Staging Environment
- Spin up a new instance for the staging environment and delete the old development instance using Terraform.
- Pull the Docker image and run it.
- Output the link to access the running container and verify the site.
-
Approval for Production Deployment
- Prompt for approval to proceed to the production environment.
- If approved, proceed to the next steps.
-
Deploy to Production Environment
- Destroy the staging environment and spin up a new production environment using Terraform.
- Pull the Docker images and run three instances on different ports.
- Set up Jenkins for load balancing and rate limiting between the instances.
- Output the publicly accessible IP for the production environment.
This CI/CD pipeline ensures a robust and automated process for deploying code across development, staging, and production environments, with necessary checks and approvals at each stage.