# Note: this is an overrides file for ./docker/docker-compose.community.yml:
# It's used for setting special environment and configurations for running integration tests.
# This file also includes services that only exists in Hive's Cloud version, and are not available in the self-hosted version.
# Please refer to TESTING.md for more information.

version: '3.8'
name: 'hive-tests'

networks:
  stack:
    name: hive

services:
  local_cdn:
    image: node:24.13.0-alpine3.23
    working_dir: /app
    command: ['node', 'index.js']
    networks:
      - 'stack'
    healthcheck:
      test: ['CMD', 'wget', '--spider', '-q', 'localhost:3004/_readiness']
      interval: 5s
      timeout: 5s
      retries: 6
      start_period: 5s
    ports:
      - 3004:3004
    volumes:
      - '${PWD}/packages/services/cdn-worker/dist/index.nodejs.js:/app/index.js'
    environment:
      NODE_ENV: production
      PORT: 3004
      LOG_LEVEL: debug
      CDN_AUTH_PRIVATE_KEY: 1e1064ef9cda8bf38936b77317e90dc3
      S3_ENDPOINT: 'http://s3:9000'
      S3_ACCESS_KEY_ID: minioadmin
      S3_SECRET_ACCESS_KEY: minioadmin
      S3_BUCKET_NAME: artifacts

  local_broker:
    image: node:24.13.0-alpine3.23
    working_dir: /app
    command: ['node', 'broker.js']
    networks:
      - 'stack'
    healthcheck:
      test: ['CMD', 'wget', '--spider', '-q', 'localhost:3013/_readiness']
      interval: 5s
      timeout: 5s
      retries: 6
      start_period: 5s
    ports:
      - 3013:3013
    volumes:
      - '${PWD}/packages/services/broker-worker/dist/index.nodejs.js:/app/broker.js'
    environment:
      NODE_ENV: production
      PORT: 3013
      LOG_LEVEL: debug
      CF_BROKER_SIGNATURE: secretSignature

  mock_server:
    image: mockserver/mockserver:5.15.0
    # healthcheck - no time to implement it
    # The image does not contain curl or wget.
    networks:
      - 'stack'
    ports:
      - 3042:3042
    environment:
      MOCKSERVER_LOG_LEVEL: DEBUG
      MOCKSERVER_SERVER_PORT: 3042

  composition_federation_2:
    image: '${DOCKER_REGISTRY}composition-federation-2${DOCKER_TAG}'
    networks:
      - 'stack'
    healthcheck:
      test: ['CMD', 'wget', '--spider', '-q', 'localhost:3069/_readiness']
      interval: 5s
      timeout: 5s
      retries: 6
      start_period: 5s
    ports:
      - 3069:3069
    environment:
      NODE_ENV: production
      PORT: 3069
      LOG_LEVEL: debug
      SECRET: '${EXTERNAL_COMPOSITION_SECRET}'

  external_composition:
    image: node:24.13.0-alpine3.23
    working_dir: /app
    command: ['node', 'example.mjs']
    networks:
      - 'stack'
    healthcheck:
      test: ['CMD', 'wget', '--spider', '-q', 'localhost:3012/_readiness']
      interval: 5s
      timeout: 5s
      retries: 6
      start_period: 5s
    ports:
      - 3012:3012
    volumes:
      - '${PWD}/packages/libraries/external-composition/dist/example.js:/app/example.mjs'
    environment:
      NODE_ENV: production
      PORT: 3012
      LOG_LEVEL: debug
      SECRET: '${EXTERNAL_COMPOSITION_SECRET}'

  commerce:
    image: '${DOCKER_REGISTRY}commerce${DOCKER_TAG}'
    networks:
      - 'stack'
    ports:
      - 3009:3009
    depends_on:
      clickhouse:
        condition: service_healthy
      migrations:
        condition: service_completed_successfully
    environment:
      NODE_ENV: production
      LOG_LEVEL: debug
      LIMIT_CACHE_UPDATE_INTERVAL_MS: '${LIMIT_CACHE_UPDATE_INTERVAL_MS}'
      POSTGRES_HOST: db
      POSTGRES_PORT: 5432
      POSTGRES_DB: '${POSTGRES_DB}'
      POSTGRES_USER: '${POSTGRES_USER}'
      POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
      CLICKHOUSE_PROTOCOL: 'http'
      CLICKHOUSE_HOST: 'clickhouse'
      CLICKHOUSE_PORT: '8123'
      CLICKHOUSE_USERNAME: '${CLICKHOUSE_USER}'
      CLICKHOUSE_PASSWORD: '${CLICKHOUSE_PASSWORD}'
      STRIPE_SECRET_KEY: empty
      PORT: 3009

  # Overrides only to `docker-compose.community.yaml` from now on:
  server:
    environment:
      CDN_CF: '1'
      CDN_CF_BASE_PATH: http://local_cdn:3004
      CDN_CF_ACCOUNT_ID: 103df45224310d669213971ce28b5b70
      CDN_CF_AUTH_TOKEN: 85e20c26c03759603c0f45884824a1c3
      CDN_CF_NAMESPACE_ID: 33b1e3bbb4a4707d05ea0307cbb55c79
      CDN_CF_BASE_URL: http://localhost:3004
      CDN_AUTH_PRIVATE_KEY: 1e1064ef9cda8bf38936b77317e90dc3
      CDN_API: '1'
      CDN_API_BASE_URL: 'http://localhost:3001'
      REQUEST_BROKER: '1'
      REQUEST_BROKER_SIGNATURE: 'secretSignature'
      REQUEST_BROKER_ENDPOINT: 'http://local_broker:3013'
      GITHUB_APP_ID: 123123
      GITHUB_APP_PRIVATE_KEY: 5f938d51a065476c4dc1b04aeba13afb
      FEEDBACK_SLACK_TOKEN: ''
      FEEDBACK_SLACK_CHANNEL: '#hive'
      COMMERCE_ENDPOINT: '${COMMERCE_ENDPOINT}'
      COMMERCE_BILLING: '${COMMERCE_BILLING}'
      EMAIL_PROVIDER: '${EMAIL_PROVIDER}'
      LOG_LEVEL: debug
      # Auth
      WEB_APP_URL: '${HIVE_APP_BASE_URL}'
      AUTH_ORGANIZATION_OIDC: '1'
      AUTH_REQUIRE_EMAIL_VERIFICATION: '1'
      GRAPHQL_PUBLIC_ORIGIN: http://localhost:8082
      SUPERTOKENS_RATE_LIMIT: '0'
      SUPERTOKENS_REFRESH_TOKEN_KEY: '1000:15e5968d52a9a48921c1c63d88145441a8099b4a44248809a5e1e733411b3eeb80d87a6e10d3390468c222f6a91fef3427f8afc8b91ea1820ab10c7dfd54a268:39f72164821e08edd6ace99f3bd4e387f45fa4221fe3cd80ecfee614850bc5d647ac2fddc14462a00647fff78c22e8d01bc306a91294f5b889a90ba891bf0aa0'
      SUPERTOKENS_ACCESS_TOKEN_KEY: 's-aaa5da0d-8678-46ef-b56d-9cd19e1cdb5b|MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjdpx/LNIAPKDCNgszZIzz2tepThK9/3mCWTrOjAJY8KI8YgMo5Gf+IwYvJ2VcpKYa36UJ70bD283P2O/yE/IjtXI6S9cJyd5LrYs+QDENc8au63iDy2iAiFpR1kO7cWQPDK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X5UBfHlhvwzi4U9eenu7UHH8XrxEHlAwUC9mQbaqzoR/A7jEg8qqincMDUCkk1kjP4nNgQSBFcCgYEAnU/KSQf79m57nXMv+ge9QWkAggnHO7baRox5qlMM6l1gTZB5yELaLNXeik9D2mhVwcpezcQo2Uf+B4MviVeqpoTzYwgdxYg+ebYPUzhd3Ya8ANRDwKCB7SSoRULEDpWebV6ngOc+ruv9ii3ZbVEi7ribtHo6w7rVVJc2bMEKns8CgYB9ssp/yoxLxE2dz7hWCEMDDUUx/1AENQEYNATzS5j9hGsTntodULvnaUBl+eZlEcQ+h5DMlEBzt1l79DHClvGaFx2IFiM7LKoJWiaajhtzo0TWBhlxlyZY3ubm4RD+7WeLU5tqBkdv0VEVtW2D2epbeivBvDvIOog0Ffh3+0NsRQKBgGPA8w84hugPy0dega/VNIfD49SSCsqs+uD9tzDwlSIQsD6/PNpmuh7wR7wA45Ad1TOb9l4Y46ZU5psw7vXyp34MlKHZxbc63BMmBbXJ6ovNIm6MK6J8pacRNbslyVlOOzYzbZhqCu+1KgNza4rMhpBGdEYPtC/ly91mPdbc2rU1AoGBALl6eZqBMahE0S19X5SO/xykGe4ALf74UWCsfKrVEO4Zd3IcELnir0uEPABWvd5C/EAaGoi/a2xgdwuKG32GMpinjoXJywzsquQC6N8CcFIzDiQXaL4j4lFztjgowqNs/YwpOGbm1Dyr3Av072jDPajQGP/xX4fFxBZFnyk1vnXT'
    extra_hosts:
      - 'host.docker.internal:host-gateway'

  broker:
    image: redpandadata/redpanda:latest
    hostname: broker
    networks:
      - 'stack'
    command:
      - redpanda
      - start
      - --smp
      - '1'
      - --set redpanda.empty_seed_starts_cluster=false
      - --seeds "redpanda-1:33145"
      - --kafka-addr
      - PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092
      - --advertise-kafka-addr
      - PLAINTEXT://broker:29092,OUTSIDE://localhost:9092
      - --pandaproxy-addr
      - PLAINTEXT://0.0.0.0:28082,OUTSIDE://0.0.0.0:8082
      - --advertise-pandaproxy-addr
      - PLAINTEXT://broker:28082,OUTSIDE://localhost:8082
      - --advertise-rpc-addr redpanda-1:33145
    mem_limit: 300m
    mem_reservation: 100m
    healthcheck:
      test: 'curl -f http://localhost:9644/public_metrics'
      interval: 3s
      timeout: 3s
      retries: 6
      start_period: 5s

  db:
    ports:
      - '5432:5432'
  clickhouse:
    ports:
      - '8123:8123'
    volumes:
      - ./.hive/clickhouse/logs:/var/log/clickhouse-server
      - ./.hive/clickhouse/db:/var/lib/clickhouse
      - ./configs/clickhouse:/etc/clickhouse-server/conf.d

  usage:
    environment:
      COMMERCE_ENDPOINT: '${COMMERCE_ENDPOINT}'
      RATE_LIMIT_TTL: 1000
      LOG_LEVEL: debug
    depends_on:
      broker:
        condition: service_started # Redpand is ready when it starts
      tokens:
        condition: service_healthy

  usage-ingestor:
    environment:
      CLICKHOUSE_ASYNC_INSERT_BUSY_TIMEOUT_MS: '${CLICKHOUSE_ASYNC_INSERT_BUSY_TIMEOUT_MS}'
      CLICKHOUSE_ASYNC_INSERT_MAX_DATA_SIZE: '${CLICKHOUSE_ASYNC_INSERT_MAX_DATA_SIZE}'
      LOG_LEVEL: debug
    depends_on:
      broker:
        condition: service_started # Redpand is ready when it starts
      tokens:
        condition: service_healthy

  workflows:
    environment:
      EMAIL_PROVIDER: '${EMAIL_PROVIDER}'
      SCHEMA_ENDPOINT: http://schema:3002
      LOG_LEVEL: debug
    ports:
      - '3014:3014'

  schema:
    environment:
      LOG_LEVEL: debug
      REQUEST_BROKER: '1'
      REQUEST_BROKER_SIGNATURE: 'secretSignature'
      REQUEST_BROKER_ENDPOINT: 'http://local_broker:3013'
    ports:
      - '3002:3002'

  otel-collector:
    depends_on:
      clickhouse:
        condition: service_healthy
      server:
        condition: service_healthy
    build:
      context: ${PWD}/docker/configs/otel-collector
      dockerfile: ${PWD}/docker/otel-collector.dockerfile
    environment:
      HIVE_OTEL_AUTH_ENDPOINT: 'http://server:3001/otel-auth'
      CLICKHOUSE_PROTOCOL: 'http'
      CLICKHOUSE_HOST: clickhouse
      CLICKHOUSE_PORT: 8123
      CLICKHOUSE_USERNAME: '${CLICKHOUSE_USER}'
      CLICKHOUSE_PASSWORD: '${CLICKHOUSE_PASSWORD}'
    volumes:
      - '${PWD}/docker/configs/otel-collector/builder-config.yaml:/builder-config.yaml'
      - '${PWD}/docker/configs/otel-collector/config.yaml:/etc/otel-config.yaml'
    ports:
      - '4317:4317'
      - '4318:4318'
    networks:
      - 'stack'
    healthcheck:
      test: ['CMD', 'wget', '--spider', '-q', 'localhost:13133']
      interval: 5s
      timeout: 5s
      retries: 6
      start_period: 10s

  #
  # Awkwardly, we need to override some services for different reasons
  #

  # It's not part of integration tests
  app:
    image: node:24.13.0-alpine3.23
    command: ['npx', 'http-server']

  # Redpand is used for integration tests, instead of Kafka. Zookeeper is no longer needed
  zookeeper:
    image: node:24.13.0-alpine3.23
    command: ['npx', 'http-server']
