services:
  sqlserver:
    container_name: "sqlserver"
    image: mcr.microsoft.com/mssql/server:${SQL_SERVER_VERSION}
    ports:
      - "1433:1433"
    environment:
      ACCEPT_EULA: Y
      MSSQL_PID: Standard
      MSSQL_SA_PASSWORD: $MSSQL_PASSWORD
      MSSQL_AGENT_ENABLED: true
    healthcheck:
      test: [ CMD-SHELL, /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P $MSSQL_PASSWORD -q "SELECT 1" || exit 1 ]
      retries: 3
      start_period: 3s
      timeout: 3s
    networks:
      test-network:
  init-db:
    container_name: "init-db"
    image: mcr.microsoft.com/mssql/server:${SQL_SERVER_VERSION}
    environment:
      MSSQL_SA_PASSWORD: $MSSQL_PASSWORD
    volumes:
      - ./scripts:/scripts.d
    depends_on:
      sqlserver:
        condition: service_healthy
    command: >
      bash -c '/opt/mssql-tools18/bin/sqlcmd -C -S sqlserver -U sa -P $MSSQL_PASSWORD -d master -i /scripts.d/init-db.sql; echo "All done!";'
    networks:
      test-network:
        aliases:
          - "initdb"
  azurite:
    container_name: "azurite"
    depends_on:
      init-db:
        condition: service_completed_successfully
    image: mcr.microsoft.com/azure-storage/azurite:latest
    ports:
      - "10000:10000"
      - "10001:10001"
      - "10002:10002"
    networks:
      test-network:
        aliases:
          - "azurite"
  emulator:
    container_name: "eventhubs-emulator"
    image: mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest
    volumes:
      - "./config.json:/Eventhubs_Emulator/ConfigFiles/Config.json"
    ports:
      - "5672:5672"
    environment:
      BLOB_SERVER: azurite
      METADATA_SERVER: azurite
      ACCEPT_EULA: Y
    depends_on:
      - azurite
    networks:
      test-network:
        aliases:
          - "eventhubs-emulator"
  debezium-server-sqlserver:
    container_name: "debezium-sqlserver"
    image: quay.io/debezium/server:${DEBEZIUM_VERSION}
    ports:
      - "8080:8080"
    depends_on:
      init-db:
        condition: service_completed_successfully
    environment:
      DEBEZIUM_SOURCE_CONNECTOR_CLASS: "io.debezium.connector.sqlserver.SqlServerConnector"
      DEBEZIUM_SOURCE_SNAPSHOT_ISOLATION_MODE: read_uncommitted
      DEBEZIUM_SOURCE_TOPIC_PREFIX: ${EVENT_HUB_NAME}
      DEBEZIUM_SOURCE_OFFSET_STORAGE_FILE_FILENAME: "./data/offsets.dat"
      DEBEZIUM_SOURCE_SCHEMA_HISTORY_INTERNAL: "io.debezium.storage.file.history.FileSchemaHistory"
      DEBEZIUM_SOURCE_SCHEMA_HISTORY_INTERNAL_FILE_FILENAME: "./data/schema_history_internal.dat"
      DEBEZIUM_SOURCE_DATABASE_HOSTNAME: sqlserver
      DEBEZIUM_SOURCE_DATABASE_ENCRYPT: false
      DEBEZIUM_SOURCE_DATABASE_PORT: 1433
      DEBEZIUM_SOURCE_DATABASE_NAMES: testDB
      DEBEZIUM_SOURCE_DATABASE_USER: sa
      DEBEZIUM_SOURCE_DATABASE_PASSWORD: $MSSQL_PASSWORD
      DEBEZIUM_SINK_TYPE: eventhubs
      DEBEZIUM_SINK_EVENTHUBS_CONNECTIONSTRING: ${EVENT_HUB_CONNECTION_STRING}
      DEBEZIUM_SINK_EVENTHUBS_HUBNAME: ${EVENT_HUB_NAME}
      QUARKUS_LOG_LEVEL: DEBUG
      QUARKUS_LOG_CONSOLE_JSON: false
    volumes:
      - $PWD/data:/data \
    networks:
      test-network:
        aliases:
          - "debezium-server"
networks:
  test-network:
