A Python web application integrated with a full CI/CD pipeline using GitLab CI/CD, Docker, and automated deployment to a remote server.
- Python 3.9 — Application runtime
- Docker — Containerization
- GitLab CI/CD — Automated pipeline (test → build → deploy)
- DockerHub — Container registry
- Linux VPS — Deployment target (via SSH)
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
The .gitlab-ci.yml defines a 3-stage pipeline:
- Runs on a
python:3.9-slimDocker image - Installs dependencies via
make - Executes the test suite with
make test
- 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
- 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
1. Clone the repo:
git clone https://github.com/umarjay/python-app-cicd-gitlab.git
cd python-app-cicd-gitlab2. Install dependencies:
pip install -r src/requirements.txt3. Run the app:
python src/run.py4. Or run via Docker:
docker build -t python-app -f build/Dockerfile .
docker run -d -p 5000:5000 python-appApp will be available at http://localhost:5000
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 |
Code Push │ ▼ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ TEST │────▶│ BUILD │────▶│ DEPLOY │ │ │ │ │ │ │ │make test│ │ docker │ │ ssh into│ │ │ │build&push│ │ VPS & │ │ │ │ │ │ run │ └─────────┘ └─────────┘ └─────────┘
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.