# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
version: '2.1'

services:
  # Java agent
  gateway:
    image: ${HUB}/gateway-service:${TAG}
    networks: [ sw ]
    privileged: true
    environment:
      SW_AGENT_NAME: gateway
      SW_AGENT_COLLECTOR_BACKEND_SERVICES: ${BACKEND_SERVICE}:11800
    healthcheck:
      test: [ "CMD-SHELL", "curl http://localhost/actuator/health" ]
      interval: 30s
      timeout: 10s
      retries: 3
    depends_on:
      oap:
        condition: service_healthy
      songs:
        condition: service_healthy

  # Java agent
  songs:
    image: ${HUB}/songs-service:${TAG}
    privileged: true
    networks: [ sw ]
    environment:
      SW_AGENT_NAME: songs
      SW_AGENT_COLLECTOR_BACKEND_SERVICES: ${BACKEND_SERVICE}:11800
      ACTIVE_MQ_URL: tcp://activemq:61616
      ACTIVE_MQ_QUEUE: queue-songs-ping      
    healthcheck:
      test: [ "CMD-SHELL", "curl http://localhost/actuator/health" ]
      interval: 30s
      timeout: 10s
      retries: 3
    depends_on:
      oap:
        condition: service_healthy      
      activemq:
        condition: service_healthy

  # Python agent
  rcmd:
    image: ${HUB}/recommendation-service:${TAG}
    networks: [ sw ]
    environment:
      SW_AGENT_NAME: recommendation
      SW_AGENT_COLLECTOR_BACKEND_SERVICES: ${BACKEND_SERVICE}:11800
    healthcheck:
      test: [ "CMD-SHELL", "curl http://localhost/health" ]
      interval: 30s
      timeout: 10s
      retries: 3
    depends_on:
      oap:
        condition: service_healthy

  # NodeJS backend agent
  app:
    image: ${HUB}/app:${TAG}
    networks: [ sw ]
    ports:
      - "9090:80"
    environment:
      SW_AGENT_NAME_SERVER: app
      REACT_APP_SW_AGENT_NAME_UI: ui
      SW_AGENT_COLLECTOR_BACKEND_SERVICES: ${BACKEND_SERVICE}:11800
    healthcheck:
      test: [ "CMD-SHELL", "curl http://localhost/health" ]
      interval: 30s
      timeout: 10s
      retries: 3
    depends_on:
      oap:
        condition: service_healthy

  loadgen:
    image: ${HUB}/load-gen:${TAG}
    networks: [ sw ]
    depends_on:
      app:
        condition: service_healthy

  frontend:
    image: ${HUB}/frontend:${TAG}
    environment:
      SW_AGENT_COLLECTOR_BACKEND_SERVICES: ${BACKEND_SERVICE}:11800
    networks: [ sw ]
    volumes:
      - ./config/apisix/apisix.yaml:/usr/local/apisix/conf/apisix.yaml
      - ./config/apisix/config.yaml:/usr/local/apisix/conf/config.yaml
      
  activemq:
    image: rmohr/activemq:5.15.9
    environment:
      ACTIVEMQ_SUNJMX_START: "-Dcom.sun.management.jmxremote.port=1616 -Dcom.sun.management.jmxremote.rmi.port=1616 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
      ACTIVEMQ_BROKER_NAME: activemq-broker
    expose:
      - 1616:1616
    volumes:
      - ./config/activemq/activemq.xml:/opt/activemq/conf/activemq.xml
    networks: [ sw ]
    healthcheck:
      test: [ "CMD-SHELL", "curl http://localhost:8161" ]
      interval: 30s
      timeout: 10s
      retries: 3    

  # Go agent
  rating:
    image: ${HUB}/rating-service:${TAG}
    networks: [ sw ]
    environment:
      SW_AGENT_NAME: rating
      SW_AGENT_REPORTER_GRPC_BACKEND_SERVICE: ${BACKEND_SERVICE}:11800
    healthcheck:
      test: [ "CMD-SHELL", "curl http://localhost/rating" ]
      interval: 30s
      timeout: 10s
      retries: 3
    depends_on:
      oap:
        condition: service_healthy

networks:
  sw:
