#{{services
services:
#}}
#{{db
  db:
    image: mariadb:11.4
    container_name: ${orga}-DB
    #disk_quota: 10G
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: ${restartPolicy}
    volumes:
#      - ./initdb.d:/docker-entrypoint-initdb.d:ro
      - orgaDB:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    environment:
      - MARIADB_AUTO_UPGRADE=1
    env_file:
      - ../../secret/orgas/${orga}/env-${nextcloudDBName}
#      - ../../secret/orgas/${orga}/env-${mattermostDBName}
      - ../../secret/orgas/${orga}/env-${wordpressDBName}
    networks:
      - orgaNet
    healthcheck: # utilisé par init-db.sh pour la créa d'orga
      #maridb10.5
      #test: ["CMD", 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root', '-p$$MYSQL_ROOT_PASSWORD' ]
      #maridb11.4
      #test: ["CMD", 'healthcheck.sh', '--su-mysql', '--connect', '--innodb_initialized']
      test: ["CMD", "mariadb-admin", "ping", "--silent"]
      interval: 30s
      timeout: 30s
      retries: 5
#}}
#{{cloud
  cloud:
    image: nextcloud
    container_name: ${orga}-${nextcloudServName}
    #disk_quota: 10G
    restart: ${restartPolicy}
    networks:
      - orgaNet
#      - postfixNet
    depends_on:
      - db
      #db:
      #    condition: service_healthy  # on peut mais ca va ralentir le process
    links:
      - db
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${orga}-${nextcloudServName}.rule=Host(`${orga}-${cloudHost}.${domain}`){{FOREIGN_NC}}"
      - "traefik.http.routers.${orga}-${nextcloudServName}.middlewares=nextcloud-redirectregex1@file,nextcloud-redirectregex2@file"
    volumes:
      - cloudMain:/var/www/html
      - cloudData:/var/www/html/data
      - cloudConfig:/var/www/html/config
      - cloudApps:/var/www/html/apps
      - cloudCustomApps:/var/www/html/custom_apps
      - cloudThemes:/var/www/html/themes/
      - cloudPhp:/usr/local/etc/php/conf.d/
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    env_file:
      - ../../secret/orgas/${orga}/env-${nextcloudServName}
      - ../../secret/orgas/${orga}/env-${nextcloudDBName}
    environment:
      - NEXTCLOUD_TRUSTED_DOMAINS=${orga}-${cloudHost}.${domain}
      - MAIL_DOMAIN=${domain}
#}}
#{{agora
  agora:
    build:
      context: app
      # uncomment following lines for team edition or change UID/GID
      args:
        - edition=team
        - PUID=1000
        - PGID=1000
    container_name: ${orga}-${mattermostServName}
    #disk_quota: 10G
    restart: ${restartPolicy}
    # memory: 1G
    networks:
      - orgaNet
#      - postfixNet
    expose:
      - ${matterPort}
    depends_on:
      - db
      #db:
          # condition: service_healthy  # on peut mais ca va ralentir le process
    links:
      - db
    volumes:
      - matterConfig:/mattermost/config:rw
      - matterData:/mattermost/data:rw
      - matterLogs:/mattermost/logs:rw
      - matterPlugins:/mattermost/plugins:rw
      - matterClientPlugins:/mattermost/client/plugins:rw
      - matterIcons:/mattermost/client/images:ro
      - /etc/ssl:/etc/ssl:ro
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /etc/environment:/etc/environment:ro
    env_file:
      - ../../secret/orgas/${orga}/env-${mattermostServName}
    environment:
      - VIRTUAL_HOST=${orga}-${matterHost}.${domain}
      # in case your config is not in default location
      #- MM_CONFIG=/mattermost/config/config.json

    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${orga}-${mattermostServName}.rule=Host(`${orga}-${matterHost}.${domain}`)"
#}}
#{{wp
  wordpress:
    image: wordpress
    container_name: ${orga}-${wordpressServName}
    restart: ${restartPolicy}
    networks:
      - orgaNet
#      - postfixNet
    depends_on:
      - db
      #db:
         # condition: service_healthy  # on peut mais ca va ralentir le process
    links:
      - db
    env_file:
      - ../../secret/orgas/${orga}/env-${wordpressServName}
    environment:
      # - WORDPRESS_SMTP_HOST=${smtpHost}.${domain}
      # - WORDPRESS_SMTP_PORT=25
      # - WORDPRESS_SMTP_USERNAME
      # - WORDPRESS_SMTP_PASSWORD
      # - WORDPRESS_SMTP_FROM=${orga}-
      - WORDPRESS_SMTP_FROM_NAME=${orga}-
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${orga}-${wordpressServName}.rule=Host(`${orga}-${wordpressHost}.${domain}`){{FOREIGN_WP}}"
    volumes:
      - wordpress:/var/www/html
#      - ../../config/orgaTmpl/wp:/usr/local/bin/wp:ro
#}}
#{{wiki
  dokuwiki:
    image: dokuwiki/dokuwiki
    container_name: ${orga}-${dokuwikiServName}
    #disk_quota: 10G
    restart: ${restartPolicy}
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${orga}-${dokuwikiServName}.rule=Host(`${orga}-${dokuwikiHost}.${domain}`){{FOREIGN_DW}}"
      - "traefik.http.services.${orga}-${dokuwikiServName}.loadbalancer.server.port=8080"
    volumes:
      - wikiData:/storage/data
      - wikiConf:/storage/conf
      - wikiPlugins:/storage/lib/plugins
      - wikiLibtpl:/storage/lib/tpl
      - wikiLogs:/var/log
    networks:
      - orgaNet
