networks:
  dokploy-network:
    external: true

services:
  prefect-server:
    build: .
    networks:
      dokploy-network:
        aliases:
          - prefect
    environment:
      PREFECT_SERVER_API_HOST: 0.0.0.0
      PREFECT_UI_API_URL: https://prefect.optovia.ru/api
      PREFECT_API_DATABASE_CONNECTION_URL: postgresql+asyncpg://postgres:fdlocdpwdjiulmag@optoviaproject-prefectdb-xnriu0:5432/postgres
      # Infisical Machine Identity auth
      INFISICAL_API_URL: ${INFISICAL_API_URL}
      INFISICAL_CLIENT_ID: ${INFISICAL_CLIENT_ID}
      INFISICAL_CLIENT_SECRET: ${INFISICAL_CLIENT_SECRET}
      INFISICAL_PROJECT_ID: ${INFISICAL_PROJECT_ID}
      INFISICAL_ENV: ${INFISICAL_ENV:-prod}
    command: /app/flows/entrypoint_server.sh
    expose:
      - "4200"
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request as u; u.urlopen('http://localhost:4200/api/health', timeout=1)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  prefect-services:
    build: .
    networks:
      - dokploy-network
    depends_on:
      prefect-server:
        condition: service_healthy
    environment:
      PREFECT_API_URL: http://prefect-server:4200/api
      PREFECT_API_DATABASE_CONNECTION_URL: postgresql+asyncpg://postgres:fdlocdpwdjiulmag@optoviaproject-prefectdb-xnriu0:5432/postgres
      ARANGODB_URL: http://optoviaproject-arangodb-qj1hop-arangodb-1:8529
      ARANGODB_DATABASE: optovia_maps
      ARANGODB_PASSWORD: 78gwcnmmnneriiju
      EXCHANGE_GRAPHQL_URL: http://optoviaproject-exchange-pdytpt:8000/graphql/public/
      TEMPORAL_HOST: temporal:7233
      TEMPORAL_NAMESPACE: default
      # Infisical Machine Identity auth
      INFISICAL_API_URL: ${INFISICAL_API_URL}
      INFISICAL_CLIENT_ID: ${INFISICAL_CLIENT_ID}
      INFISICAL_CLIENT_SECRET: ${INFISICAL_CLIENT_SECRET}
      INFISICAL_PROJECT_ID: ${INFISICAL_PROJECT_ID}
      INFISICAL_ENV: ${INFISICAL_ENV:-prod}
    command: /app/flows/entrypoint_services.sh

  prefect-flow-server:
    build: .
    networks:
      - dokploy-network
    depends_on:
      prefect-server:
        condition: service_healthy
    environment:
      PREFECT_API_URL: http://prefect-server:4200/api
      ARANGODB_URL: http://optoviaproject-arangodb-qj1hop-arangodb-1:8529
      ARANGODB_DATABASE: optovia_maps
      ARANGODB_PASSWORD: 78gwcnmmnneriiju
      EXCHANGE_GRAPHQL_URL: http://optoviaproject-exchange-pdytpt:8000/graphql/public/
      TEMPORAL_HOST: temporal:7233
      TEMPORAL_NAMESPACE: default
      # Infisical Machine Identity auth
      INFISICAL_API_URL: ${INFISICAL_API_URL}
      INFISICAL_CLIENT_ID: ${INFISICAL_CLIENT_ID}
      INFISICAL_CLIENT_SECRET: ${INFISICAL_CLIENT_SECRET}
      INFISICAL_PROJECT_ID: ${INFISICAL_PROJECT_ID}
      INFISICAL_ENV: ${INFISICAL_ENV:-prod}
    command: /app/flows/entrypoint.sh
    restart: on-failure
