This repository contains a production-ready DevOps setup for the Branch Loan API. The goal of this project is to containerize the existing API, enable secure HTTPS access, support multiple environments, and automate build and release using CI/CD.
The API is a backend-only service (no frontend UI) that exposes REST endpoints for managing microloans. This setup focuses on reliability, security, and reproducibility across environments.
The application is composed of three main services running in Docker containers:
Browser / curl
|
HTTPS (443)
v
+-------------+
| Nginx |
| (TLS Proxy) |
+-------------+
|
HTTP (8000)
v
+-------------+ +--------------------+
| Flask API | <----> | PostgreSQL DB |
| (Gunicorn) | | (Persistent) |
+-------------+ +--------------------+
- Requests are made to
https://branchloans.com - Nginx terminates HTTPS using a self-signed certificate (local development)
- Traffic is proxied to the Flask API container
- The API communicates with PostgreSQL over Docker’s internal network
- Database schema is managed using Alembic migrations
Ensure the following are installed:
- Docker (v20+)
- Docker Compose v2
- Git
- OpenSSL
Tested on Windows/Linux using Docker Desktop.
git clone https://github.com/<your-username>/dummy-branch-app.git
cd dummy-branch-app Add the following entry to your hosts file:
127.0.0.1 branchloans.comLocations:
- Windows:
C:\Windows\System32\drivers\etc\hosts - Linux/macOS:
/etc/hosts
This allows accessing the API via https://branchloans.com.
Create a directory for certificates:
mkdir -p certsGenerate the certificate:
openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout certs/branchloans.key \
-out certs/branchloans.crt \
-subj "/C=IN/ST=KA/L=Bangalore/O=Branch/OU=Dev/CN=branchloans.com"Note: Browsers will show a warning for self-signed certificates. This is expected for local development.
Build and start services with Docker Compose:
docker compose up -d --buildThis starts the following containers:
- PostgreSQL database
- Flask API (via Gunicorn)
- Nginx reverse proxy (HTTPS)
Verify containers:
docker compose psdocker compose exec api alembic upgrade headcurl -k https://branchloans.com/api/loansThe project supports multiple environments using environment variables.
Files:
.env.example– sample variables (committed).env.dev– local development (not committed).env.staging/.env.prod– future environments
Switching environments:
ENV_FILE=.env.dev docker compose up -dApproach:
- Avoids hardcoding secrets
- Keeps one compose file
- Matches production practices
docker compose exec api alembic upgrade headInsert sample loan data:
docker compose exec api python scripts/seed.pyThis is not used in CI or production. In real deployments, data is created via API calls.
Continuous integration and deployment are implemented using GitHub Actions.
Trigger conditions:
- Push to
main - Pull requests
Pipeline stages:
- Checkout code
- Install Python dependencies
- Run tests (if present)
- Build Docker image
- Scan image for CRITICAL vulnerabilities (via Trivy)
- Push image to GitHub Container Registry (GHCR)
Images are tagged using the Git commit SHA for traceability. Images are pushed only on successful pushes to main; pull requests do not publish images.
- No secrets stored in code
- Uses GitHub-provided
GITHUB_TOKEN - Pipeline fails on CRITICAL vulnerabilities
- HTTPS enabled via Nginx
- Backend API not directly exposed
- Secrets managed via environment variables
- Database credentials not committed
- Vulnerability scanning enforced in CI
-At this stage, observability is provided through application logs and container logs available via Docker.
-In a production environment, this setup could be extended with centralized logging, metrics collection, and alerting using tools such as Prometheus, Grafana, ELK stack, or cloud-native monitoring services.
-Health check endpoints (/health) are exposed to support uptime monitoring and
service readiness checks.
Containers not running
docker compose ps
docker compose up -dDatabase errors
docker compose exec api alembic upgrade headHTTPS issues
- Ensure
branchloans.comis mapped to127.0.0.1 - Accept self-signed certificate warning in browser
Empty /api/loans response
- Run seed script for demo data
- Empty list is expected on fresh databases
Docker & Docker Compose
- Simplifies setup and ensures portability.
Nginx for HTTPS
- Simulates real-world TLS termination used in production (ALB / Ingress).
Environment-based configuration
- Enables the same setup for dev, staging, and production.
GitHub Container Registry (GHCR)
- Provides integrated authentication and clean deployment workflow.
Trade-offs
- Self-signed certificates used for local development only
- No frontend UI (API-only service)
- Production TLS via managed certificates
- Centralized logging and metrics
- Kubernetes deployment
- Automated database migrations in release pipeline
This project demonstrates:
- Production-ready containerization
- Secure HTTPS setup
- Multi-environment configuration
- Automated CI/CD with security scanning
- Clear, reproducible documentation