# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Hedgedoc v2
spec:
    description: HedgeDoc lets you create real-time collaborative markdown notes.
    icon: https://avatars.githubusercontent.com/u/67865462?s=200&v=4
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: HedgeDoc Domain
          description: The domain name for HedgeDoc.
    tags:
        - Tool
    readme: |
        HedgeDoc lets you create real-time collaborative markdown notes.

        This is the v2 version of HedgeDoc, which is in development, but containing some new features and improvements.
    services:
        - name: postgresql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            id: postgresql
            source:
                image: postgres:17
                command:
                    - docker-entrypoint.sh
                    - -c
                    - config_file=/etc/postgresql/postgresql.conf
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/data
            instructions:
                - title: Connection String
                  content: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}
                - title: PostgreSQL Connect Command
                  content: psql "postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USERNAME}
                - title: PostgresSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgresSQL database
                  content: ${POSTGRES_DATABASE}
                - title: PostgreSQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                HD_DATABASE_HOST:
                    default: ${POSTGRES_HOST}
                    expose: true
                HD_DATABASE_NAME:
                    default: ${POSTGRES_DB}
                    expose: true
                HD_DATABASE_PASS:
                    default: ${POSTGRES_PASSWORD}
                    expose: true
                HD_DATABASE_PORT:
                    default: ${POSTGRES_PORT}
                    expose: true
                HD_DATABASE_TYPE:
                    default: postgres
                    expose: true
                HD_DATABASE_USER:
                    default: ${POSTGRES_USER}
                    expose: true
                PGDATA:
                    default: /var/lib/postgresql/data/pgdata
                POSTGRES_CONNECTION_STRING:
                    default: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                    expose: true
                POSTGRES_DATABASE:
                    default: ${POSTGRES_DB}
                    expose: true
                POSTGRES_DB:
                    default: zeabur
                POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                POSTGRES_URI:
                    default: ${POSTGRES_CONNECTION_STRING}
                    expose: true
                POSTGRES_USER:
                    default: root
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: true
            configs:
                - path: /etc/postgresql/postgresql.conf
                  template: |
                    # https://github.com/postgres/postgres/blob/master/src/backend/utils/misc/postgresql.conf.sample
                    listen_addresses = '*'
                    max_connections = 100
                    shared_buffers = 128MB
                    dynamic_shared_memory_type = posix
                    max_wal_size = 1GB
                    min_wal_size = 80MB
                    log_timezone = 'Etc/UTC'
                    datestyle = 'iso, mdy'
                    timezone = 'Etc/UTC'
                    lc_messages = 'en_US.utf8'
                    lc_monetary = 'en_US.utf8'
                    lc_numeric = 'en_US.utf8'
                    lc_time = 'en_US.utf8'
                    default_text_search_config = 'pg_catalog.english'
                  permission: null
                  envsubst: null
        - name: backend
          icon: https://avatars.githubusercontent.com/u/67865462?s=200&v=4
          template: PREBUILT
          spec:
            id: backend
            source:
                image: ghcr.io/hedgedoc/hedgedoc/backend:2.0.0-alpha.3
            ports:
                - id: api
                  port: 3000
                  type: HTTP
            volumes:
                - id: uploads
                  dir: /usr/src/app/backend/uploads
            env:
                HD_AUTH_LOCAL_ENABLE_LOGIN:
                    default: "true"
                HD_AUTH_LOCAL_ENABLE_REGISTER:
                    default: "true"
                HD_MEDIA_BACKEND:
                    default: filesystem
                HD_MEDIA_BACKEND_FILESYSTEM_UPLOAD_PATH:
                    default: /usr/src/app/backend/uploads
                HD_SESSION_SECRET:
                    default: ${PASSWORD}
                    expose: true
        - name: frontend
          icon: https://avatars.githubusercontent.com/u/67865462?s=200&v=4
          template: PREBUILT
          spec:
            id: frontend
            source:
                image: ghcr.io/hedgedoc/hedgedoc/frontend:2.0.0-alpha.3
            ports:
                - id: web
                  port: 3001
                  type: HTTP
            env:
                HD_INTERNAL_API_URL:
                    default: http://backend.zeabur.internal:3000
        - name: caddy
          icon: https://cdn.zeabur.com/caddy.png
          template: PREBUILT
          spec:
            id: caddy
            source:
                image: caddy:2-alpine
            ports:
                - id: web
                  port: 80
                  type: HTTP
            env:
                HD_BASE_URL:
                    default: ${ZEABUR_WEB_URL}
                    expose: true
            configs:
                - path: /etc/caddy/Caddyfile
                  template: |
                    {
                        servers {
                            trusted_proxies static private_ranges
                            trusted_proxies_strict
                        }
                    }

                    :80 {
                        log {
                            output stdout
                            level WARN
                            format console
                        }

                        reverse_proxy /realtime http://backend.zeabur.internal:3000
                        reverse_proxy /api/* http://backend.zeabur.internal:3000
                        reverse_proxy /public/* http://backend.zeabur.internal:3000
                        reverse_proxy /uploads/* http://backend.zeabur.internal:3000
                        reverse_proxy /media/* http://backend.zeabur.internal:3000
                        reverse_proxy /* http://frontend.zeabur.internal:3001
                    }
                  permission: null
                  envsubst: null
          domainKey: PUBLIC_DOMAIN
