---
version: "3.6"

services:
  nextcloud:
    build:
      context: .
      # Use the following example for adding cron:
      # https://github.com/nextcloud/docker/tree/master/.examples/dockerfiles/cron/apache
      dockerfile_inline: |
        FROM nextcloud:{{ nextcloud__version }}

        RUN apt-get update && apt-get install -y \
            supervisor \
          && rm -rf /var/lib/apt/lists/* \
          && mkdir /var/log/supervisord /var/run/supervisord

        RUN cat <<EOF > /supervisord.conf
{% filter indent(width=8) %}
        {{ lookup('ansible.builtin.file', 'supervisord.conf') }}
{% endfilter %}
        EOF

        ENV NEXTCLOUD_UPDATE=1

        CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf"]
    restart: unless-stopped
    ports:
      - "8080:80"
    depends_on:
      - db
      - redis
    networks:
      - nextcloud
    volumes:
{% if nextcloud__use_custom_new_user_skeleton %}
      - "./custom_new_user_skeleton:/custom_new_user_skeleton"
{% endif %}
      - "./nextcloud_var_www_html:/var/www/html"
      - "{{ nextcloud__data_dir }}:/var/www/html/data"
    environment:
      POSTGRES_HOST: db
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD: "{{ nextcloud__postgres_password }}"
      NEXTCLOUD_ADMIN_USER: admin
      NEXTCLOUD_ADMIN_PASSWORD: "{{ nextcloud__admin_password }}"
      REDIS_HOST: redis
      NEXTCLOUD_TRUSTED_DOMAINS: "{{ nextcloud__fqdn }}"
      # See here: https://github.com/nextcloud/docker#using-the-apache-image-behind-a-reverse-proxy-and-auto-configure-server-host-and-protocol
      APACHE_DISABLE_REWRITE_IP: 1
      TRUSTED_PROXIES: 127.0.0.1
      OVERWRITECLIURL: "https://{{ nextcloud__fqdn }}/"
      OVERWRITEHOST: "{{ nextcloud__fqdn }}"
      OVERWRITEPROTOCOL: "https"
    
  db:
    image: postgres:{{ nextcloud__postgres_version }}
    restart: unless-stopped
    networks:
      - nextcloud
    volumes:
      - "./database:/var/lib/postgresql/data"
    environment:
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD: "{{ nextcloud__postgres_password }}"

  redis:
    image: redis:alpine
    restart: unless-stopped
    networks:
      - nextcloud

networks:
  nextcloud:
    external: false