Skip to content

Ghul2002/python-jenkins-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python CI/CD Pipeline with Jenkins & Docker

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.

Architecture & Workflow

The pipeline follows these steps:

  1. Code: Basic Python application with unit tests.
  2. CI (Jenkins): Automatic code download (SCM), running tests in the container.
  3. Build: Building a Docker image and assigning tags based on the build number.
  4. Registry: Authenticating with Docker Hub and pushing the built images to the remote registry.
  5. CD (Deploy): Automatically replacing the container on the production server (Homelab).

Technology

  • Language: Python 3.9
  • Testing: Pytest
  • CI/CD: Jenkins (Pipeline-as-Code)
  • Containerization: Docker & Docker Hub
  • Infrastructure: Linux / Docker-outside-of-Docker

Pipeline Stages

Detailed breakdown of the Jenkinsfile stages:

  • Install & Test: Starts an isolated python:slim container, creates venv, and executes pytest.
  • Build & Push: Logs into Docker Hub, builds an image with the tag ${BUILD_NUMBER} and latest, 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.

Usage

  1. Clone this repository: git clone
  2. Configure Credentials in Jenkins:
  • github-token (Personal Access Token).
  • docker-hub-credentials (Username & Access Token).
  1. Create a "Pipeline" job in Jenkins.
  2. Configure the job to use the Jenkinsfile from SCM.
  3. (Optional) Set the Build Trigger to "Poll SCM" (e.g., * * * * *) for full automation.

Requirements

  • Docker and Docker Compose installed.
  • Jenkins configured with access to /var/run/docker.sock.

Future development

  • Monitoring implementation (Prometheus + Grafana).

Author: Ghul2002

About

CI/CD Pipeline for a Python-based application. It automates the process from code commit to deployment using a Jenkins-based pipeline.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors