This document summarizes the DevOps implementation, containerization, and deployment setup for the Health Care Management System project. The project stack includes FastAPI, PostgreSQL, Redis, and RabbitMQ, with a primary focus on reproducible deployment through Docker and Docker Compose.
As part of the DevOps implementation, the application was containerized to ensure environment consistency, easier deployment, and improved scalability.
Package the FastAPI application and all its dependencies into Docker containers.
Connect the app to PostgreSQL, Redis, and RabbitMQ containers for database, caching, and message brokering.
Ensure reproducible builds using environment variables and Docker Compose orchestration.
The main application was containerized using a Dockerfile that: Uses a lightweight python:3.11-slim base image. Installs project dependencies via requirements.txt. Launches the FastAPI app using Uvicorn on port 8000. Configures environment variables for portability.
The docker-compose.yml file orchestrates multiple containers for: app → FastAPI API container db → PostgreSQL (persistent data layer) redis → Caching layer for performance optimization rabbitmq → Message broker for notification services All services communicate over an internal Docker network.
A .env file was created to manage configuration securely:
POSTGRES_SERVER=db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=healthcare
REDIS_HOST=redis
REDIS_PORT=6379
RABBITMQ_HOST=rabbitmq
This ensures environment isolation without hardcoding credentials.
The config.py file was updated so that the app connects to containerized services via service names (db, redis, rabbitmq) instead of localhost.
After building containers using:
docker compose up --build The API was verified via Swagger UI at http://localhost:8000/docs. The /health endpoint was added to confirm PostgreSQL connectivity. Redis connectivity was tested via /api/test-redis.
Redis was configured and tested to store and retrieve cached data, validating the connectivity and functionality within the container network.
The entire system can now be started with a single command (docker compose up). FastAPI automatically connects to all dependencies within the Docker network. The setup is environment-independent, reproducible, and aligned with DevOps principles.
docker-compose.yml defines services for the API, database, Redis, and RabbitMQ. Used for local development, integration testing, and as a base for CI/CD pipeline builds. Ensures consistent multi-container networking and volume management.
All credentials and connection strings are externalized in .env files. For production, secrets should be stored using Azure Key Vault, AWS Secrets Manager, or HashiCorp Vault. Environment-specific overrides are supported (e.g., .env.staging, .env.prod).
To automate build, test, and deployment, implement a GitHub Actions pipeline with the following stages:
Pipeline Steps Checkout repository. Set up Python (3.10/3.11). Install dependencies (pip install -r requirements.txt). Run linting and unit tests (flake8, pytest). Build Docker image and push to container registry (Docker Hub / GHCR). Deploy to staging or production (via SSH, Kubernetes, or Docker Swarm).
On PR: run tests and linting. On merge to main: build, push, and deploy automatically.
Integrate structured JSON logs and centralize with ELK, Loki, or Datadog. Add /health and /metrics endpoints for readiness and liveness checks. Use Prometheus + Grafana for performance visualization.
Deploy behind an NGINX or Traefik reverse proxy for load balancing. For scaling, use Kubernetes or a managed container platform. Run multiple replicas of API and worker containers. Use shared Redis or DB locks for coordination between distributed workers.
Enforce HTTPS through proxy or ingress controller. Keep database and API credentials encrypted. Rotate secrets periodically and grant minimal permissions.
Tag each Docker image with its Git commit SHA for traceability. Enable quick rollback by redeploying a previously tagged version. Use persistent storage volumes for PostgreSQL and Redis to prevent data loss.