Skip to content

πŸš€ CI/CD Pipeline with Jenkins, Docker & AWS | Automated deployment of React apps to EC2 using ECR, Nginx & GitHub webhooks

License

Notifications You must be signed in to change notification settings

Smilin01/AWS-Deployment-CI-CD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Resume Builder - CI/CD Pipeline with AWS

Jenkins Docker AWS Nginx

A complete DevOps CI/CD pipeline project demonstrating automated deployment of a React application to AWS using Jenkins, Docker, and Nginx.


πŸ“‹ Table of Contents


πŸ—οΈ Architecture Overview

CI/CD Pipeline Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           CI/CD PIPELINE ARCHITECTURE                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  GitHub  β”‚ ──────► β”‚   Jenkins    β”‚ ──────► β”‚   AWS ECR   β”‚
    β”‚   Repo   β”‚ Webhook β”‚   Server     β”‚  Push   β”‚  Registry   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β”‚ Build                  β”‚ Pull
                                β–Ό                        β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚    Docker    β”‚         β”‚    EC2      β”‚
                         β”‚    Image     β”‚ ──────► β”‚   Server    β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  Deploy β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                        β”‚
                                                        β–Ό
                                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                 β”‚   Nginx     β”‚
                                                 β”‚   + App     β”‚
                                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                        β”‚
                                                        β–Ό
                                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                 β”‚    Users    β”‚
                                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Detailed Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                              β”‚
β”‚    Developer          GitHub           Jenkins          AWS                 β”‚
β”‚        β”‚                β”‚                 β”‚               β”‚                 β”‚
β”‚        β”‚   Push Code    β”‚                 β”‚               β”‚                 β”‚
β”‚        │───────────────►│                 β”‚               β”‚                 β”‚
β”‚        β”‚                β”‚   Webhook       β”‚               β”‚                 β”‚
β”‚        β”‚                │────────────────►│               β”‚                 β”‚
β”‚        β”‚                β”‚                 β”‚               β”‚                 β”‚
β”‚        β”‚                β”‚                 β”‚  Docker Build β”‚                 β”‚
β”‚        β”‚                β”‚                 │──────────────►│                 β”‚
β”‚        β”‚                β”‚                 β”‚               β”‚                 β”‚
β”‚        β”‚                β”‚                 β”‚  Push to ECR  β”‚                 β”‚
β”‚        β”‚                β”‚                 │──────────────►│  ECR            β”‚
β”‚        β”‚                β”‚                 β”‚               β”‚                 β”‚
β”‚        β”‚                β”‚                 β”‚  Deploy       β”‚                 β”‚
β”‚        β”‚                β”‚                 │──────────────►│  EC2            β”‚
β”‚        β”‚                β”‚                 β”‚               β”‚                 β”‚
β”‚        β”‚                β”‚                 β”‚  Health Check β”‚                 β”‚
β”‚        β”‚                β”‚                 │◄──────────────│                 β”‚
β”‚        β”‚                β”‚                 β”‚               β”‚                 β”‚
β”‚        β”‚   Success!     β”‚                 β”‚               β”‚                 β”‚
β”‚        │◄───────────────│◄────────────────│               β”‚                 β”‚
β”‚                                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Category Technology
CI/CD Jenkins
Containerization Docker
Container Registry AWS ECR
Cloud Platform AWS (EC2, ECR, IAM)
Web Server Nginx
Version Control Git, GitHub
Application React + TypeScript + Vite
Backend Services Supabase

πŸ“ Project Structure

