services:
  db:
    image: postgres:17    
    restart: always
    volumes:
      - {{ service_directory }}/data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_USER
    networks:
      - default

  redis:
    image: redis:alpine    
    restart: always
    volumes:
      - {{ service_directory }}/data/redis:/data
    networks:
      - default 

  app:
    image: nextcloud:{{nextcloud_version}}    
    restart: always
    ports:
      - 127.0.0.1:10080:80
    volumes:
      - {{ service_directory }}/data/system:/var/www/html
      - {{ service_directory }}/data/apps:/var/www/html/custom_apps
      - {{ service_directory }}/data/config:/var/www/html/config
      - {{ service_directory }}/data/appdata:/var/www/html/data
      - {{ service_directory }}/data/themes:/var/www/html/themes
    networks:
      - default
    environment:
      - POSTGRES_HOST      
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_USER
      - NEXTCLOUD_ADMIN_PASSWORD
      - NEXTCLOUD_ADMIN_USER
      - REDIS_HOST
      - APACHE_DISABLE_REWRITE_IP
      - TRUSTED_PROXIES
      - NEXTCLOUD_TRUSTED_DOMAINS
      - OVERWRITEPROTOCOL  
    depends_on:
      - db
      - redis

  cron:
    image: nextcloud:{{nextcloud_version}}    
    restart: always
    volumes:
      - {{ service_directory }}/data/system:/var/www/html
      - {{ service_directory }}/data/apps:/var/www/html/custom_apps
      - {{ service_directory }}/data/config:/var/www/html/config
      - {{ service_directory }}/data/appdata:/var/www/html/data
      - {{ service_directory }}/data/themes:/var/www/html/themes
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis

  documentserver:
    image: onlyoffice/documentserver
    restart: always
    environment:
      - TZ
      - JWT_SECRET
    volumes:
      - /opt/nextcloud/data/onlyoffice/data:/var/www/onlyoffice/Data
      - /opt/nextcloud/data/onlyoffice/db:/var/lib/postgresql
      - /opt/nextcloud/data/onlyoffice/fonts:/usr/share/fonts/truetype/custom
      - /opt/nextcloud/data/onlyoffice/log:/var/log/onlyoffice
      - /opt/nextcloud/data/onlyoffice/app:/var/lib/onlyoffice
      - /opt/nextcloud/data/onlyoffice/rabbitmq:/var/lib/rabbitmq
      - /opt/nextcloud/data/onlyoffice/redis:/var/lib/redis
    ports:
      - 127.0.0.1:10081:80      
    networks:
      default:

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.18.2
    container_name: elasticsearch
    restart: always
    volumes:
      - /volumes/nextcloud/elasticsearch/data:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=true
      - ELASTIC_PASSWORD=elastic
      - cluster.name=elasticsearch
      - bootstrap.memory_lock=true
      - ES_JAVA_OPTS=-Xms1g -Xmx1g
      - xpack.security.http.ssl.enabled=false
    networks:
      default:

  xwiki:
    image: xwiki:stable-postgres-tomcat
    container_name: xwiki
    restart: always
    depends_on:
      - xwiki-db
    ports:
      - 8080:8080
    environment:
      - DB_USER=xwiki
      - DB_PASSWORD=xwiki
      - DB_HOST=xwiki-db
    volumes:
      - /volumes/nextcloud/xwiki/data:/usr/local/xwiki
      - /volumes/nextcloud/xwiki/data/xwiki.cfg:/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.cfg
      - /volumes/nextcloud/xwiki/data/xwiki.properties:/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties
    networks:
      default:

  xwiki-db:
    image: postgres:17
    container_name: xwiki-db
    restart: always
    volumes:
      - /volumes/nextcloud/xwiki/db/data:/var/lib/postgresql/data
    environment:
      - POSTGRES_ROOT_PASSWORD=xwiki
      - POSTGRES_PASSWORD=xwiki
      - POSTGRES_USER=xwiki
      - POSTGRES_DB=xwiki
      - POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8
    networks:
      default:

  

networks:
  default:
    ipam:
      driver: default
      config:
        - subnet: 172.3.0.0/16
          gateway: 172.3.0.1