This project demonstrates a complete CI/CD lifecycle for a Python-based application. It automates the process from code commit to production deployment using a Jenkins-based pipeline running in a local homelab environment.
The pipeline follows these steps:
- Code: Basic Python application with unit tests.
- CI (Jenkins): Automatic code download (SCM), running tests in the container.
- Build: Building a Docker image and assigning tags based on the build number.
- Registry: Authenticating with Docker Hub and pushing the built images to the remote registry.
- CD (Deploy): Automatically replacing the container on the production server (Homelab).
- Language: Python 3.9
- Testing: Pytest
- CI/CD: Jenkins (Pipeline-as-Code)
- Containerization: Docker & Docker Hub
- Infrastructure: Linux / Docker-outside-of-Docker
Detailed breakdown of the Jenkinsfile stages:
- Install & Test: Starts an isolated
python:slimcontainer, createsvenv, and executespytest. - Build & Push: Logs into Docker Hub, builds an image with the tag
${BUILD_NUMBER}andlatest, and then uploads it to the registry. - Deploy: It connects to the Docker daemon on the host, stops the old version of the application, and runs the latest one downloaded from Docker Hub.
- Clone this repository:
git clone - Configure Credentials in Jenkins:
github-token(Personal Access Token).docker-hub-credentials(Username & Access Token).
- Create a "Pipeline" job in Jenkins.
- Configure the job to use the
Jenkinsfilefrom SCM. - (Optional) Set the Build Trigger to "Poll SCM" (e.g., * * * * *) for full automation.
- Docker and Docker Compose installed.
- Jenkins configured with access to
/var/run/docker.sock.
- Monitoring implementation (Prometheus + Grafana).
Author: Ghul2002