Skip to content

πŸš€ Automated CI/CD pipeline using GitHub Actions, Docker, and Flask - from code to deployment in minutes!

Notifications You must be signed in to change notification settings

rishigupta2004/dockerimagecicd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Docker CI/CD Pipeline with Flask and GitHub Actions

πŸš€ Overview

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.

πŸ“‹ Table of Contents

✨ Features

  • 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   GitHub Repo   │───▢│  GitHub Actions │───▢│   Docker Hub    β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ Flask App     β”‚    β”‚ β€’ Build         β”‚    β”‚ β€’ Image Store   β”‚
β”‚ β€’ Dockerfile    β”‚    β”‚ β€’ Test          β”‚    β”‚ β€’ Version Tags  β”‚
β”‚ β€’ Workflow      β”‚    β”‚ β€’ Deploy        β”‚    β”‚ β€’ Distribution  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Prerequisites

Before getting started, ensure you have the following installed:

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/rishigupta2004/dockerimagecicd.git
cd dockerimagecicd

2. Local Development Setup

# Install dependencies
pip install -r requirements.txt

# Run the Flask application locally
python app.py

The application will be available at http://localhost:5000

3. Docker Setup

# Build the Docker image
docker build -t flask-cicd-app .

# Run the container
docker run -p 5000:5000 flask-cicd-app

πŸ”„ CI/CD Pipeline

The 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

Pipeline Stages

  1. Code Checkout: Retrieves the latest code from the repository
  2. Environment Setup: Configures Python and Docker environments
  3. Dependency Installation: Installs required packages
  4. Testing: Runs unit tests and code quality checks
  5. Docker Build: Creates optimized Docker images
  6. Image Tagging: Applies version tags and latest tag
  7. Docker Hub Push: Publishes images to Docker Hub registry
  8. Deployment: Deploys to target environment (if configured)

πŸ“ Project Structure

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

βš™οΈ Configuration

Environment Variables

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-password

GitHub Secrets

Configure the following secrets in your GitHub repository:

  • DOCKER_USERNAME: Your Docker Hub username
  • DOCKER_PASSWORD: Your Docker Hub password or access token

🚒 Deployment

Docker Hub Image

Pull and run the latest image:

docker pull rishigupta2004/flask-cicd-app:latest
docker run -p 5000:5000 rishigupta2004/flask-cicd-app:latest

Docker Compose

For production deployment:

docker-compose up -d

πŸ§ͺ Testing

Run the test suite:

# Unit tests
python -m pytest tests/

# With coverage
python -m pytest tests/ --cov=app --cov-report=html

πŸ” Monitoring and Logging

The application includes:

  • Health check endpoints
  • Structured logging
  • Docker container monitoring
  • CI/CD pipeline status tracking

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the 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.

πŸ™ Acknowledgments

  • Flask community for the excellent web framework
  • Docker for containerization technology
  • GitHub Actions for CI/CD automation
  • Contributors and maintainers

Made by Rishi Gupta

About

πŸš€ Automated CI/CD pipeline using GitHub Actions, Docker, and Flask - from code to deployment in minutes!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published