# documentation: https://docs.hatchet.run/self-hosting/docker-compose
# slogan: Hatchet allows you to run background tasks at scale with a high-throughput, low-latency computing service built on an open-source, fault-tolerant queue.
# category: automation
# tags: ai-agents,background-tasks,data-pipelines,scheduling
# logo: svgs/hatchet.svg
# port: 80

services:
  hatchet-dashboard:
    image: ghcr.io/hatchet-dev/hatchet/hatchet-dashboard:latest
    command: sh ./entrypoint.sh --config /hatchet/config
    environment:
      - DATABASE_URL=postgres://$SERVICE_USER_POSTGRES:$SERVICE_PASSWORD_POSTGRES@postgres:5432/$POSTGRES_DB
      - SERVICE_URL_HATCHET_80
      # Default credentials are "admin@example.com" and "Admin123!!"
    depends_on:
      postgres:
        condition: service_healthy
      rabbitmq:
        condition: service_healthy
      setup-config:
        condition: service_completed_successfully
      migration:
        condition: service_completed_successfully
    volumes:
      - hatchet-certs:/hatchet/certs
      - hatchet-config:/hatchet/config

  hatchet-engine:
    image: ghcr.io/hatchet-dev/hatchet/hatchet-engine:latest
    command: /hatchet/hatchet-engine --config /hatchet/config
    restart: on-failure
    depends_on:
      postgres:
        condition: service_healthy
      rabbitmq:
        condition: service_healthy
      setup-config:
        condition: service_completed_successfully
      migration:
        condition: service_completed_successfully
    environment:
      - DATABASE_URL=postgres://$SERVICE_USER_POSTGRES:$SERVICE_PASSWORD_POSTGRES@postgres:5432/$POSTGRES_DB
      - SERVER_GRPC_BIND_ADDRESS=${SERVER_GRPC_BIND_ADDRESS:-0.0.0.0}
      - SERVER_GRPC_INSECURE=${SERVER_GRPC_INSECURE:-t}
    volumes:
      - hatchet-certs:/hatchet/certs
      - hatchet-config:/hatchet/config

  postgres:
    image: postgres:16-alpine
    volumes:
      - postgresql-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=$SERVICE_USER_POSTGRES
      - POSTGRES_PASSWORD=$SERVICE_PASSWORD_POSTGRES
      - POSTGRES_DB=${POSTGRES_DB:-hatchet}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 5s
      timeout: 20s
      retries: 10

  rabbitmq:
    image: rabbitmq:3-management
    hostname: "rabbitmq"
    environment:
      - SERVICE_URL_RABBITMQ_15672
      - RABBITMQ_DEFAULT_USER=$SERVICE_USER_RABBITMQ
      - RABBITMQ_DEFAULT_PASS=$SERVICE_PASSWORD_RABBITMQ
      - PORT=${RABBITMQ_PORT:-5672}
    healthcheck:
      test: rabbitmq-diagnostics -q ping
      interval: 5s
      timeout: 30s
      retries: 10
    volumes:
      - rabbitmq-data:/var/lib/rabbitmq/

  migration:
    image: ghcr.io/hatchet-dev/hatchet/hatchet-migrate:latest
    command: /hatchet/hatchet-migrate
    restart: no
    exclude_from_hc: true
    environment:
      - DATABASE_URL=postgres://$SERVICE_USER_POSTGRES:$SERVICE_PASSWORD_POSTGRES@postgres:5432/$POSTGRES_DB
    depends_on:
      postgres:
        condition: service_healthy

  setup-config:
    image: ghcr.io/hatchet-dev/hatchet/hatchet-admin:latest
    command: /hatchet/hatchet-admin quickstart --skip certs --generated-config-dir /hatchet/config --overwrite=false
    restart: no
    environment:
      - DATABASE_URL=postgres://$SERVICE_USER_POSTGRES:$SERVICE_PASSWORD_POSTGRES@postgres:5432/$POSTGRES_DB
      - SERVER_TASKQUEUE_RABBITMQ_URL=amqp://$SERVICE_USER_RABBITMQ:$SERVICE_PASSWORD_RABBITMQ@rabbitmq:5672/
      - SERVER_AUTH_COOKIE_DOMAIN=${SERVER_AUTH_COOKIE_DOMAIN:-localhost:8080}
      - SERVER_AUTH_COOKIE_INSECURE=${SERVER_AUTH_COOKIE_INSECURE:-t}
      - SERVER_GRPC_BIND_ADDRESS=${SERVER_GRPC_BIND_ADDRESS:-0.0.0.0}
      - SERVER_GRPC_INSECURE=${SERVER_GRPC_INSECURE:-t}
      - SERVER_GRPC_BROADCAST_ADDRESS=${SERVER_GRPC_BROADCAST_ADDRESS:-localhost:7077}
      - SERVER_DEFAULT_ENGINE_VERSION=V1
      - SERVER_INTERNAL_CLIENT_INTERNAL_GRPC_BROADCAST_ADDRESS=${SERVER_INTERNAL_CLIENT_INTERNAL_GRPC_BROADCAST_ADDRESS:-hatchet-engine:7077}
    volumes:
      - hatchet_certs:/hatchet/certs
      - hatchet_config:/hatchet/config
    depends_on:
      migration:
        condition: service_completed_successfully
      rabbitmq:
        condition: service_healthy
      postgres:
        condition: service_healthy
