version: "2.4"

services:
  alfresco:
    image: docker.io/alfresco/alfresco-content-repository-community:${ALFRESCO_COMMUNITY_TAG}
    mem_limit: 1700m
    environment:
      JAVA_TOOL_OPTIONS: "
        -Dencryption.keystore.type=JCEKS
        -Dencryption.cipherAlgorithm=DESede/CBC/PKCS5Padding
        -Dencryption.keyAlgorithm=DESede
        -Dencryption.keystore.location=/usr/local/tomcat/shared/classes/alfresco/extension/keystore/keystore
        -Dmetadata-keystore.password=mp6yc0UD9e
        -Dmetadata-keystore.aliases=metadata
        -Dmetadata-keystore.metadata.password=oKIWzVdEdA
        -Dmetadata-keystore.metadata.algorithm=DESede
        "
      JAVA_OPTS: '
        -Delasticsearch.createIndexIfNotExists=true
        -Ddb.driver=org.postgresql.Driver
        -Ddb.username=alfresco
        -Ddb.password=alfresco
        -Ddb.url=jdbc:postgresql://postgres:5432/alfresco
        -Dsolr.secureComms=secret
        -Dsolr.sharedSecret=secret
        -Dindex.subsystem.name=elasticsearch
        -Delasticsearch.host=elasticsearch
        -Delasticsearch.indexName=${ELASTICSEARCH_INDEX_NAME}
        -Dshare.host=127.0.0.1
        -Dshare.port=8081
        -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"
        -Dmessaging.broker.username=admin
        -Dmessaging.broker.password=admin
        -Ddeployment.method=DOCKER_COMPOSE
        -Dtransform.service.enabled=true
        -Dtransform.service.url=http://transform-router:8095
        -Dsfs.url=http://shared-file-store:8099/
        -DlocalTransform.core-aio.url=http://transform-core-aio:8090/
        -Dalfresco-pdf-renderer.url=http://transform-core-aio:8090/
        -Djodconverter.url=http://transform-core-aio:8090/
        -Dimg.url=http://transform-core-aio:8090/
        -Dtika.url=http://transform-core-aio:8090/
        -Dtransform.misc.url=http://transform-core-aio:8090/
        -Dcsrf.filter.enabled=false
        -Dalfresco.restApi.basicAuthScheme=true
        -Xms1500m -Xmx1500m
        '
    ports:
      - "8080:8080"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/probes/-ready-"]
      interval: 30s
      timeout: 10s
      retries: 10
      start_period: 2m

  transform-core-aio:
    image: alfresco/alfresco-transform-core-aio:${TRANSFORM_CORE_AIO_TAG}
    mem_limit: 1536m
    environment:
      JAVA_OPTS: " -Xms256m -Xmx1536m"
      ACTIVEMQ_URL: "nio://activemq:61616"
      SPRING_ACTIVEMQ_USER: admin
      SPRING_ACTIVEMQ_PASSWORD: admin #pragma: allowlist secret
      FILE_STORE_URL: "http://shared-file-store:8099/alfresco/api/-default-/private/sfs/versions/1/file"
    ports:
      - 8090:8090
    links:
      - activemq
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8090/ready"]
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 30s

  share:
    image: docker.io/alfresco/alfresco-share:${SHARE_TAG}
    mem_limit: 512m
    environment:
      REPO_HOST: "alfresco"
      REPO_PORT: "8080"
      JAVA_OPTS: "
        -Xms500m
        -Xmx500m
        -Dalfresco.host=localhost
        -Dalfresco.port=8080
        -Dalfresco.context=alfresco
        -Dalfresco.protocol=http
        "
    ports:
      - "8081:8080"

  postgres:
    image: postgres:${POSTGRES_TAG}
    mem_limit: 512m
    environment:
      - POSTGRES_PASSWORD=alfresco
      - POSTGRES_USER=alfresco
      - POSTGRES_DB=alfresco
    command: postgres -c max_connections=300 -c log_min_messages=LOG
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -d $$POSTGRES_DB -U $$POSTGRES_USER"]
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 5s
    ports:
      - 5432:5432

  activemq:
    image: docker.io/alfresco/alfresco-activemq:${ACTIVE_MQ_TAG}
    mem_limit: 1g
    ports:
      - 8161:8161 # Web Console
      - 5672:5672 # AMQP
      - 61616:61616 # OpenWire
      - 61613:61613 # STOMP

  elasticsearch:
    image: elasticsearch:${ELASTICSEARCH_TAG}
    mem_limit: 1700m
    environment:
      - xpack.security.enabled=false
      - discovery.type=single-node
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    cap_add:
      - IPC_LOCK
    ports:
      - 9200:9200
      - 9300:9300
    healthcheck:
      test: ["CMD-SHELL", "curl -fs http://localhost:9200/_cluster/health | grep -E '\"status\":\"(green|yellow)\"'"]
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 30s

  kibana:
    image: kibana:${KIBANA_TAG}
    mem_limit: 1g
    environment:
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
    ports:
      - 5601:5601
    depends_on:
      - elasticsearch

  batch-indexing:
    image: alfresco/alfresco-elasticsearch-batch-indexing:${BATCH_INDEXING_TAG}
    mem_limit: 1g
    depends_on:
      elasticsearch:
        condition: service_healthy
      alfresco:
        condition: service_healthy
      transform-core-aio:
        condition: service_healthy
    environment:
      JAVA_OPTS: " -Xms256m -Xmx768m"
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/alfresco
      SPRING_DATASOURCE_USERNAME: alfresco
      SPRING_DATASOURCE_PASSWORD: alfresco #pragma: allowlist secret
      SPRING_ELASTICSEARCH_REST_URIS: http://elasticsearch:9200
      ELASTICSEARCH_INDEXNAME: ${ELASTICSEARCH_INDEX_NAME}
      ALFRESCO_ACCEPTEDCONTENTMEDIATYPESCACHE_BASEURL: http://transform-core-aio:8090/transform/config
      ALFRESCO_ACS_URL: http://alfresco:8080
      ALFRESCO_CONTENT_TRANSFORM_SHAREDSECRET: secret #pragma: allowlist secret
    volumes:
      - ./db-drivers:/opt/db-drivers:ro
