Skip to content

Repository files navigation

Python App with CI/CD Pipeline (GitLab)

A Python web application integrated with a full CI/CD pipeline using GitLab CI/CD, Docker, and automated deployment to a remote server.

🔧 Tech Stack

  • Python 3.9 — Application runtime
  • Docker — Containerization
  • GitLab CI/CD — Automated pipeline (test → build → deploy)
  • DockerHub — Container registry
  • Linux VPS — Deployment target (via SSH)

📁 Project Structure

python-app/ ├── build/ │ └── Dockerfile ├── deploy/ │ ├── kubernetes/ │ │ ├── aks-live.yaml │ │ ├── app.sample.yaml │ │ └── readme.md │ └── webapp.bicep ├── src/ │ ├── app/ │ │ ├── static/ │ │ │ ├── css/ │ │ │ │ └── main.css │ │ │ ├── img/ │ │ │ │ ├── docker-whale.svg │ │ │ │ ├── favicon.ico │ │ │ │ ├── flask.png │ │ │ │ ├── github-2.svg │ │ │ │ └── python.svg │ │ │ └── js/ │ │ │ ├── monitor.js │ │ │ └── sorttable.js │ │ ├── templates/ │ │ │ ├── base.html │ │ │ ├── index.html │ │ │ ├── info.html │ │ │ └── monitor.html │ │ ├── tests/ │ │ │ ├── test_api.py │ │ │ └── test_views.py │ │ ├── init.py │ │ ├── apis.py │ │ ├── conftest.py │ │ └── views.py │ ├── requirements.txt │ └── run.py ├── .gitlab-ci.yml ├── CONTRIBUTING.md ├── LICENSE ├── makefile └── README.md

⚙️ CI/CD Pipeline Overview

The .gitlab-ci.yml defines a 3-stage pipeline:

1. test

  • Runs on a python:3.9-slim Docker image
  • Installs dependencies via make
  • Executes the test suite with make test

2. build

  • Uses Docker-in-Docker (docker:dind) to build the image
  • Tags and pushes the image to DockerHub: umarjay/umarjalal:python-app1.0
  • Credentials are stored securely as GitLab CI/CD variables

3. deploy

  • SSHs into a remote VPS using a stored SSH key
  • Stops and removes any running containers
  • Pulls and runs the newly built Docker image on port 5000

🚀 How to Run Locally

1. Clone the repo:

git clone https://github.com/umarjay/python-app-cicd-gitlab.git
cd python-app-cicd-gitlab

2. Install dependencies:

pip install -r src/requirements.txt

3. Run the app:

python src/run.py

4. Or run via Docker:

docker build -t python-app -f build/Dockerfile .
docker run -d -p 5000:5000 python-app

App will be available at http://localhost:5000

🔐 GitLab CI/CD Variables Required

These must be set in GitLab → Settings → CI/CD → Variables:

Variable Description
REGISTRY_USER DockerHub username
REGISTRY_PASS DockerHub password
SSH_KEY Private SSH key to access the VPS

📌 Pipeline Diagram

Code Push │ ▼ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ TEST │────▶│ BUILD │────▶│ DEPLOY │ │ │ │ │ │ │ │make test│ │ docker │ │ ssh into│ │ │ │build&push│ │ VPS & │ │ │ │ │ │ run │ └─────────┘ └─────────┘ └─────────┘

📝 Notes

This project uses benc-uk/python-demoapp as the base application (MIT licensed). The focus of this project is the CI/CD pipeline implementation using GitLab CI/CD, Docker, and automated VPS deployment — which was built entirely by me.

About

Python Flask app with a full CI/CD pipeline using GitLab CI/CD, Docker and automated VPS deployment

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages