version: "3"

volumes:
  redpanda: null
  test-mongodb: null
  test-mongoconfdb: null

services:
  customer-service:
    container_name: customer-service
    build:
      context: ../../.
      dockerfile: Dockerfile
      target: test
    env_file:
      - .env.test
    environment:
      - HTTP_HOST=0.0.0.0
      - HTTP_PORT=8000

      - GRPC_HOST=0.0.0.0
      - GRPC_PORT=9000
      - GRPC_DOMEN=customer-service:9000

      - MONGO_HOST=customer-db
      - MONGO_PORT=27017
      - MONGO_USER=test
      - MONGO_PASSWORD=test
      - MONGO_DB_NAME=admin
      - MONGO_AUTH=admin

      - KAFKA_BROKERS=customer-redpanda:9092
      - KAFKA_TOPIC_TARIFF=tariffs

      - AUTH_MICROSERVICE_USER_URL=http://pena-auth-service:8000/user
      - HUBADMIN_MICROSERVICE_TARIFF_URL=http://hub-admin-backend-service:8000/tariff
      - CURRENCY_MICROSERVICE_TRANSLATE_URL=http://cbrfworker-service:8000/change
      - DISCOUNT_MICROSERVICE_GRPC_HOST=discount-service:9000
      - PAYMENT_MICROSERVICE_GRPC_HOST=treasurer-service:9085
    ports:
      - 8082:8000
      - 9092:9000
    depends_on:
      - customer-db
      - customer-migration
      - redpanda
      - test-pena-auth-service
    networks:
      - test

  customer-migration:
    container_name: customer-migration
    build:
      context: ../../.
      dockerfile: Dockerfile
      target: test
    command:
      [
        "sh",
        "-c",
        'migrate -source file://migrations -database "mongodb://test:test@customer-db:27017/admin?authSource=admin" up',
      ]
    depends_on:
      - customer-db
    networks:
      - test

  customer-db:
    container_name: customer-db
    image: "mongo:6.0.3"
    environment:
      MONGO_INITDB_ROOT_USERNAME: test
      MONGO_INITDB_ROOT_PASSWORD: test
    ports:
      - "27024:27017"
    networks:
      - test

  redpanda:
    container_name: customer-redpanda
    tty: true
    image: docker.redpanda.com/redpandadata/redpanda:v23.1.13
    command:
      - redpanda start
      - --smp 1
      - --overprovisioned
      - --kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092
      # Address the broker advertises to clients that connect to the Kafka API.
      # Use the internal addresses to connect to the Redpanda brokers
      # from inside the same Docker network.
      # Use the external addresses to connect to the Redpanda brokers
      # from outside the Docker network.
      - --advertise-kafka-addr internal://redpanda:9092,external://localhost:19092
      - --pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082
      # Address the broker advertises to clients that connect to the HTTP Proxy.
      - --advertise-pandaproxy-addr internal://redpanda:8082,external://localhost:18082
      - --schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081
      # Redpanda brokers use the RPC API to communicate with each other internally.
      - --rpc-addr redpanda:33145
      - --advertise-rpc-addr redpanda:33145
    ports:
      - 18081:18081
      - 18082:18082
      - 19092:19092
      - 19644:9644
    volumes:
      - redpanda:/var/lib/redpanda/data
    networks:
      - test
    healthcheck:
      test: ["CMD-SHELL", "rpk cluster health | grep -E 'Healthy:.+true' || exit 1"]
      interval: 15s
      timeout: 3s
      retries: 5
      start_period: 5s

  console:
    tty: true
    image: docker.redpanda.com/redpandadata/console:v2.2.4
    entrypoint: /bin/sh
    command: -c "echo \"$$CONSOLE_CONFIG_FILE\" > /tmp/config.yml; /app/console"
    environment:
      CONFIG_FILEPATH: /tmp/config.yml
      CONSOLE_CONFIG_FILE: |
        kafka:
          brokers: ["redpanda:9092"]
          schemaRegistry:
            enabled: true
            urls: ["http://redpanda:8081"]
        redpanda:
          adminApi:
            enabled: true
            urls: ["http://redpanda:9644"]
        connect:
          enabled: true
          clusters:
            - name: local-connect-cluster
              url: http://connect:8083
    ports:
      - 8080:8080
    networks:
      - test
    depends_on:
      - redpanda

  connect:
    tty: true
    image: docker.redpanda.com/redpandadata/connectors:latest
    hostname: connect
    container_name: connect
    networks:
      - test
    # platform: 'linux/amd64'
    depends_on:
      - redpanda
    ports:
      - "8083:8083"
    environment:
      CONNECT_CONFIGURATION: |
        key.converter=org.apache.kafka.connect.converters.ByteArrayConverter
        value.converter=org.apache.kafka.connect.converters.ByteArrayConverter
        group.id=connectors-cluster
        offset.storage.topic=_internal_connectors_offsets
        config.storage.topic=_internal_connectors_configs
        status.storage.topic=_internal_connectors_status
        config.storage.replication.factor=-1
        offset.storage.replication.factor=-1
        status.storage.replication.factor=-1
        offset.flush.interval.ms=1000
        producer.linger.ms=50
        producer.batch.size=131072
      CONNECT_BOOTSTRAP_SERVERS: redpanda:9092
      CONNECT_GC_LOG_ENABLED: "false"
      CONNECT_HEAP_OPTS: -Xms512M -Xmx512M
      CONNECT_LOG_LEVEL: info

  test-pena-auth-db:
    container_name: test-pena-auth-db
    init: true
    image: "mongo:6.0.3"
    command: mongod --quiet --logpath /dev/null
    volumes:
      - test-mongodb:/data/db
      - test-mongoconfdb:/data/configdb
    environment:
      MONGO_INITDB_ROOT_USERNAME: test
      MONGO_INITDB_ROOT_PASSWORD: test
    networks:
      - test

  test-pena-auth-service:
    image: penahub.gitlab.yandexcloud.net:5050/pena-services/pena-auth-service:staging.872
    container_name: test-pena-auth-service
    init: true
    env_file: auth.env.test
    healthcheck:
      test: wget -T1 --spider http://localhost:8000/user
      interval: 2s
      timeout: 2s
      retries: 5
    environment:
      - DB_HOST=test-pena-auth-db
      - DB_PORT=27017
      - ENVIRONMENT=staging
      - HTTP_HOST=0.0.0.0
      - HTTP_PORT=8000
      - DB_USERNAME=test
      - DB_PASSWORD=test
      - DB_NAME=admin
      - DB_AUTH=admin
    depends_on:
      - test-pena-auth-db
    networks:
      - test

networks:
  test: