# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Nextcloud with Office
spec:
    description: Open source content collaboration platform. Include Collabora Online for document editing.
    icon: https://cdn.zeabur.com/nextcloud.svg
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Nextcloud domain
          description: The domain of your Nextcloud instance.
        - key: OFFICE_DOMAIN
          type: DOMAIN
          name: Collabora Online domain
          description: The domain of your Collabora Online instance.
    readme: |
        # Nextcloud

        Nextcloud is open source file sync and share software for everyone from individuals operating the free Nextcloud Server in the privacy of their own home, to large enterprises and service providers supported by the Nextcloud Enterprise Subscription. Nextcloud provides a safe, secure, and compliant file synchronization and sharing solution on servers that you control.

        ## Deployment

        This is the one-click template. You only need to set up Nextcloud itself. The template will automatically deploy MariaDB and Redis as the database and cache for Nextcloud.

        Note that initialization may take some time. Please be patient and wait for the deployment to be ready. **You should also disable the health check when initializing Nextcloud (or it will be restarted too soon).**

        ## Collabora Online

        This template includes Collabora Online, an open-source office suite that allows you to edit documents directly in your browser. It integrates with Nextcloud, providing a seamless editing experience.

        To enable document editing, install the [Collabora Online app](https://apps.nextcloud.com/apps/richdocuments) in Nextcloud. After installation, set up the Collabora Online server in Nextcloud Settings under Collabora Online. Point the server to your office's public URL, which may look like `https://office.zeabur.app`.
    services:
        - name: mariadb
          icon: https://cdn.zeabur.com/mariadb.svg
          template: PREBUILT
          spec:
            source:
                image: mariadb:11
            ports:
                - id: database
                  port: 3306
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/mysql
            instructions:
                - title: Command to connect to your MariaDB
                  content: mariadb --host ${PORT_FORWARDED_HOSTNAME} --host=${PORT_FORWARDED_HOSTNAME} --port=${DATABASE_PORT_FORWARDED_PORT} --user=${MARIADB_USERNAME} --password=${MARIADB_PASSWORD} --database=${MARIADB_DATABASE}
                - title: MariaDB username
                  content: ${MARIADB_USERNAME}
                - title: MariaDB password
                  content: ${MARIADB_PASSWORD}
                - title: MariaDB database
                  content: ${MARIADB_DATABASE}
                - title: MariaDB host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: MariaDB port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                MARIADB_DATABASE:
                    default: zeabur
                    expose: true
                MARIADB_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                MARIADB_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                MARIADB_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                MARIADB_ROOT_PASSWORD:
                    default: ${PASSWORD}
                MARIADB_USERNAME:
                    default: root
                    expose: true
                MYSQL_DATABASE:
                    default: ${MARIADB_DATABASE}
                    expose: true
                MYSQL_HOST:
                    default: ${MARIADB_HOST}
                    expose: true
                MYSQL_PASSWORD:
                    default: ${MARIADB_PASSWORD}
                    expose: true
                MYSQL_USER:
                    default: ${MARIADB_USERNAME}
                    expose: true
            configs:
                - path: /etc/mysql/conf.d/99-custom.cnf
                  template: |
                    ; see https://mariadb.com/kb/en/server-system-variables/#setting-server-system-variables for configuration
                  permission: null
                  envsubst: null
        - name: redis
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/redis.svg
          template: PREBUILT
          spec:
            source:
                image: redis/redis-stack-server:latest
            ports:
                - id: database
                  port: 6379
                  type: TCP
            volumes:
                - id: data
                  dir: /data
            instructions:
                - title: Command to connect to your Redis
                  content: redis-cli -h ${PORT_FORWARDED_HOSTNAME} -p ${DATABASE_PORT_FORWARDED_PORT} -a ${REDIS_PASSWORD}
                - title: Redis Connection String
                  content: redis://:${REDIS_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}
                - title: Redis password
                  content: ${REDIS_PASSWORD}
                - title: Redis host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: Redis port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                CONFFILE:
                    default: /etc/redis-stack.conf
                REDIS_ARGS:
                    default: --requirepass ${REDIS_PASSWORD}
                REDIS_CONNECTION_STRING:
                    default: redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}
                    expose: true
                REDIS_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                REDIS_HOST_PASSWORD:
                    default: ${REDIS_PASSWORD}
                    expose: true
                REDIS_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                REDIS_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                REDIS_URI:
                    default: ${REDIS_CONNECTION_STRING}
                    expose: true
            configs:
                - path: /etc/redis-stack.conf
                  template: |
                    port 6379
                    daemonize no
                  permission: null
                  envsubst: null
        - name: nextcloud
          icon: https://cdn.zeabur.com/nextcloud.svg
          template: PREBUILT
          spec:
            source:
                image: nextcloud
            ports:
                - id: http
                  port: 80
                  type: HTTP
            volumes:
                - id: nextcloud-storage
                  dir: /var/www/html
            env:
                OVERWRITEHOST:
                    default: ${ZEABUR_HTTP_DOMAIN}
                OVERWRITEPROTOCOL:
                    default: https
                TRUSTED_PROXIES:
                    default: 10.0.0.0/8
          domainKey: PUBLIC_DOMAIN
        - name: office
          icon: https://avatars.githubusercontent.com/u/22418908?s=200&v=4
          template: PREBUILT
          spec:
            source:
                image: collabora/code
                runAsUserID: 1001
            ports:
                - id: web
                  port: 9980
                  type: HTTP
            env:
                extra_params:
                    default: --o:ssl.enable=false --o:ssl.termination=true
                server_name:
                    default: ${ZEABUR_WEB_DOMAIN}
          domainKey: OFFICE_DOMAIN
