version: '3'
services:
  migrations:
    image: marbas:local
    build:
        context: .
        dockerfile: Dockerfile
    env_file:
      - .env
    user: "1000:1000"
    volumes:
      - ./marbas:/app/marbas
      - ./api:/app/api
      - ./sde:/app/sde
      - ./manage.py:/app/manage.py
    command: sh -c "python manage.py makemigrations && python manage.py migrate"
    depends_on:
      db:
        condition: service_healthy

  eveal:
    image: marbas:local
    env_file:
      - .env
    ports:
      - 8000:8000
    user: "1000:1000"
    volumes:
      - ./marbas:/app/marbas
      - ./api:/app/api
      - ./sde:/app/sde
      - ./manage.py:/app/manage.py
#      - ./static_eve:/app/static_eve
    command: ["uvicorn", "marbas.asgi:application", "--host", "0.0.0.0", "--port", "8000", "--reload"]
    depends_on:
      redis:
        condition: service_healthy
      db:
        condition: service_healthy
      migrations:
        condition: service_completed_successfully
#      elasticsearch:
#        condition: service_healthy

  redis:
    image: redis:latest
    ports:
      - 6379:6379
    healthcheck:
      test: redis-cli ping
      interval: 3s

  db:
    image: postgres:13-alpine
    ports:
      - 5432:5432
    volumes:
      - marbas_dbdata:/var/lib/postgresql/data
    env_file:
      - .env
    healthcheck:
      test: pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}
      interval: 1s
      timeout: 3s
      retries: 10

#  elasticsearch:
#    image: elasticsearch:latest
#    ports:
#      - 9200:9200
#    environment:
#        - discovery.type=single-node
#        - cluster.name=elasticsearch
#        - bootstrap.memory_lock=true
#        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
#    healthcheck:
#      test: curl -s http://elasticsearch:9200 >/dev/null || exit 1
#      interval: 10s
#      timeout: 3s
#      retries: 3

volumes:
    marbas_dbdata:
