# This docker-compose file will spin up an ACS cluster on a local host or on a server and it requires a minimum of 12GB Memory to distribute among containers.
# Limit container memory and assign X percentage to JVM.  There are couple of ways to allocate JVM Memory for ACS Containers
# For example: 'JAVA_OPTS: "$JAVA_OPTS -XX:+PrintFlagsFinal -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"'
# See Oracle docs (https://docs.oracle.com/javase/9/gctuning/parallel-collector1.htm#JSGCT-GUID-CAB83393-3438-44ED-98F0-D15641B43C7D).
# If the container memory is not explicitly set then the flags above will set the max heap default to 1/4 of the container's memory, which may not be ideal.
# For performance tuning, assign the container memory and give a percentage of it to the JVM.

# Using version 2 as 3 does not support resource constraint options (cpu_*, mem_* limits) for non swarm mode in Compose
version: "2"

services:
    alfresco:
        image: XX_VOTRE_IMAGE:VERSION
        mem_limit: 1500m
        depends_on:
            - db
        environment:
            JAVA_OPTS: "
                -Ddb.driver=org.mariadb.jdbc.Driver
                -Ddb.username=XX_USER
                -Ddb.password=XX_PWD
                -Ddb.url='jdbc:mariadb://db:3306/alfresco?useUnicode=yes&characterEncoding=UTF-8'
                -Dsolr.host=solr6
                -Dsolr.port=8983
                -Dsolr.secureComms=none
                -Dsolr.base.url=/solr
                -Dindex.subsystem.name=solr6
                -Dshare.host=127.0.0.1
                -Dshare.port=8080
                -Dalfresco.host=localhost
                -Dalfresco.port=8080
                -Daos.baseUrlOverwrite=http://localhost:8080/alfresco/aos
                -Dmessaging.broker.url=\"failover:(nio://activemq:61616)?timeout=3000&jms.useCompression=true\"
                -Ddeployment.method=DOCKER_COMPOSE

                -Dlocal.transform.service.enabled=true
                -DlocalTransform.pdfrenderer.url=http://alfresco-pdf-renderer:8090/
                -DlocalTransform.imagemagick.url=http://imagemagick:8090/
                -DlocalTransform.libreoffice.url=http://libreoffice:8090/
                -DlocalTransform.tika.url=http://tika:8090/
                -DlocalTransform.misc.url=http://transform-misc:8090/

                -Dlegacy.transform.service.enabled=true
                -Dalfresco-pdf-renderer.url=http://alfresco-pdf-renderer:8090/
                -Djodconverter.url=http://libreoffice:8090/
                -Dimg.url=http://imagemagick:8090/
                -Dtika.url=http://tika:8090/
                -Dtransform.misc.url=http://transform-misc:8090/

                -Dcsrf.filter.enabled=false
                -Xms1500m -Xmx1500m"

        volumes:
            - ./alfresco/data/alf-repo-data:/usr/local/tomcat/alf_data
            - ./alfresco/logs:/usr/local/tomcat/logs
            - ./alfresco/config/alfresco-global.properties:/usr/local/tomcat/shared/classes/alfresco-global.properties

    alfresco-pdf-renderer:
        image: alfresco/alfresco-pdf-renderer:2.1.0
        mem_limit: 1g
        environment:
            JAVA_OPTS: " -Xms256m -Xmx512m"
        ports:
            - 8090:8090

    imagemagick:
        image: alfresco/alfresco-imagemagick:2.1.0
        mem_limit: 1g
        environment:
            JAVA_OPTS: " -Xms256m -Xmx512m"
        ports:
            - 8091:8090

    libreoffice:
        image: alfresco/alfresco-libreoffice:2.1.0
        mem_limit: 1g
        environment:
            JAVA_OPTS: " -Xms256m -Xmx512m"
        ports:
            - 8092:8090

    tika:
        image: alfresco/alfresco-tika:2.1.0
        mem_limit: 1g
        environment:
            JAVA_OPTS: " -Xms256m -Xmx512m"
        ports:
            - 8093:8090

    transform-misc:
        image: alfresco/alfresco-transform-misc:2.1.0
        mem_limit: 1g
        environment:
            JAVA_OPTS: " -Xms256m -Xmx512m"
        ports:
            - 8094:8090

    share:
        image: alfresco/alfresco-share:6.2.0
        mem_limit: 1g
        environment:
            REPO_HOST: "alfresco"
            REPO_PORT: "8080"
            JAVA_OPTS: "
                -Xms500m
                -Xmx500m
                -Dalfresco.host=localhost
                -Dalfresco.port=8080
                -Dalfresco.context=alfresco
                -Dalfresco.protocol=http
                "
        volumes:
            - ./alfresco/logs/share:/usr/local/tomcat/logs
            - ./alfresco/config/ext-share-config-custom.xml:/usr/local/tomcat/shared/classes/alfresco/web-extension/ext-share-config-custom.xml


    db:
      image: mariadb:latest
      container_name: mariadb
      volumes:
        - ./alfresco/data/mariadb_data:/var/lib/mysql
        - ./alfresco/logs/mariadb:/var/log/mysql
      environment:
        - MYSQL_ROOT_PASSWORD=XX_ROOT_PWD
        - MYSQL_DATABASE=alfresco
        - MYSQL_USER=XX_USER
        - MYSQL_PASSWORD=XX_PWD
      command: [mysqld, --character-set-server=utf8, --collation-server=utf8_bin, --wait_timeout=28800]


    solr6:
        image: alfresco/alfresco-search-services:1.4.0
        mem_limit: 2g
        environment:
            #Solr needs to know how to register itself with Alfresco
            - SOLR_ALFRESCO_HOST=alfresco
            - SOLR_ALFRESCO_PORT=8080
            #Alfresco needs to know how to call solr
            - SOLR_SOLR_HOST=solr6
            - SOLR_SOLR_PORT=8983
            #Create the default alfresco and archive cores
            - SOLR_CREATE_ALFRESCO_DEFAULTS=alfresco,archive
            #HTTP by default
            - ALFRESCO_SECURE_COMMS=none
            - "SOLR_JAVA_MEM=-Xms2g -Xmx2g"
        volumes:
            - ./alfresco/data/solr-data:/opt/alfresco-search-services/data
        ports:
            - 8083:8983 #Browser port

    activemq:
        image: alfresco/alfresco-activemq:5.15.8
        mem_limit: 1g
        ports:
            - 8161:8161 # Web Console
            - 5672:5672 # AMQP
            - 61616:61616 # OpenWire
            - 61613:61613 # STOMP

    proxy:
        image: alfresco/acs-community-ngnix:1.0.0
        mem_limit: 128m
        depends_on:
            - alfresco
        volumes:
            - ./alfresco/config:/etc/nginx/conf.d
            - ./alfresco/logs/nginx:/var/log/nginx
        ports:
            - 8080:8080
        links:
            - alfresco
            - share

    app:
      depends_on:
       - db
      image: phpmyadmin/phpmyadmin
      container_name: phpmyadmin
      restart: always
      ports:
       - '8095:80'
      environment:
        PMA_HOST: db
