name: 'reptracker'
services:
  haf:
    image: ${HAF_REGISTRY:-registry.gitlab.syncad.com/hive/haf/instance}:${HAF_VERSION:-9ec94375}
    entrypoint: /home/haf_admin/docker_entrypoint.sh
    command: $${HAF_COMMAND}
    environment:
      HIVED_UID:
      HAF_COMMAND: --shared-file-size=1G --plugin database_api --replay --stop-at-block=5000000
      DATADIR: /home/hived/datadir
      SHM_DIR: /home/hived/shm_dir
      PG_ACCESS: "
        host    haf_block_log    reptracker_user    all    trust\n
        host    haf_block_log    reptracker_owner   all    trust\n
        host    haf_block_log    haf_admin        all    trust\n
        host    postgres         haf_admin        all    trust\n
        host    haf_block_log    pghero           all    trust\n
        host    postgres         pghero           all    trust\n
        host    haf_block_log    reptracker_owner   all    trust\n
        "
    ports:
      - "5432:5432"
    volumes:
      - haf_datadir:/home/hived/datadir
      - haf_shmdir:/home/hived/shm_dir
      - ./blockchain:/home/hived/datadir/blockchain
      - ./scripts/haf-healthcheck.sh:/home/hived/healthcheck.sh
    networks:
      haf-network:
    healthcheck:
      test: ["CMD-SHELL","/home/hived/healthcheck.sh"]
      interval: 60s
      timeout: 10s
      retries: 3
      start_period: 48h #time for replay to finish
  backend-setup:
    image: ${BACKEND_REGISTRY:-registry.gitlab.syncad.com/hive/reputation_tracker}:${BACKEND_VERSION:-latest}
    working_dir: /app
    command: "install_app"
    environment:
      POSTGRES_HOST: haf
    networks:
      haf-network:
    depends_on:
      haf:
        condition: service_healthy
  backend-block-processing:
    image: ${BACKEND_REGISTRY:-registry.gitlab.syncad.com/hive/reputation_tracker}:${BACKEND_VERSION:-latest}
    working_dir: /app
    command: "process_blocks"
    environment:
      POSTGRES_HOST: haf
      POSTGRES_USER: reptracker_owner
    networks:
      haf-network:
    healthcheck:
      test: ["CMD-SHELL","/app/block-processing-healthcheck.sh"]
      interval: 60s
      timeout: 5s
      retries: 20
      start_period: 72h #time for sync to finish
    depends_on:
      backend-setup:
        condition: service_completed_successfully
  backend-postgrest:
    image: ${POSTGREST_REGISTRY:-postgrest/postgrest}:${POSTGREST_VERSION:-latest}
    ports:
      - "3000:3000"
      - "3001:3001"
    environment:
      PGRST_ADMIN_SERVER_PORT: 3001
      PGRST_DB_URI: postgresql://reptracker_owner@haf:5432/haf_block_log
      PGRST_DB_SCHEMA: reptracker_endpoints
      PGRST_DB_ANON_ROLE: reptracker_user
      PGRST_DB_POOL: 20
      PGRST_DB_POOL_ACQUISITION_TIMEOUT: 10
      PGRST_OPENAPI_SERVER_PROXY_URI: http://localhost:3000
      PGRST_DB_EXTRA_SEARCH_PATH: reptracker_app
    networks:
      haf-network:
    depends_on:
      haf:
        condition: service_healthy
      backend-block-processing:
        condition: service_healthy

networks:
  haf-network:
    name: haf-network

volumes:
  haf_datadir:
    driver: local
  haf_shmdir:
    driver: local
  pgadmin_data:
    driver: local