version: '3.8'

services:
  # Redis Cache Service
  redis:
    image: redis:7-alpine
    container_name: controles_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - controles_network

  # Flask Application
  app:
    build: .
    container_name: controles_app
    ports:
      - "5000:5000"
    environment:
      - FLASK_APP=app.py
      - FLASK_ENV=production
      - REDIS_URL=redis://redis:6379/0
      - DATABASE_URL=sqlite:///app/database.db
      - ADMIN_OTP_SECRET=JBSWY3DPEHPK3PXP
    volumes:
      - ./database.db:/app/database.db
      - ./admin_qr.png:/app/admin_qr.png
    depends_on:
      redis:
        condition: service_healthy
    restart: unless-stopped
    networks:
      - controles_network

volumes:
  redis_data:
    driver: local

networks:
  controles_network:
    driver: bridge 