services:
  web:
    image: nginx
    extends:
      file: docker-compose.core.yml
      service: web
    volumes:
      - ./nginx/web.conf:/etc/nginx/nginx.conf
      - ./nginx/logs/nginx:/var/log/nginx
    depends_on:
      core:
        condition: service_healthy
  installer:
    extends:
      file: docker-compose.core.yml
      service: setup
    image: nextcloud:fpm
    restart: on-failure
    entrypoint:
      - bash
      - -c
      - /entrypoint.sh php-fpm & while ! echo '' 2>/dev/null >/dev/tcp/127.0.0.1/9000; do sleep 1; done; kill -9 $!; true;
  db:
    image: mariadb:lts
    restart: unless-stopped
    env_file: db.env
    environment:
      MARIADB_RANDOM_ROOT_PASSWORD: "yes"
      MARIADB_MYSQL_LOCALHOST_USER: 1
    volumes:
      - ./data/db:/var/lib/mysql
    command:
      - --innodb_read_only_compressed=OFF
    healthcheck:
      test: [CMD, healthcheck.sh, --su-mysql, --connect, --innodb_initialized]
      start_period: 1m
      start_interval: 10s
      interval: 1m
      timeout: 5s
      retries: 3
  cache:
    build:
      context: .
      dockerfile: cache.Dockerfile
    restart: unless-stopped
    env_file:
      - cache.env
    volumes:
      - ./data/cache:/data
    healthcheck:
      test: [CMD, bash, -c, echo '' > /dev/tcp/127.0.0.1/6379]
      interval: 5s
      timeout: 3s
      retries: 5
  core:
    extends:
      file: docker-compose.core.yml
      service: nextcloud
    build:
      context: .
      dockerfile: cloud.Dockerfile
    cap_add:
      - SYS_ADMIN
    depends_on: &nextcloud-conditions
      db:
        condition: service_healthy
      cache:
        condition: service_healthy
      installer:
        condition: service_completed_successfully
        restart: true
    healthcheck:
      test: [CMD, bash, -c , php-fpm-healthcheck]
      start_period: 1m
      start_interval: 10s
      interval: 1m
      timeout: 5s
      retries: 5
  cron:
    extends:
      file: docker-compose.core.yml
      service: nextcloud
    image: nextcloud:fpm
    depends_on:
      <<: *nextcloud-conditions
    entrypoint: /cron.sh
  bridge:
    image: shenxn/protonmail-bridge
    restart: unless-stopped
    volumes:
      - ./data/bridge:/root
  turn:
    image: instrumentisto/coturn
    restart: unless-stopped
  collabora:
    image: collabora/code
    restart: unless-stopped
    environment:
      dictionaries: de_CH de en
      extra_params: '--o:logging.level_startup=warning --o:ssl.enable=true --o:ssl.termination=true --o:user_interface.mode=notebookbar'
    volumes:
      - /etc/localtime:/etc/localtime:ro
    cap_add:
      - MKNOD

volumes:
  webroot: {}