# docker-compose for ONAP portal containers: database, microservice, portal apps.
# Relies on .env file, which CANNOT be specified via command-line option
# Works in multiple environments; does not pull from a Nexus registry.
# Exposes the portal apps docker (but not DB nor WMS dockers) on the host network.
# Images must be pulled from ONAP Nexus registry after logging in like this:
# docker login -u USER -p PASS nexus3.onap.org:10001
# Uses healthcheck feature added in docker-compose v2.1

version: '2.1'

services:

  cli:
    image: ${CLI_IMG_NAME}:${PORTAL_TAG}
    environment:
      CLI_MODE: 'daemon'
    ports:
      - 8080:80
      - 9090:8080
    logging:
      driver: json-file

  # Config files may use hostname "portal-db"
  portal-db:
    image: ${DB_IMG_NAME}:${PORTAL_TAG}
    environment:
      MYSQL_ROOT_PASSWORD: 'Aa123456'
    expose:
      - 3306
    volumes:
      # Just specify a path and let the Engine create a volume
      - /var/lib/mysql
      # Inject the onboarding script at start time
      - ./Apps_Users_OnBoarding_Script.sql:/docker-entrypoint-initdb.d/zzz_apps_users_onboarding.sql
    logging:
      driver: json-file
    healthcheck:
      test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
      timeout: 10s
      retries: 30
      
  # Config files may use hostname "portal-cassandra"
  portal-cassandra:
    image: ${CDR_IMG_NAME}:${PORTAL_TAG}
    environment:
      - CASSUSER=root
      - CASSPASS=Aa123456
    expose:
      - 7000
      - 7001
      - 7199
      - 9042
      - 9160
    ports:
      - 7000:7000
      - 7001:7001
      - 7199:7199
      - 9042:9042
      - 9160:9160
    volumes:
      - ./portal.cql:/docker-entrypoint-initdb.d/zzz_portal.cql
      - ./portalsdk.cql:/docker-entrypoint-initdb.d/zzz_portalsdk.cql
    links:
      - portal-db      
    depends_on:
      portal-db:
        condition: service_healthy
        
  # Config files may use hostname "portal-zk"
  portal-zk:
    image: ${ZK_IMG_NAME}:${PORTAL_TAG}
    expose:
      - 2181
    ports:
      - 2181:2181           

  # The app config file uses the docker name above
  portal-wms:
    image: ${WMS_IMG_NAME}:${PORTAL_TAG}
    expose:
      - 8082
    links:
      - portal-db
    depends_on:
      portal-db:
        condition: service_healthy
    volumes:
      - ${PROPS_DIR}/ONAPWIDGETMS/application.properties:/application.properties
      - ${PROPS_DIR}/ONAPWIDGETMS/application.yml:/application.yml
    command:
      - /start-wms.sh
    logging:
      driver: json-file

  portal-app:
    image: ${EP_IMG_NAME}:${PORTAL_TAG}
    ports:
      - 8989:8080
      - 8010:8009
      - 8006:8005
    links:
      - portal-db
      - portal-wms
      - portal-zk
      - portal-cassandra
    depends_on:
      portal-db:
        condition: service_healthy
      portal-wms:
        condition: service_started
    volumes:
      - ${PROPS_DIR}/ONAPPORTAL/system.properties:${WEBAPPS_DIR}/ONAPPORTAL/WEB-INF/conf/system.properties
      - ${PROPS_DIR}/ONAPPORTAL/fusion.properties:${WEBAPPS_DIR}/ONAPPORTAL/WEB-INF/fusion/conf/fusion.properties
      - ${PROPS_DIR}/ONAPPORTAL/portal.properties:${WEBAPPS_DIR}/ONAPPORTAL/WEB-INF/classes/portal.properties
      - ${PROPS_DIR}/ONAPPORTAL/music.properties:${WEBAPPS_DIR}/ONAPPORTAL/WEB-INF/classes/music.properties
      - ${PROPS_DIR}/ONAPPORTAL/openid-connect.properties:${WEBAPPS_DIR}/ONAPPORTAL/WEB-INF/classes/openid-connect.properties
      - ${PROPS_DIR}/ONAPPORTAL/logback.xml:${WEBAPPS_DIR}/ONAPPORTAL/WEB-INF/classes/logback.xml
      - ${LOGS_DIR}:/opt/apache-tomcat-8.0.37/logs
    command:
      - /start-apache-tomcat.sh
      # see comments in .env file
      - -i
      - $EXTRA_HOST_IP
      - -n
      - $EXTRA_HOST_NAME
    logging:
      driver: json-file

  portal-sdk:
    image: ${SDK_IMG_NAME}:${PORTAL_TAG}
    ports:
      - 8990:8080
    links:
      - portal-db
      - portal-wms
      - portal-zk
      - portal-cassandra
    depends_on:
      portal-db:
        condition: service_healthy
    volumes:
      - ${PROPS_DIR}/ONAPPORTALSDK/fusion.properties:${WEBAPPS_DIR}/ONAPPORTALSDK/WEB-INF/fusion/conf/fusion.properties
      - ${PROPS_DIR}/ONAPPORTALSDK/system.properties:${WEBAPPS_DIR}/ONAPPORTALSDK/WEB-INF/conf/system.properties
      - ${PROPS_DIR}/ONAPPORTALSDK/portal.properties:${WEBAPPS_DIR}/ONAPPORTALSDK/WEB-INF/classes/portal.properties
      - ${PROPS_DIR}/ONAPPORTALSDK/music.properties:${WEBAPPS_DIR}/ONAPPORTALSDK/WEB-INF/classes/music.properties
      - ${PROPS_DIR}/ONAPPORTALSDK/logback.xml:${WEBAPPS_DIR}/ONAPPORTALSDK/WEB-INF/classes/logback.xml
      - ${LOGS_DIR}:/opt/apache-tomcat-8.0.37/logs
    command:
      - /start-apache-tomcat.sh
    logging:
      driver: json-file