version: '3.7'

volumes:
  files:
    driver: local
  mysql:
    driver: local
  backup:
    driver: local
  redis:
    driver: local
  tmp:
    driver: local

services:
  traefik:
    image: "traefik:v2.2"
    container_name: "traefik"
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.websecure.address=:443"
      # Ocis certificate resolver
      - "--certificatesresolvers.ocis.acme.tlschallenge=true"
      - "--certificatesresolvers.ocis.acme.caserver=https://acme-v02.api.letsencrypt.org/directory"
      - "--certificatesresolvers.ocis.acme.email=user@${OCIS_DOMAIN}"
      - "--certificatesresolvers.ocis.acme.storage=/letsencrypt/acme-ocis.json"
      # OC10 certificate resolver
      - "--certificatesresolvers.oc10.acme.tlschallenge=true"
      - "--certificatesresolvers.oc10.acme.caserver=https://acme-v02.api.letsencrypt.org/directory"
      - "--certificatesresolvers.oc10.acme.email=user@${OCIS_DOMAIN}"
      - "--certificatesresolvers.oc10.acme.storage=/letsencrypt/acme-oc10.json"
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - "letsencrypt:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

  owncloud:
    build:
      context: ./oc10
      dockerfile: Dockerfile
    expose:
      - "8080"
    depends_on:
      - db
      - redis
    environment:
      OWNCLOUD_DOMAIN: ${OC10_DOMAIN}
      OWNCLOUD_DB_TYPE: mysql
      OWNCLOUD_DB_NAME: owncloud
      OWNCLOUD_DB_USERNAME: owncloud
      OWNCLOUD_DB_PASSWORD: owncloud
      OWNCLOUD_DB_HOST: db
      OWNCLOUD_ADMIN_USERNAME: admin
      OWNCLOUD_ADMIN_PASSWORD: admin
      OWNCLOUD_MYSQL_UTF8MB4: "true"
      OWNCLOUD_REDIS_ENABLED: "true"
      OWNCLOUD_REDIS_HOST: redis
      OWNCLOUD_DEBUG: "true"
      OWNCLOUD_TRUSTED_PROXIES: ${OC10_DOMAIN}
      OWNCLOUD_OVERWRITE_PROTOCOL: https
      OWNCLOUD_OVERWRITE_HOST: ${OC10_DOMAIN}
      OWNCLOUD_APPS_ENABLE: "openidconnect,oauth2,user_ldap,graphapi"
      OWNCLOUD_LOG_LEVEL: 0
    volumes:
      - files:/mnt/data
      - tmp:/tmp/shared
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.oc10.rule=Host(`${OC10_DOMAIN}`)"
      - "traefik.http.routers.oc10.entrypoints=websecure"
      - "traefik.http.routers.oc10.tls.certresolver=oc10"
      - "traefik.http.services.oc10.loadbalancer.server.port=8080"
      - "traefik.docker.network=ocisnet"
      - "traefik.protocol=https"

  ocis:
    image: owncloud/ocis:latest
    ports:
      - 9200:9200
    environment:
      OCIS_DOMAIN: ${OCIS_DOMAIN}
      PROXY_CONFIG_FILE: "/etc/ocis/proxy.json"
      PROXY_TLS: "false"
      PROXY_OIDC_ISSUER: https://${OCIS_DOMAIN}
      PROXY_OIDC_INSECURE: "true"
      PROXY_AUTOPROVISION_ACCOUNTS: "true"
      KONNECTD_ISS: https://${OCIS_DOMAIN}
      KONNECTD_IDENTIFIER_REGISTRATION_CONF: "/config/identifier-registration.yml"
      KONNECTD_TLS: 0
      KONNECTD_SIGNING_KID: super
      GRAPH_OIDC_ENDPOINT: https://${OC10_DOMAIN}/apps/graphapi/v1.0
      PHOENIX_OIDC_AUTHORITY: https://${OCIS_DOMAIN}
      PHOENIX_OIDC_METADATA_URL: https://${OCIS_DOMAIN}/.well-known/openid-configuration
      PHOENIX_WEB_CONFIG_SERVER: https://${OCIS_DOMAIN}
      STORAGE_OIDC_ISSUER: https://${OCIS_DOMAIN}
      STORAGE_TRANSFER_EXPIRES: 86400
      STORAGE_FRONTEND_URL: https://${OCIS_DOMAIN}
      STORAGE_DATAGATEWAY_URL: https://${OCIS_DOMAIN}/data
      STORAGE_LDAP_IDP: https://${OCIS_DOMAIN}
      STORAGE_STORAGE_METADATA_PROVIDER_DRIVER: owncloud # Storage fails start up if backend owncloud is selected and this env vars isn't set
      STORAGE_STORAGE_METADATA_DATA_PROVIDER_DRIVER: owncloud # Storage fails start up if backend owncloud is selected and this env vars isn't set
      GLAUTH_BACKEND_DATASTORE: owncloud
      GLAUTH_BACKEND_SERVERS: https://${OC10_DOMAIN}/apps/graphapi/v1.0
      GLAUTH_BACKEND_BASEDN: dc=example,dc=org
      ACCOUNTS_STORAGE_DISK_PATH: /var/tmp/ocis-accounts # Accounts fails to start when cs3 backend is used atm
      # Konnectd ldap setup
      LDAP_URI: ldap://localhost:9125
      LDAP_BINDDN: "cn=admin,dc=example,dc=org"
      LDAP_BINDPW: "admin"
      LDAP_BASEDN: "dc=example,dc=org"
      LDAP_SCOPE: sub
      LDAP_LOGIN_ATTRIBUTE: uid
      LDAP_EMAIL_ATTRIBUTE: mail
      LDAP_NAME_ATTRIBUTE: givenName
      LDAP_UUID_ATTRIBUTE: uid
      LDAP_UUID_ATTRIBUTE_TYPE: text
      LDAP_FILTER: "(objectClass=posixaccount)"
    volumes:
      - ./ocis:/config
      - ./ocis/proxy-config.json:/etc/ocis/proxy.json
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.ocis.rule=Host(`${OCIS_DOMAIN}`)"
      - "traefik.http.routers.ocis.entrypoints=websecure"
      - "traefik.http.routers.ocis.tls.certresolver=ocis"
      - "traefik.http.services.ocis.loadbalancer.server.port=9200"
      - "traefik.docker.network=ocisnet"
      - "traefik.protocol=https"

  db:
    image: webhippie/mariadb:latest
    restart: always
    environment:
      MARIADB_ROOT_PASSWORD: owncloud
      MARIADB_USERNAME: owncloud
      MARIADB_PASSWORD: owncloud
      MARIADB_DATABASE: owncloud
      MARIADB_MAX_ALLOWED_PACKET: 128M
      MARIADB_INNODB_LOG_FILE_SIZE: 256M
    healthcheck:
      test: ["CMD", "/usr/bin/healthcheck"]
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - mysql:/var/lib/mysql
      - backup:/var/lib/backup

  redis:
    image: webhippie/redis:latest
    environment:
      - REDIS_DATABASES=1
    volumes:
      - redis:/var/lib/redis