#}}
#{{castopod
  castopod:
    image: castopod/castopod:latest
    container_name: ${orga}-${castopodServName}
    #disk_quota: 10G
    restart: ${restartPolicy}
    # memory: 1G
    networks:
      - orgaNet
#      - postfixNet
    expose:
      - 8000
    depends_on:
      - db
    links:
      - db
    volumes:
      - castopodMedia:/var/www/castopod/public/media
    environment:
      CP_BASEURL: "https://${orga}-${castopodHost}.${domain}"
      CP_ANALYTICS_SALT: qldsgfliuzrbhgmkjbdbmkvb
      VIRTUAL_PORT: 8000
      CP_CACHE_HANDLER: redis
      CP_REDIS_HOST: redis
      CP_DATABASE_HOSTNAME: db
    env_file:
      - ../../secret/orgas/${orga}/env-${castopodServName}
      - ../../secret/orgas/${orga}/env-${castopodDBName}
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${orga}-${castopodServName}.rule=Host(`${orga}-${castopodHost}.${domain}`){{FOREIGN_POD}}"
  redis:
    image: redis:7.0-alpine
    container_name: ${orga}-castopodCache
    volumes:
      - castopodCache:/data
    networks:
      - orgaNet
    env_file:
      - ../../secret/orgas/${orga}/env-${castopodServName}
    command: --requirepass ${castopodRedisPassword}
#}}
#{{spip
  spip:
    container_name: ${orga}-${spipServName}
    image: ipeos/spip:4.4
    restart: ${restartPolicy}
    depends_on:
      - db
    links:
      - db
    env_file:
      - ../../secret/orgas/${orga}/env-${spipServName}
    environment:
      - SPIP_AUTO_INSTALL=1
      - SPIP_DB_HOST=db
      - SPIP_SITE_ADDRESS=https://${orga}-${spipHost}.${domain}
    expose:
      - 80
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${orga}-${spipServName}.rule=Host(`${orga}-${spipHost}.${domain}`){{FOREIGN_SPIP}}"
    networks:
      - orgaNet
    volumes:
      - spip:/usr/src/spip
#}}
#{{webdav
  webdav:
    image: httpd:2.4
    container_name: ${orga}-${webdavServName}
    restart: unless-stopped
    networks:
      - orgaNet
    environment:
      #surcharge dans compose.override.yml
      - LDAP_USERS=
      - DOMAIN=${domain}
      - LDAP_ROOT=${ldap_root}
    volumes:
      - wordpress:/var/www/webdav
      - ./webdav-conf/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
      - ./webdav-conf/httpd-webdav.conf:/usr/local/apache2/conf/extra/httpd-webdav.conf:ro      
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${orga}-${webdavServName}.rule=Host(`${orga}-${webdavHost}.${domain}`)"
#}}


#{{services
volumes:
#}}
#{{db
  orgaDB:
    external: true
    name: orga_${orga}-orgaDB
#}}
#{{agora
  matterConfig:
    external: true
    name: orga_${orga}-matterConfig
  matterData:
    external: true
    name: orga_${orga}-matterData
  matterLogs:
    external: true
    name: orga_${orga}-matterLogs
  matterPlugins:
    external: true
    name: orga_${orga}-matterPlugins
  matterClientPlugins:
    external: true
    name: orga_${orga}-matterClientPlugins
  matterIcons:
    external: true
    name: matterIcons
#{{cloud
  cloudMain:
    external: true
    name: orga_${orga}-cloudMain
  cloudData:
    external: true
    name: orga_${orga}-cloudData
  cloudConfig:
    external: true
    name: orga_${orga}-cloudConfig
  cloudApps:
    external: true
    name: orga_${orga}-cloudApps
  cloudCustomApps:
    external: true
    name: orga_${orga}-cloudCustomApps
  cloudThemes:
    external: true
    name: orga_${orga}-cloudThemes
  cloudPhp:
    external: true
    name: orga_${orga}-cloudPhp
#}}
#{{wiki
  wikiData:
    external: true
    name: orga_${orga}-wikiData
  wikiConf:
    external: true
    name: orga_${orga}-wikiConf
  wikiPlugins:
    external: true
    name: orga_${orga}-wikiPlugins
  wikiLibtpl:
    external: true
    name: orga_${orga}-wikiLibtpl
  wikiLogs:
    external: true
    name: orga_${orga}-wikiLogs
#}}
#{{wp
  wordpress:
    external: true
    name: orga_${orga}-wordpress
#}}
#{{castopod
  castopodMedia:
    external: true
    name: orga_${orga}-castopodMedia
  castopodCache:
    external: true
    name: orga_${orga}-castopodCache
#}}
#{{spip
  spip:
    external: true
    name: orga_${orga}-spip
#}}



networks:
  orgaNet:
    external: true
    name: ${orga}-orgaNet
  # postfixNet:
  #   external:
  #     name: postfixNet
