services:
  db:
    image: postgres:15
    environment:
      - POSTGRES_USER=mypasteuser
      - POSTGRES_PASSWORD=mypastepassword
      - POSTGRES_DB=mypastedb
    volumes:
      - db_data:/var/lib/postgresql/data
    networks:
      - my_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mypasteuser -d mypastedb"]
      interval: 5s
      timeout: 3s
      retries: 5

  app:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - ./uploads:/app/uploads
    environment:
      - DB_ENGINE=postgres
      - POSTGRES_USER=mypasteuser
      - POSTGRES_PASSWORD=mypastepassword
      - POSTGRES_DB=mypastedb
      - POSTGRES_HOST=db
      - POSTGRES_PORT=5432
      - VALID_USER=admin
      - VALID_PASS=password
      - FLASK_ENV=production
      - ELASTICSEARCH_HOST=http://elasticsearch:9200  # Agregado
    depends_on:
      db:
        condition: service_healthy
      elasticsearch:
        condition: service_started
    networks:
      - my_network

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.9.0
    environment:
      - discovery.type=single-node  # Configuración básica para un nodo único
      - ES_JAVA_OPTS=-Xms512m -Xmx512m  # Configuración de memoria
      - xpack.security.enabled=false
      - action.auto_create_index=true
    ports:
      - "9200:9200"  # Puerto HTTP
      - "9300:9300"  # Puerto de comunicación entre nodos
    networks:
      - my_network
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:9200 || exit 1"]
      interval: 5s
      timeout: 3s
      retries: 5

volumes:
  db_data:

networks:
  my_network:
    driver: bridge

