A complete MLOps project showcasing automated deployment of a Machine Learning application to AWS EC2 using Docker, GitHub Actions, and ECR.
This project demonstrates production-grade ML deployment with continuous integration and delivery. It features a student performance prediction model deployed as a Flask web application with fully automated CI/CD pipeline.
๐ Live Production Deployment: http://34.228.159.84/
This project focuses on MLOps and Cloud Deployment, featuring:
- โ Complete CI/CD Pipeline: Automated testing โ Docker build โ ECR push โ EC2 deployment
- โ AWS Cloud Infrastructure: EC2, ECR, IAM, Security Groups, and VPC configuration
- โ Containerization: Docker multi-stage builds with optimized image size
- โ Infrastructure as Code: GitHub Actions workflow for automated deployments
- โ Production Best Practices: Gunicorn WSGI server, health checks, logging, monitoring
- โ Zero-Downtime Deployment: Automated container replacement with health verification
- โ Cost-Optimized: Runs on AWS Free Tier (t2.micro)
- Deployment Architecture
- Features
- Tech Stack
- Model Performance
- CI/CD Pipeline
- Quick Start
- AWS Deployment Guide
- Project Structure
- Documentation
- Contributing
- License
GitHub Repository (Push to main)
โ
GitHub Actions Workflow
โ
โโโโโโโดโโโโโโ
โ โ
CI Job Build & Push to ECR
โ โ
โโโโโโโฌโโโโโโ
โ
Deploy to EC2
โ
Docker Container
โ
Flask App (Production)
Deployment Flow:
- Code pushed to
mainbranch triggers GitHub Actions - CI job runs tests and linting
- Docker image built and pushed to AWS ECR with version tags
- SSH deployment to EC2 pulls latest image
- Old container stopped, new container started with health check
- Application live at public IP with zero downtime
- Automated CI/CD: Push code โ Auto-deploy to production in ~3 minutes
- Docker Containerization: Consistent environments from dev to production
- AWS ECR Integration: Private container registry with image versioning
- Blue-Green Deployment: Zero-downtime container replacement
- Health Monitoring: Automated health checks post-deployment
- Security Best Practices: IAM roles, Security Groups, encrypted secrets
- ML Prediction API: Student math score prediction based on 7 features
- Web Interface: Responsive Flask UI with form validation
- RESTful Architecture: Clean API design for future integrations
- Production Logging: Comprehensive logging for debugging and audit trails
- Error Handling: Custom exception framework with detailed error reporting
| Component | Technology | Purpose |
|---|---|---|
| Container Platform | Docker | Application containerization |
| CI/CD | GitHub Actions | Automated build, test, and deployment |
| Container Registry | AWS ECR | Private Docker image storage |
| Compute | AWS EC2 (t2.micro) | Production application hosting |
| Networking | AWS VPC, Security Groups | Network isolation and security |
| IAM | AWS IAM | Access management and permissions |
| WSGI Server | Gunicorn | Production-grade Python app server |
| Version Control | Git/GitHub | Source code management |
| Component | Technology | Purpose |
|---|---|---|
| Language | Python 3.10 | Core programming language |
| Web Framework | Flask | HTTP server and routing |
| ML Framework | scikit-learn | Model training and preprocessing |
| Data Processing | pandas, numpy | Data manipulation |
| Model Storage | dill, pickle | Model serialization |
Measured on the held-out test split from artifacts/test.csv with the same preprocessing pipeline used in training.
| Model | Rยฒ Score | MAE | RMSE |
|---|---|---|---|
| Ridge โ | 0.8806 | 4.2126 | 5.3910 |
| Linear Regression | 0.8795 | 4.2434 | 5.4146 |
| CatBoost | 0.8511 | 4.5752 | 6.0203 |
| Random Forest | 0.8488 | 4.6858 | 6.0652 |
| XGBoost | 0.8231 | 5.0907 | 6.5612 |
Trigger: Push to main branch
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Job 1: Continuous Integration (CI) โ
โ โข Checkout code โ
โ โข Setup Python 3.10 โ
โ โข Install dependencies โ
โ โข Run tests & linting โ
โ โข Validate code quality โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ (Only if CI passes)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Job 2: Build & Push to ECR โ
โ โข Configure AWS credentials โ
โ โข Login to Amazon ECR โ
โ โข Build Docker image โ
โ โข Tag with git SHA & latest โ
โ โข Push to ECR registry โ
โ โข Time: ~1m 43s โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ (After successful push)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Job 3: Deploy to EC2 โ
โ โข SSH to EC2 instance โ
โ โข Pull latest image from ECR โ
โ โข Stop old container gracefully โ
โ โข Start new container on port 80 โ
โ โข Run health check โ
โ โข Clean up old images โ
โ โข Time: ~9s โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ
Deployed to Production: http://34.228.159.84/- Parallel Execution: CI runs on all branches; deployment only on main
- Automated Rollback: Deployment fails if health check doesn't pass
- Version Tagging: Each deployment tagged with git commit SHA
- Secret Management: AWS credentials stored as GitHub encrypted secrets
- Monitoring: Build status visible via GitHub Actions badge
| Stage | Time | Description |
|---|---|---|
| CI (tests + lint) | ~45s | Python setup and quality validation |
| Docker Build + ECR Push | ~1m 43s | Build container image and push to ECR |
| EC2 Deploy | ~9s | Pull latest image, replace container, and health check |
| Total: Push to Production | ~2m 37s (~3 min) | End-to-end automated deployment |
- Python 3.10+
- Git
- Docker (optional, for local container testing)
git clone https://github.com/aashishkumar-tech/mlproject.git
cd mlprojectWindows (PowerShell):
python -m venv venv
.\venv\Scripts\Activate.ps1macOS / Linux:
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtpython app.pyVisit: http://localhost:8080
This project includes step-by-step AWS setup instructions. Follow the guide to deploy your own instance:
๐ AWS-SETUP-GUIDE.md - Complete AWS deployment walkthrough
What you'll create:
- โ IAM user with ECR permissions
- โ ECR repository for Docker images
- โ EC2 Security Group with proper rules
- โ EC2 Key Pair for SSH access
- โ EC2 t2.micro instance (Free Tier)
- โ Docker and AWS CLI installation
- โ GitHub Secrets configuration
- โ Automated deployment pipeline
Time to deploy: ~30 minutes for first-time setup
# 1. Configure GitHub Secrets (in repo settings)
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
ECR_REGISTRY
ECR_REPOSITORY
EC2_HOST
EC2_USER
EC2_SSH_KEY
# 2. Push to main branch
git add .
git commit -m "deploy: initial deployment"
git push origin main
# 3. GitHub Actions automatically deploys to EC2
# Check workflow: https://github.com/aashishkumar-tech/mlproject/actions# Build image
docker build -t mlproject:local .
# Run container
docker run -d -p 80:8080 --name mlproject mlproject:local
# Test
curl http://localhost
# View logs
docker logs mlproject
# Stop container
docker stop mlproject
docker rm mlprojectDockerfile highlights:
- Base image:
python:3.10-slim - Multi-stage optimization
- 2 Gunicorn workers (optimized for 1GB RAM)
- 120s timeout (for model loading)
- Port 8080 exposed
Focus: DevOps & Deployment Components
mlproject/
โโโ .github/
โ โโโ workflows/
โ โโโ ec2-deploy.yml # โญ CI/CD Pipeline (3 jobs)
โโโ Dockerfile # โญ Container configuration
โโโ docker-compose.yml # โญ Local development setup
โโโ .dockerignore # Build optimization
โโโ AWS-SETUP-GUIDE.md # โญ Complete AWS setup guide
โโโ .markdownlint.json # Markdown linting config
โโโ requirements.txt # Python dependencies
โโโ app.py # Flask application
โโโ src/ # ML pipeline code
โ โโโ components/ # Training components
โ โโโ pipeline/ # Inference pipeline
โ โโโ utils.py # Helper functions
โโโ templates/ # HTML templates
โโโ static/ # CSS files
โโโ artifacts/ # Model files (included in Docker)
โโโ logs/ # Application logs
File: .github/workflows/ec2-deploy.yml
graph LR
A[Git Push] --> B{GitHub Actions}
B --> C[CI Job<br/>Tests & Lint]
C -->|Pass| D[Build Job<br/>Docker Build]
D --> E[Push to ECR<br/>Tag: SHA & latest]
E --> F[Deploy Job<br/>SSH to EC2]
F --> G[Pull Image]
G --> H[Stop Old Container]
H --> I[Start New Container]
I --> J[Health Check]
J -->|Pass| K[โ
Live Production]
J -->|Fail| L[โ Rollback]
Total Pipeline Time: ~3 minutes from push to production
Comprehensive documentation for different audiences:
| Document | Audience | Description |
|---|---|---|
| README.md | Everyone | Project overview and quick start |
| AWS-SETUP-GUIDE.md | DevOps Engineers | Complete AWS deployment walkthrough |
| HLD.md | Architects | High-level system design and architecture |
| TECHNICAL_DOC.md | Developers | Code structure and implementation details |
| API_DOCS.md | API Users | API endpoints and usage examples |
| CONTRIBUTING.md | Contributors | Contribution guidelines and coding standards |
โ
CI/CD Pipeline Design: Multi-stage GitHub Actions workflow
โ
Containerization: Docker best practices and optimization
โ
Cloud Infrastructure: AWS EC2, ECR, IAM, VPC configuration
โ
Automation: Automated testing, building, and deployment
โ
Security: IAM roles, encrypted secrets, security groups
โ
Monitoring: Health checks, logging, and error tracking
โ
Documentation: Comprehensive technical documentation
โ
Version Control: Git workflows and branching strategies
- Production-Grade: Not just code that works, but code that deploys automatically
- End-to-End: From local development to production deployment
- Best Practices: Follows industry standards for DevOps and MLOps
- Documented: Every step explained with detailed documentation
- Cost-Effective: Runs on AWS Free Tier
- Portfolio-Ready: Demonstrates real-world deployment skills
Worker Timeout Errors:
# Check Docker logs on EC2
ssh ec2-user@YOUR_EC2_IP
docker logs mlproject --tail 100Solution: Increase Gunicorn timeout in Dockerfile (already set to 120s)
Missing Model Files:
- Ensure
artifacts/is NOT in.dockerignore - Check that model.pkl and preprocessor.pkl exist
SSH Authentication Failed:
- Verify EC2_SSH_KEY secret contains full .pem content
- Include BEGIN and END lines
AWS Credentials Error:
- Rotate IAM access keys
- Update GitHub Secrets
๐ Full troubleshooting guide: See TECHNICAL_DOC.md
- EC2 t2.micro: 750 hours/month - $0.00
- ECR Storage: 500MB/month - $0.00
- Data Transfer: 1GB/month - $0.00
- EC2 t2.micro 24/7: ~$8.50/month
- ECR Storage (5GB): ~$0.50/month
- Data Transfer (10GB): ~$0.90/month
- Total: ~$10/month
Cost Optimization Tips:
- Stop EC2 when not in use (~$0.01/hour)
- Use reserved instances for 30-70% savings
- Clean up old Docker images regularly
- Add Application Load Balancer
- Implement Auto Scaling Groups
- Set up CloudWatch monitoring and alarms
- Enable HTTPS with SSL certificate
- Configure custom domain with Route 53
- Integrate MLflow for experiment tracking
- Add model versioning and A/B testing
- Implement model retraining pipeline
- Set up model performance monitoring
- Add feature store (AWS SageMaker)
- Kubernetes deployment (EKS)
- Terraform IaC implementation
- Multi-region deployment
- Blue-green deployment strategy
- Canary releases
Contributions are welcome! Please see CONTRIBUTING.md for:
- Code of conduct
- Development setup
- Coding standards
- Pull request process
This project is licensed under the MIT License - see the LICENSE file for details.
Aashish Kumar
Skills Demonstrated: Python โข Flask โข Docker โข AWS (EC2, ECR, IAM) โข GitHub Actions โข CI/CD โข MLOps โข DevOps
- AWS Free Tier for hosting infrastructure
- GitHub Actions for CI/CD platform
- Open-source community for tools and libraries
- GitHub Issues: Open an issue
- Email: aashishkumar.tech@gmail.com
- Documentation: Check the docs/ folder
- Live Demo: http://34.228.159.84/
โญ If you find this project useful for learning MLOps and DevOps, please star it on GitHub!
Live Application: http://34.228.159.84/
- Visit the live application
- Click "Get Started" to access prediction form
- Fill in student information
- Get instant math score prediction
- Clone and explore the
.github/workflows/ec2-deploy.ymlfile - Review
Dockerfileand.dockerignorefor containerization best practices - Follow AWS-SETUP-GUIDE.md to deploy your own instance
- Modify and push code to see CI/CD in action
- Showcase automated deployment skills
- Demonstrate AWS cloud infrastructure knowledge
- Highlight CI/CD pipeline design
- Show Docker containerization expertise
Talk about:
- How you designed the 3-stage CI/CD pipeline
- Why you chose specific AWS services (EC2 vs Lambda, ECR vs Docker Hub)
- How you optimized Docker images and Gunicorn configuration
- Security considerations (IAM, Security Groups, encrypted secrets)
- Cost optimization strategies for production deployment
Logs are stored in logs/ directory with timestamps.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Aashish Kumar
- Dataset: Student Performance Dataset
- Inspiration: End-to-end ML project deployment
- Cloud Platform: AWS Free Tier
For issues and questions:
- Open an Issue
- Check the Documentation
- Add authentication and user management
- Implement model versioning with MLflow
- Add unit tests and integration tests
- Set up monitoring with Prometheus/Grafana
- Add custom domain with HTTPS
- Implement A/B testing for model comparison
- Create REST API with FastAPI
- Add real-time prediction streaming
โญ If you find this project useful, please star it on GitHub!