version: "3.9"

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: stonks
      POSTGRES_USER: stonks
      POSTGRES_PASSWORD: stonks_dev
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./infra/migrations:/docker-entrypoint-initdb.d
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U stonks"]
      interval: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      retries: 5

  minio:
    image: minio/minio:latest
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - miniodata:/data
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 5s
      retries: 5

  minio-init:
    image: minio/mc:latest
    depends_on:
      minio:
        condition: service_healthy
    entrypoint: >
      /bin/sh -c "
      mc alias set local http://minio:9000 minioadmin minioadmin;
      mc mb --ignore-existing local/stonks-raw-market;
      mc mb --ignore-existing local/stonks-raw-news;
      mc mb --ignore-existing local/stonks-raw-filings;
      mc mb --ignore-existing local/stonks-normalized;
      mc mb --ignore-existing local/stonks-llm-prompts;
      mc mb --ignore-existing local/stonks-llm-results;
      mc mb --ignore-existing local/stonks-lakehouse;
      mc mb --ignore-existing local/stonks-audit;
      exit 0;
      "

  ollama:
    image: ollama/ollama:latest
    ports:
      - "11434:11434"
    volumes:
      - ollama_models:/root/.ollama

  trino:
    image: trinodb/trino:latest
    ports:
      - "8080:8080"
    environment:
      MINIO_ACCESS_KEY: minioadmin
      MINIO_SECRET_KEY: minioadmin
    volumes:
      - ./infra/trino/catalog:/etc/trino/catalog
    depends_on:
      - minio
      - hive-metastore

  hive-metastore:
    image: apache/hive:4.0.0
    environment:
      SERVICE_NAME: metastore
      DB_DRIVER: derby
    ports:
      - "9083:9083"
    volumes:
      - hive_data:/opt/hive/data
      - ./infra/hive/core-site.xml:/opt/hive/conf/core-site.xml:ro
      - ./infra/hive/metastore-site.xml:/opt/hive/conf/metastore-site.xml:ro
    depends_on:
      - minio

  superset:
    image: apache/superset:latest
    ports:
      - "8088:8088"
    environment:
      SUPERSET_SECRET_KEY: stonks-dev-secret-key-change-me
      ADMIN_USERNAME: admin
      ADMIN_PASSWORD: admin
      ADMIN_EMAIL: admin@stonks.local
    volumes:
      - superset_data:/app/superset_home
    depends_on:
      - trino

volumes:
  pgdata:
  miniodata:
  ollama_models:
  hive_data:
  superset_data:
