Files
quality_app/docker-compose.yml
2025-11-03 21:17:10 +02:00

240 lines
7.9 KiB
YAML

version: '3.8'
# ============================================================================
# Recticel Quality Application - Docker Compose Configuration
# Production-ready setup with health checks, logging, and resource limits
# ============================================================================
services:
# ==========================================================================
# MariaDB Database Service
# ==========================================================================
db:
image: mariadb:11.3
container_name: trasabilitate-db
restart: unless-stopped
environment:
# Root credentials
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
# Application database and user
MYSQL_DATABASE: ${DB_NAME:-trasabilitate}
MYSQL_USER: ${DB_USER:-trasabilitate}
MYSQL_PASSWORD: ${DB_PASSWORD:-Initial01!}
# Performance tuning
MYSQL_INNODB_BUFFER_POOL_SIZE: ${MYSQL_BUFFER_POOL:-256M}
MYSQL_MAX_CONNECTIONS: ${MYSQL_MAX_CONNECTIONS:-150}
ports:
- "${DB_PORT:-3306}:3306"
volumes:
# Persistent database storage
- ${DB_DATA_PATH:-/srv/docker-test/mariadb}:/var/lib/mysql
# Custom initialization scripts
- ./init-db.sql:/docker-entrypoint-initdb.d/01-init.sql:ro
# Custom MariaDB configuration (optional)
# - ./my.cnf:/etc/mysql/conf.d/custom.cnf:ro
networks:
- recticel-network
# Comprehensive health check
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# Resource limits (adjust based on your server capacity)
deploy:
resources:
limits:
cpus: '2.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 256M
# Logging configuration
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# ==========================================================================
# Flask Web Application Service
# ==========================================================================
web:
build:
context: .
dockerfile: Dockerfile
args:
BUILD_DATE: ${BUILD_DATE:-}
VERSION: ${VERSION:-1.0.0}
VCS_REF: ${VCS_REF:-}
image: recticel-quality-app:${VERSION:-latest}
container_name: recticel-app
restart: unless-stopped
# Wait for database to be healthy before starting
depends_on:
db:
condition: service_healthy
environment:
# ======================================================================
# Database Connection Settings
# ======================================================================
DB_HOST: db
DB_PORT: ${DB_PORT:-3306}
DB_NAME: ${DB_NAME:-trasabilitate}
DB_USER: ${DB_USER:-trasabilitate}
DB_PASSWORD: ${DB_PASSWORD:-Initial01!}
# Database connection tuning
DB_MAX_RETRIES: ${DB_MAX_RETRIES:-60}
DB_RETRY_INTERVAL: ${DB_RETRY_INTERVAL:-2}
# ======================================================================
# Flask Application Settings
# ======================================================================
FLASK_ENV: ${FLASK_ENV:-production}
FLASK_APP: run.py
SECRET_KEY: ${SECRET_KEY:-change-this-in-production}
# ======================================================================
# Gunicorn Configuration (override defaults)
# ======================================================================
GUNICORN_WORKERS: ${GUNICORN_WORKERS:-}
GUNICORN_WORKER_CLASS: ${GUNICORN_WORKER_CLASS:-sync}
GUNICORN_TIMEOUT: ${GUNICORN_TIMEOUT:-120}
GUNICORN_BIND: ${GUNICORN_BIND:-0.0.0.0:8781}
GUNICORN_LOG_LEVEL: ${GUNICORN_LOG_LEVEL:-info}
GUNICORN_PRELOAD_APP: ${GUNICORN_PRELOAD_APP:-true}
GUNICORN_MAX_REQUESTS: ${GUNICORN_MAX_REQUESTS:-1000}
# For Docker logging to stdout/stderr, set these to "-"
# GUNICORN_ACCESS_LOG: "-"
# GUNICORN_ERROR_LOG: "-"
# ======================================================================
# Initialization Flags
# ======================================================================
# Set to "false" after first successful deployment
INIT_DB: ${INIT_DB:-true}
SEED_DB: ${SEED_DB:-true}
# Error handling
IGNORE_DB_INIT_ERRORS: ${IGNORE_DB_INIT_ERRORS:-false}
IGNORE_SEED_ERRORS: ${IGNORE_SEED_ERRORS:-false}
# Skip health check (for faster startup in dev)
SKIP_HEALTH_CHECK: ${SKIP_HEALTH_CHECK:-false}
# ======================================================================
# Timezone and Locale
# ======================================================================
TZ: ${TZ:-Europe/Bucharest}
LANG: ${LANG:-en_US.UTF-8}
# ======================================================================
# Backup Configuration
# ======================================================================
BACKUP_PATH: ${BACKUP_PATH:-/srv/quality_recticel/backups}
ports:
- "${APP_PORT:-8781}:8781"
volumes:
# Persistent logs directory
- ${LOGS_PATH:-/srv/docker-test/logs}:/srv/quality_recticel/logs
# Instance configuration directory
- ${INSTANCE_PATH:-/srv/docker-test/instance}:/app/instance
# Database backups directory
- ${BACKUP_PATH:-/srv/docker-test/backups}:/srv/quality_recticel/backups
# ⚠️ DEVELOPMENT ONLY: Mount application code for live updates
# DISABLE IN PRODUCTION - causes configuration and security issues
# - ./py_app:/app
networks:
- recticel-network
# Application health check
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8781/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# Resource limits (adjust based on your application needs)
deploy:
resources:
limits:
cpus: '2.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 256M
# Logging configuration
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "5"
compress: "true"
# ============================================================================
# Network Configuration
# ============================================================================
networks:
recticel-network:
driver: bridge
ipam:
config:
- subnet: ${NETWORK_SUBNET:-172.20.0.0/16}
# ============================================================================
# NOTES:
# ============================================================================
# 1. Environment Variables:
# - Create a .env file in the same directory for custom configuration
# - See .env.example for available options
#
# 2. First-Time Setup:
# - Set INIT_DB=true and SEED_DB=true for initial deployment
# - After successful setup, set them to false to avoid re-initialization
#
# 3. Volumes:
# - Using bind mounts to /srv/docker-test/ for easy access
# - Ensure the host directories exist and have proper permissions
#
# 4. Security:
# - Change default passwords in production
# - Set a secure SECRET_KEY
# - Use secrets management for sensitive data
#
# 5. Scaling:
# - Adjust resource limits based on your server capacity
# - Use 'docker-compose up --scale web=3' to run multiple app instances
# (requires load balancer setup)
#
# 6. Commands:
# - Start: docker-compose up -d
# - Stop: docker-compose down
# - Logs: docker-compose logs -f web
# - Rebuild: docker-compose up -d --build
# ============================================================================