version: '3'

#
# This docker compose file is for running LOCAL deployments of YOUnite (generally for development or demos)
#
# REQUIRED ENVIRONMENT VARIABLES
# - HOST_IP: The host system IP address
# - YOUNITE_HOSTNAME: The "hosts" (e.g. /etc/hosts or DNS entry) for the host system (this var is only
#   required in non development environments).
#
#  See the readme and compose.sh for usage
#

services:
  younite-api:
    image: 160909222919.dkr.ecr.us-west-2.amazonaws.com/younite/younite-api:latest
    container_name: younite-api
    restart: always
    environment:
      - SPRING_PROFILES_ACTIVE=dev
      - SPRING_DATASOURCE_URL=jdbc:postgresql://younite-db:5432/younite
      - SPRING_DATASOURCE_USERNAME=younite
      - SPRING_DATASOURCE_PASSWORD=younite
      - COOKIE_DOMAIN=.${YOUNITE_HOSTNAME}
      - NOTIFICATIONS_ENABLED=true
      - DATA_VIRTUALIZATION_ENABLED=true
      # Token expiration time in minutes (1440 minutes = 24 hours)
      - SECURITY_ACCESS_TOKEN_VALIDITY_MINUTES=1440
      # URL to the public endpoint for the YOUnite Server API. Required for a redirect after authentication is completed.
      - YOUNITE_API_URL=http://${YOUNITE_HOSTNAME}:8080/api
      # API_JAVA_OPTS is used below for performance tuning, specifically for BitBucket pipelines postman tests.
      # DEBUG level is also turned on for BitBucket pipelines debugging so a more verbose log will be dumped on error
      - JAVA_OPTS= -Dlogging.level.com.younite=DEBUG
      # For INFO level debugging use this line instead of the one above
      #- JAVA_OPTS= -Dlogging.level.com.younite=INFO
      #
      # SSO Config
      #
      - OIDC_DISCOVERY_DOCUMENT_URL=http://${YOUNITE_HOSTNAME}:8800/auth/realms/younite/.well-known/openid-configuration
      - OIDC_SUCCESSFUL_LOGIN_URL=http://${YOUNITE_HOSTNAME}/dashboard
      - OIDC_CLIENT_SECRET=d174ca69-ff0e-41c6-8b5d-c76376363fe8
      #
      # Message Bus Config
      #
      - MESSAGE_BUS_URL=tcp://younite-mb:61616
      - MESSAGE_BUS_USERNAME=artemis
      - MESSAGE_BUS_PASSWORD=artemis
      - ACTIVE_MQ_API_URI=http://younite-mb:8161/console/jolokia/
      #
      # Logging Config
      #
      - LOGGING_LOGSTASH_HOST=younite-logstash
      - LOGGING_LOGSTASH_PORT=4560
      # for certain testing we need to turn elastic/logstash "off"
      - LOGGING_ELASTIC_ENABLED=true
      - LOGGING_LOGSTASH_ENABLED=false
    ports:
      - 8080:8080/tcp
    extra_hosts:
      - "${YOUNITE_HOSTNAME}:${HOST_IP}"
    networks:
      - younite

  younite-notification-service:
    image: 160909222919.dkr.ecr.us-west-2.amazonaws.com/younite/younite-notification-service:latest
    container_name: younite-notification-service
    restart: always
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://younite-notification-service-db:5432/notifications
      - SPRING_DATASOURCE_USERNAME=younite
      - SPRING_DATASOURCE_PASSWORD=younite
      - MESSAGE_BUS_URL=tcp://younite-mb:61616
      - MESSAGE_BUS_USERNAME=artemis
      - MESSAGE_BUS_PASSWORD=artemis
      - API_HOST=http://younite-api:8080
      - NOTIFICATION_SERVICE_CLIENT_ID=notifications
      - NOTIFICATION_SERVICE_CLIENT_SECRET=76cf79c5-1a8a-43e6-bee1-af77a2d2d400
      - OIDC_ISSUER=http://${YOUNITE_HOSTNAME}:8800/auth/realms/younite
      - WEBSOCKET_ALLOWED_ORIGINS=http://${YOUNITE_HOSTNAME},https://${YOUNITE_HOSTNAME},http://${YOUNITE_HOSTNAME}:8082
      - JAVA_OPTS=-Dlogging.level.com.younite=DEBUG
      - MESSAGE_BROKER_RELAY_HOST=younite-mb
      - MESSAGE_BROKER_RELAY_STOMP_PORT=61613
      - MESSAGE_BROKER_RELAY_TCP_PORT=61616
      - MESSAGE_BROKER_RELAY_CLIENT_USER=artemis
      - MESSAGE_BROKER_RELAY_CLIENT_PASSWORD=artemis
      - MESSAGE_BROKER_RELAY_SYSTEM_USER=artemis
      - MESSAGE_BROKER_RELAY_SYSTEM_PASSWORD=artemis
    ports:
      - 8082:8080/tcp
    extra_hosts:
      - "${YOUNITE_HOSTNAME}:${HOST_IP}"
    networks:
      - younite

  younite-notification-service-db:
    image: postgres:12
    container_name: younite-notification-service-db
    restart: always
    environment:
      - POSTGRES_DB=notifications
      - POSTGRES_USER=younite
      - POSTGRES_PASSWORD=younite
    ports:
      - 5433:5432/tcp
    networks:
      - younite

  younite-data-virtualization-service:
    image: 160909222919.dkr.ecr.us-west-2.amazonaws.com/younite/younite-data-virtualization-service:latest
    container_name: younite-data-virtualization-service
    restart: always
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://younite-db:5432/younite
      - SPRING_DATASOURCE_USERNAME=younite
      - SPRING_DATASOURCE_PASSWORD=younite
      - MESSAGE_BUS_URL=tcp://younite-mb:61616
      - MESSAGE_BUS_USERNAME=artemis
      - MESSAGE_BUS_PASSWORD=artemis
      - OIDC_ISSUER=http://${YOUNITE_HOSTNAME}:8800/auth/realms/younite
      - LOGGING_LOGSTASH_ENABLED=false
      - LOGGING_LOGSTASH_HOST=younite-logstash
      - LOGGING_LOGSTASH_PORT=4560
      - JAVA_OPTS=-Dlogging.level.com.younite=DEBUG
    ports:
      - 8084:8080/tcp
    extra_hosts:
      - "${YOUNITE_HOSTNAME}:${HOST_IP}"
    networks:
      - younite

  younite-mb:
    image: 160909222919.dkr.ecr.us-west-2.amazonaws.com/younite/activemq-artemis:2.18.0
    container_name: younite-mb
    restart: always
    environment:
      - ARTEMIS_USER=artemis
      - ARTEMIS_PASSWORD=artemis
      - JAVA_EXTRA_ARGS=
    ports:
      - 61616:61616/tcp
      - 61613:61613/tcp
      - 8161:8161/tcp
    networks:
      - younite

  younite-db:
    image: postgres:12
    container_name: younite-db
    restart: always
    environment:
      - POSTGRES_PASSWORD=younite
      - POSTGRES_DB=younite
      - POSTGRES_USER=younite
    networks:
      - younite
    ports:
      - "5432:5432"

  younite-ui:
    image: 160909222919.dkr.ecr.us-west-2.amazonaws.com/younite/youniteui:latest
    container_name: younite-ui
    restart: always
    environment:
      # API_ENDPOINT: URI of the YOUnite API service
      - API_ENDPOINT=http://${YOUNITE_HOSTNAME}:8080/api
      # DVS_API_ENDPOINT: URI of the YOUnite Data virtualization service
      - DVS_API_ENDPOINT=http://${YOUNITE_HOSTNAME}:8084/api
      # SSO_TYPE: O = Open ID Connect, S = SAML (not yet supported)
      - SSO_TYPE=O
      # KIBANA_URL: URI of the Kibana server
      - KIBANA_URL=http://${YOUNITE_HOSTNAME}:5601
      # NOTIFICATIONS_CSRF_URL: URI to retrieve a cross-site request forgery (CSRF)
      # token from. Typically this is the /csrf endpoint of the YOUnite Notification
      # Service
      - NOTIFICATIONS_CSRF_URL=http://${YOUNITE_HOSTNAME}:8082/csrf
      # NOTIFICATIONS_STOMP_URL: URI to register for stomp notifications - this
      # typically is the /ws endpoint of the YOUnite Notification Service.
      - NOTIFICATIONS_STOMP_URL=http://${YOUNITE_HOSTNAME}:8082/ws

    ports:
      - "80:80"
    networks:
      - younite

  younite-keycloak:
    image: 160909222919.dkr.ecr.us-west-2.amazonaws.com/younite/keycloak:16.1.1
    container_name: younite-keycloak
    restart: always
    ports:
      - 8800:8080
    environment:
      - KEYCLOAK_USER=admin
      - KEYCLOAK_PASSWORD=admin
      - DB_VENDOR=h2
      - REDIRECT_URIS="http://${YOUNITE_HOSTNAME}/*","http://${YOUNITE_HOSTNAME}:8080/*","http://${YOUNITE_HOSTNAME}:5601/*"
      - YOUNITE_CLIENT_SECRET=d174ca69-ff0e-41c6-8b5d-c76376363fe8
      - NOTIFICATIONS_CLIENT_SECRET=76cf79c5-1a8a-43e6-bee1-af77a2d2d400
    networks:
      - younite

networks:
  younite:
    external:
      name: younite
