A complete CI/CD pipeline setup using Jenkins, Docker, and Terraform to automate the build, deployment, and rollback of a full-stack open-source PoolsApp (mrpool404/poolsapp) using Docker containers application on the AWS EC2.
This repo features:
- A three-stage Jenkins pipeline
- Dockerized frontend and backend apps
- AWS-hosted EC2 instance with pre-installed Docker (via Terraform)
- Docker image versioning, tagging, and stable rollback
- Reusable Jenkins shared library logic
- Frontend: Angular
- Backend: Node.js
- Database: MongoDB
- Containerization: Docker
.
βββ Jenkins
β βββ 01_build_push_images.groovy # Builds Docker images and pushes them to DockerHub
β βββ 02_deploy_with_docker.groovy # Deploys Docker containers to EC2 using docker-compose
β βββ 03_rollback_handler.groovy # Rollback pipeline triggered on deployment failure
β βββ Deployment_Docker.groovy # (Initial approach by me) Combined pipeline if needed
β βββ preInstalledDockerUbuntu.groovy # Jenkins pipeline to provision Docker-ready EC2 via Terraform
βββ Pools-App-Backend # Backend code (Node.js/Express or similar)
βββ Pools-App-Frontend # Frontend code (Angular/React/Vue or similar)
βββ Terraform
β βββ preInstalledDockerUbuntu.tf # Terraform script to provision Docker-ready EC2
βββ docker-compose.yml # Defines frontend, backend, and MongoDB services
βββ README.md # You're here!
βββ LICENSE
βββ images
βββ poolsapp-LICENSE
βββ poolsapp-README.md # Original README from open-source poolsapp project
Each part of the project is modular and easily extendable, with individual Jenkins pipelines for each phase of CI/CD, and infrastructure provisioning handled via Terraform.
Before you can use this project, ensure the following tools and configurations are in place:
- Jenkins with:
- SSH Agent Plugin
- Pipeline Plugin
- Credentials Plugin
- Docker
- AWS CLI
- Terraform v1.5+
- AWS Account with the following:
- IAM Role for Terraform (
role-arn-terrafomRM
) - S3 Bucket named
pools.app-bucket-by-terraform
- Secrets Manager for:
- Database credentials
- Terraform role ARN
- IAM Role for Terraform (
- GitHub repository:
- This repo:
git@github.com:kakarot404/docker_deployment_using_jenkins.git
- Shared Jenkins library:
jenkins-shared-lib
- This repo:
- DockerHub account with credentials stored in Jenkins (
dockerhub-creds
)
In Jenkins, configure the following credentials:
ID | Type | Purpose |
---|---|---|
dockerhub-creds |
Username & Password | DockerHub login |
deployKey_JenkinsDockerDeployemnt_git |
SSH Private Key | GitHub clone over SSH |
SSH-cred-jenkins-nginx |
SSH Private Key | EC2 server access via SSH |
β Note: All infrastructure is provisioned using Terraform and assumes you're deploying to AWS EC2 with Docker pre-installed.
This project provisions a Docker-ready EC2 instance using Terraform + EC2 Image Builder, triggered via a Jenkins pipeline. The instance is created with:
- Ubuntu 20.04
- Docker pre-installed
- AWS CLI v2 installed
- Logs uploaded to an S3 bucket
Terraform
βββ preInstalledDockerUbuntu.tf
Jenkins
βββ preInstalledDockerUbuntu.groovy
The preInstalledDockerUbuntu.groovy
pipeline:
- Downloads the required Terraform file from this repo.
- Retrieves the IAM role ARN from AWS Secrets Manager (
role-arn-terrafomRM
). - Executes
terraform init
andterraform apply
to:- Launch an EC2 instance
- Install Docker (if not already installed)
- Install AWS CLI
- Upload a
hello-world
Docker test log to S3
In Jenkins, create a pipeline job pointing to:
Jenkins/preInstalledDockerUbuntu.groovy
Make sure the Jenkins instance has the required AWS credentials or permissions to assume the role via role_arn.
The following variables are passed at runtime:
Variable Description
assume_role_arn IAM role ARN for Terraform
bucket_name S3 bucket for logs
π Output
Once the pipeline completes:
A new EC2 instance is launched with Docker ready.
Its public IP is returned via Terraform output.
Dockerβs test container log is uploaded to s3://pools.app-bucket-by-terraform/logs/hello_output.log.
This repository follows a multi-stage Jenkins pipeline flow, triggered by GitHub webhooks and executed through Jenkins using a shared library.
Stage | Pipeline Script | Trigger Condition | Description |
---|---|---|---|
01 | 01_build_push_images.groovy |
GitHub Push (webhook) | Clones the repo, builds backend & frontend Docker images, and pushes them to DockerHub. |
02 | 02_deploy_with_docker.groovy |
After successful Stage 01 | Fetches docker-compose.yml and metadata, transfers files to EC2, and deploys containers. |
03 | 03_rollback_handler.groovy |
On Stage 02 failure | Performs rollback to last known stable images if deployment fails. |
π All Jenkins pipelines use this shared Jenkins library.
GitHub Push
β¬οΈ
01_build_push_images.groovy
β¬οΈ (on success)
02_deploy_with_docker.groovy
β¬οΈ (on failure)
03_rollback_handler.groovy
-
Build metadata like GIT_COMMIT, IMAGE_TAG, and BUILD_TIMESTAMP are stored in S3 for reference and rollback.
-
AWS Secrets Manager is used to retrieve environment variables and credentials securely.
All Docker images are:
Tagged with the short commit hash and timestamp (<commit>-<timestamp>)
Pushed as :latest and :stable tags for traceability and rollback
Type File S3 Path
Metadata latest_build.json s3://pools.app-bucket-by-terraform/test/artifact/
Compose File docker-compose.yml s3://pools.app-bucket-by-terraform/test/artifact/
Health Log output.log s3://pools.app-bucket-by-terraform/test/
Rollback Logs rollback-<timestamp>.log s3://pools.app-bucket-by-terraform/test/logs/
Er. Powar Shubham S
GitHub: kakarot404
Docker Hub: https://hub.docker.com/repositories/kakarot404