This repository demonstrates a complete CI/CD pipeline implementation using GitHub Actions, Docker, and Flask. The project showcases automated workflow orchestration that builds, tests, and deploys a Flask application using Docker containers, with seamless integration to Docker Hub for image distribution.
- Features
- Architecture
- Prerequisites
- Quick Start
- CI/CD Pipeline
- Project Structure
- Configuration
- Deployment
- Contributing
- License
- Automated CI/CD Pipeline: Complete workflow automation using GitHub Actions
- Flask Web Application: Lightweight Python web framework implementation
- Docker Integration: Containerized application for consistent deployment
- Docker Hub Publishing: Automated image publishing to Docker Hub registry
- Multi-stage Builds: Optimized Docker images for production
- Environment Management: Configurable environments for different deployment stages
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β GitHub Repo βββββΆβ GitHub Actions βββββΆβ Docker Hub β
β β β β β β
β β’ Flask App β β β’ Build β β β’ Image Store β
β β’ Dockerfile β β β’ Test β β β’ Version Tags β
β β’ Workflow β β β’ Deploy β β β’ Distribution β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Before getting started, ensure you have the following installed:
- Docker (v20.10+)
- Docker Compose (v2.0+)
- Git
- Python (v3.8+)
git clone https://github.com/rishigupta2004/dockerimagecicd.git
cd dockerimagecicd# Install dependencies
pip install -r requirements.txt
# Run the Flask application locally
python app.pyThe application will be available at http://localhost:5000
# Build the Docker image
docker build -t flask-cicd-app .
# Run the container
docker run -p 5000:5000 flask-cicd-appThe GitHub Actions workflow automatically triggers on:
- Push to main branch: Full CI/CD pipeline execution
- Pull requests: Build and test validation
- Manual trigger: On-demand pipeline execution
- Code Checkout: Retrieves the latest code from the repository
- Environment Setup: Configures Python and Docker environments
- Dependency Installation: Installs required packages
- Testing: Runs unit tests and code quality checks
- Docker Build: Creates optimized Docker images
- Image Tagging: Applies version tags and latest tag
- Docker Hub Push: Publishes images to Docker Hub registry
- Deployment: Deploys to target environment (if configured)
dockerimagecicd/
βββ .github/
β βββ workflows/
β βββ ci-cd.yml # GitHub Actions workflow
βββ app/
β βββ __init__.py
β βββ app.py # Flask application
β βββ requirements.txt # Python dependencies
β βββ templates/
β βββ index.html # HTML templates
βββ tests/
β βββ test_app.py # Unit tests
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose setup
βββ .dockerignore # Docker ignore file
βββ README.md # Project documentation
Create a .env file in the root directory:
# Flask Configuration
FLASK_ENV=production
FLASK_DEBUG=False
SECRET_KEY=your-secret-key-here
# Docker Hub Configuration
DOCKER_USERNAME=your-dockerhub-username
DOCKER_PASSWORD=your-dockerhub-passwordConfigure the following secrets in your GitHub repository:
DOCKER_USERNAME: Your Docker Hub usernameDOCKER_PASSWORD: Your Docker Hub password or access token
Pull and run the latest image:
docker pull rishigupta2004/flask-cicd-app:latest
docker run -p 5000:5000 rishigupta2004/flask-cicd-app:latestFor production deployment:
docker-compose up -dRun the test suite:
# Unit tests
python -m pytest tests/
# With coverage
python -m pytest tests/ --cov=app --cov-report=htmlThe application includes:
- Health check endpoints
- Structured logging
- Docker container monitoring
- CI/CD pipeline status tracking
- 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.
- Flask community for the excellent web framework
- Docker for containerization technology
- GitHub Actions for CI/CD automation
- Contributors and maintainers
Made by Rishi Gupta