resume-builder-devops/
β”œβ”€β”€ πŸ“„ README.md                 # This file
β”œβ”€β”€ πŸ“„ Dockerfile                # Multi-stage Docker build
β”œβ”€β”€ πŸ“„ Jenkinsfile               # CI/CD Pipeline definition
β”œβ”€β”€ πŸ“„ docker-compose.yml        # Local development setup
β”œβ”€β”€ πŸ“„ docker-compose.prod.yml   # Production deployment
β”œβ”€β”€ πŸ“„ .dockerignore             # Docker build exclusions
β”œβ”€β”€ πŸ“ nginx/
β”‚   β”œβ”€β”€ nginx.conf               # Main Nginx configuration
β”‚   β”œβ”€β”€ default.conf             # Server block configuration
β”‚   └── proxy.conf               # Reverse proxy for production
β”œβ”€β”€ πŸ“ scripts/
β”‚   β”œβ”€β”€ setup-jenkins.sh         # Jenkins server setup script
β”‚   β”œβ”€β”€ setup-app-server.sh      # Application server setup
β”‚   └── deploy.sh                # Manual deployment script
└── πŸ“ docs/
    β”œβ”€β”€ DEPLOYMENT_GUIDE.md      # Detailed deployment guide
    └── TROUBLESHOOTING.md       # Common issues and solutions

✨ Features

CI/CD Pipeline

  • βœ… Automated Builds: Triggered on every push to main branch
  • βœ… Docker Multi-stage Build: Optimized image size
  • βœ… AWS ECR Integration: Secure container registry
  • βœ… Automated Deployment: Zero-downtime deployment to EC2
  • βœ… Health Checks: Automatic verification after deployment

Infrastructure

  • βœ… Nginx Reverse Proxy: SSL termination and load balancing
  • βœ… Docker Containerization: Consistent environments
  • βœ… Environment Variables: Secure secrets management
  • βœ… Gzip Compression: Optimized content delivery
  • βœ… Security Headers: XSS, CSRF protection

Monitoring

  • βœ… Container Health Checks: Built-in Docker health monitoring
  • βœ… Nginx Access Logs: Request logging and analysis
  • βœ… Jenkins Build History: Pipeline execution tracking

πŸ“‹ Prerequisites

AWS Account

  • EC2 instances (2x - Jenkins + App server)
  • ECR repository
  • IAM roles with appropriate permissions

Local Development

  • Docker Desktop
  • Git
  • Node.js 20+

Jenkins Server Requirements

  • Ubuntu 22.04 LTS
  • Java 17+
  • Docker
  • AWS CLI

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/yourusername/resume-builder-devops.git
cd resume-builder-devops

2. Local Development with Docker

# Build and run locally
docker-compose up --build

# Access the application
open http://localhost:3000

3. Production Deployment

# Deploy with SSL (on EC2)
docker-compose -f docker-compose.prod.yml up -d

πŸ“– Detailed Setup Guide

Step 1: AWS Infrastructure Setup

EC2 Instances

Jenkins Server:

  • Instance Type: t3.small or t3.medium
  • AMI: Ubuntu 22.04 LTS
  • Storage: 20GB
  • Security Group Ports: 22, 8080

Application Server:

  • Instance Type: t3.micro or t3.small
  • AMI: Ubuntu 22.04 LTS
  • Storage: 10GB
  • Security Group Ports: 22, 80, 443, 3000

ECR Repository

# Create ECR repository
aws ecr create-repository --repository-name resume-builder --region ap-south-1

Step 2: Jenkins Server Setup

SSH into Jenkins server and run:

#!/bin/bash
# Update system
sudo apt update && sudo apt upgrade -y

# Install Java
sudo apt install -y fontconfig openjdk-17-jdk

# Install Docker
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntu

# Install Jenkins
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/" | \
  sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt update
sudo apt install -y jenkins

# Add jenkins to docker group
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins

# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install -y unzip
unzip awscliv2.zip
sudo ./aws/install

# Show Jenkins initial password
echo "=== Jenkins Initial Password ==="
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Step 3: Configure Jenkins Credentials

Add these credentials in Jenkins (Manage Jenkins β†’ Credentials):

