version: '3.8'

services:
  # Base de données PostgreSQL
  postgres:
    image: postgres:15-alpine
    container_name: veza-postgres-local
    environment:
      POSTGRES_DB: veza_local
      POSTGRES_USER: veza_user
      POSTGRES_PASSWORD: veza_password
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./scripts/database/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - veza-network

  # Cache Redis
  redis:
    image: redis:7-alpine
    container_name: veza-redis-local
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - veza-network

  # Monitoring - Prometheus
  prometheus:
    image: prom/prometheus:latest
    container_name: veza-prometheus-local
    ports:
      - "9090:9090"
    volumes:
      - ./config/prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
    networks:
      - veza-network

  # Monitoring - Grafana
  grafana:
    image: grafana/grafana:latest
    container_name: veza-grafana-local
    ports:
      - "3000:3000"
    environment:
      GF_SECURITY_ADMIN_PASSWORD: admin
      GF_USERS_ALLOW_SIGN_UP: "false"
    volumes:
      - grafana_data:/var/lib/grafana
      - ./config/grafana/dashboards:/etc/grafana/provisioning/dashboards
      - ./config/grafana/datasources:/etc/grafana/provisioning/datasources
    networks:
      - veza-network

  # Logging - Elasticsearch
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.8.0
    container_name: veza-elasticsearch-local
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ports:
      - "9200:9200"
    volumes:
      - elasticsearch_data:/usr/share/elasticsearch/data
    networks:
      - veza-network

  # Logging - Kibana
  kibana:
    image: docker.elastic.co/kibana/kibana:8.8.0
    container_name: veza-kibana-local
    ports:
      - "5601:5601"
    environment:
      ELASTICSEARCH_HOSTS: http://elasticsearch:9200
    volumes:
      - kibana_data:/usr/share/kibana/data
    networks:
      - veza-network
    depends_on:
      - elasticsearch

  # Logging - Filebeat
  filebeat:
    image: docker.elastic.co/beats/filebeat:8.8.0
    container_name: veza-filebeat-local
    user: root
    volumes:
      - ./config/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
      - /var/lib/docker/containers:/var/lib/docker/containers:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - veza-network
    depends_on:
      - elasticsearch

volumes:
  postgres_data:
  redis_data:
  prometheus_data:
  grafana_data:
  elasticsearch_data:
  kibana_data:

networks:
  veza-network:
    driver: bridge
