No description
  • Python 94.5%
  • Dockerfile 5.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-12-02 07:37:36 +00:00
init-scripts feat: initial commit 2025-12-02 07:35:28 +00:00
webapp feat: initial commit 2025-12-02 07:35:28 +00:00
docker-compose.yml feat: initial commit 2025-12-02 07:35:28 +00:00
README.md feat: readme added 2025-12-02 07:37:36 +00:00

DevOps Database Demo 🚀

A containerized full-stack application demonstrating Docker Compose, PostgreSQL, and Flask integration. This project showcases DevOps best practices including multi-container orchestration, database initialization, and health checks.

📋 Overview

This demo application provides a web interface for managing employees and projects, featuring:

  • PostgreSQL Database: Persistent data storage with relational tables
  • Flask Web App: Interactive UI for CRUD operations
  • Docker Compose: Orchestrated multi-container deployment
  • Database Initialization: Automatic schema creation with sample data

🏗️ Architecture

┌─────────────────┐         ┌──────────────────┐
│                 │         │                  │
│  Flask Web App  │ ◄─────► │  PostgreSQL DB   │
│   (Port 8080)   │         │   (Port 5432)    │
│                 │         │                  │
└─────────────────┘         └──────────────────┘
        │                            │
        └────────────────────────────┘
              demo_network (bridge)

🛠️ Prerequisites

  • Docker (version 20.10 or higher)
  • Docker Compose (version 2.0 or higher)

🚀 Quick Start

  1. Clone the repository (or create the project structure):

    mkdir devops-demo && cd devops-demo
    
  2. Start the application:

    docker-compose up -d
    
  3. Access the web interface:

    http://localhost:8080
    
  4. View logs (optional):

    docker-compose logs -f
    
  5. Stop the application:

    docker-compose down
    

📁 Project Structure

.
├── docker-compose.yml           # Multi-container orchestration
├── init-scripts/
│   └── 01-create-tables.sql    # Database schema and seed data
└── webapp/
    ├── Dockerfile               # Flask app container definition
    ├── app.py                   # Main Flask application
    └── requirements.txt         # Python dependencies

🗄️ Database Schema

Employees Table

  • id - Auto-incrementing primary key
  • name - Employee full name
  • email - Unique email address
  • department - Department assignment
  • salary - Compensation amount
  • created_at - Record creation timestamp

Projects Table

  • id - Auto-incrementing primary key
  • name - Project name
  • description - Project details
  • manager_id - Foreign key to employees (manager)
  • status - Active, completed, or on-hold
  • budget - Project budget
  • start_date / end_date - Project timeline
  • created_at - Record creation timestamp

🔌 Database Connection

Connection String:

postgresql://postgres:devops_password@postgres:5432/demo_db

Connect from host machine using tools like pgAdmin or psql:

psql -h localhost -p 5432 -U postgres -d demo_db
# Password: devops_password

🎯 Features

Web Interface

  • Dashboard: Real-time statistics (employee count, project count, total budget)
  • Employee Management: Add, view, and delete employees
  • Project Management: Create projects with manager assignments
  • Data Validation: Form validation and database constraints

Technical Features

  • Health Checks: Ensures database is ready before app starts
  • Data Persistence: PostgreSQL data survives container restarts
  • Network Isolation: Custom bridge network for secure communication
  • Automatic Initialization: SQL scripts run on first startup

🔧 Configuration

Environment Variables

PostgreSQL (docker-compose.yml):

  • POSTGRES_PASSWORD: Database superuser password
  • POSTGRES_DB: Default database name
  • POSTGRES_USER: Database username

Flask App (docker-compose.yml):

  • DATABASE_URL: PostgreSQL connection string

Port Mappings

  • 8080:5000 - Web application (host:container)
  • 5432:5432 - PostgreSQL database (host:container)

📝 Common Commands

Docker Compose Operations

# Start services in background
docker-compose up -d

# View running containers
docker-compose ps

# View logs
docker-compose logs -f webapp
docker-compose logs -f postgres

# Restart services
docker-compose restart

# Stop and remove containers
docker-compose down

# Stop and remove containers + volumes (DELETES DATA)
docker-compose down -v

# Rebuild containers
docker-compose up -d --build

Database Operations

# Access PostgreSQL CLI
docker exec -it demo_postgres psql -U postgres -d demo_db

# Backup database
docker exec demo_postgres pg_dump -U postgres demo_db > backup.sql

# Restore database
docker exec -i demo_postgres psql -U postgres demo_db < backup.sql

🐛 Troubleshooting

Database connection fails

# Check if PostgreSQL is healthy
docker-compose ps

# View PostgreSQL logs
docker-compose logs postgres

# Restart services
docker-compose restart

Port already in use

# Check what's using the port
lsof -i :8080  # or :5432

# Modify ports in docker-compose.yml if needed

Reset everything

# Stop containers and remove volumes
docker-compose down -v

# Start fresh
docker-compose up -d

🔒 Security Notes

⚠️ This is a development demo only!

For production use, you should:

  • Use strong, unique passwords (not devops_password)
  • Store secrets in environment files or secret managers
  • Use HTTPS/TLS for database connections
  • Implement proper authentication and authorization
  • Enable PostgreSQL SSL mode
  • Use production WSGI server (e.g., Gunicorn) instead of Flask dev server

📚 Learning Resources

🤝 Contributing

This is a demo project for learning purposes. Feel free to:

  • Fork and experiment
  • Add new features (authentication, API endpoints, etc.)
  • Improve the UI
  • Add tests

📄 License

This project is provided as-is for educational purposes.


Built with 🐳 Docker • 🐘 PostgreSQL • 🐍 Flask