ID Type Description
aws-ecr-registry Secret text ECR registry URL
vite-openrouter-api-key Secret text OpenRouter API Key
vite-supabase-url Secret text Supabase URL
vite-supabase-anon-key Secret text Supabase Anon Key
ec2-host-ip Secret text App EC2 Public IP
ec2-ssh-key SSH Username with private key EC2 SSH Key
github-credentials Username with password GitHub PAT

Step 4: Create Jenkins Pipeline

  1. New Item β†’ Pipeline
  2. Pipeline from SCM β†’ Git
  3. Repository URL: Your GitHub repo
  4. Branch: */main
  5. Script Path: Jenkinsfile

πŸ”„ Pipeline Stages

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     JENKINS PIPELINE STAGES                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ Checkout │───►│  Docker  │───►│ Push to  │───►│ Deploy   β”‚
    β”‚   Code   β”‚    β”‚  Build   β”‚    β”‚   ECR    β”‚    β”‚ to EC2   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                          β”‚
                                                          β–Ό
                                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                    β”‚  Health  β”‚
                                                    β”‚  Check   β”‚
                                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Stage Description Duration
Checkout Clone repository from GitHub ~5s
Docker Build Multi-stage build with Nginx ~60s
Push to ECR Tag and push to AWS ECR ~10s
Deploy to EC2 SSH deploy and restart container ~15s
Health Check Verify application is running ~10s

βš™οΈ Configuration

Environment Variables

Variable Description
VITE_OPENROUTER_API_KEY OpenRouter API key for AI features
VITE_SUPABASE_URL Supabase project URL
VITE_SUPABASE_ANON_KEY Supabase anonymous key

Nginx Configuration

The application uses Nginx with:

  • Gzip compression enabled
  • Static file caching
  • SPA routing support
  • Security headers

Docker Build

Multi-stage build process:

  1. Stage 1 (Builder): Node.js builds the React app
  2. Stage 2 (Production): Nginx serves the built assets

πŸ“Š Monitoring & Logging

Container Logs

# View application logs
docker logs resume-builder-app

# Follow logs in real-time
docker logs -f resume-builder-app

Nginx Access Logs

# Access logs
docker exec resume-builder-app cat /var/log/nginx/access.log

# Error logs
docker exec resume-builder-app cat /var/log/nginx/error.log

Health Check

# Check container health
docker inspect --format='{{.State.Health.Status}}' resume-builder-app

# Manual health check
curl http://localhost:3000/health

πŸ”§ Troubleshooting

Common Issues

Issue Solution
Docker permission denied sudo usermod -aG docker jenkins && sudo systemctl restart jenkins
ECR login failed Configure AWS CLI: aws configure
SSH connection timeout Check security group rules
Health check failing Verify port 3000 is open

Debug Commands

# Check Docker status
sudo systemctl status docker

# Check Jenkins status
sudo systemctl status jenkins

# List running containers
docker ps

# Check container logs
docker logs resume-builder-app

πŸ“Έ Screenshots

AWS EC2 Instances

Jenkins Server and Application Server running on AWS EC2

AWS EC2 Instances

Jenkins Pipeline - Successful Build

Complete CI/CD pipeline execution with all stages passed

Jenkins Pipeline Success

AWS ECR Repository

Docker images stored in Amazon Elastic Container Registry

AWS ECR Repository

AWS IAM Role Configuration

IAM role with ECR permissions attached to EC2 instances

AWS IAM Role

Server Access Logs

Live server logs showing application requests

Server Logs

Docker Container Running

Docker container running with health status showing "healthy"

Docker Container Running

Docker Container Stats

Real-time resource usage monitoring of the deployed container

Docker Container Stats


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

John Smilin DS


πŸ™ Acknowledgments


⭐ Star this repository if you found it helpful!

About

πŸš€ CI/CD Pipeline with Jenkins, Docker & AWS | Automated deployment of React apps to EC2 using ECR, Nginx & GitHub webhooks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published