# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Listmonk (without DB)
spec:
    description: For users to test the latest Listmonk (please read the instructions)
    icon: https://cdn.zeabur.com/listmonk.svg
    variables:
        - key: LISTMONK_DOMAIN
          type: DOMAIN
          name: Listmonk Domain
          description: What is the URL of Listmonk you want to access to?
    tags:
        - Website
    readme: |
        # Listmonk (without DB)
        > For users wanting to test the latest Listmonk version

        Change environment variable `UPGRADE_LISTMONK_DATABASE` to "true" to deploy the migration.

        The upgrade of Listmonk should be *careful*. [Check Listmonk's documentation for more information](https://listmonk.app/docs/upgrade/).
    services:
        - name: listmonk-nodb
          icon: https://cdn.zeabur.com/listmonk.svg
          template: PREBUILT
          spec:
            id: listmonk-latest
            source:
                image: listmonk/listmonk:latest
                command:
                    - /bin/sh
                args:
                    - /bin/docker-entrypoint.sh
            ports:
                - id: web
                  port: 9000
                  type: HTTP
            env:
                LISTMONK_db__database:
                    default: ${POSTGRES_DATABASE}
                LISTMONK_db__host:
                    default: ${POSTGRES_HOST}
                LISTMONK_db__password:
                    default: ${POSTGRES_PASSWORD}
                LISTMONK_db__port:
                    default: ${POSTGRES_PORT}
                LISTMONK_db__ssl_mode:
                    default: disable
                LISTMONK_db__user:
                    default: ${POSTGRES_USERNAME}
                UPGRADE_LISTMONK_DATABASE:
                    default: "false"
            configs:
                - path: /bin/docker-entrypoint.sh
                  template: |
                    #!/bin/sh
                    set -ex

                    listmonk_wrapper() {
                      ./listmonk --yes --config /etc/listmonk/config.toml $@
                    }

                    listmonk_wrapper --install --idempotent

                    if [[ "$UPGRADE_LISTMONK_DATABASE" = "true" ]]; then
                      listmonk_wrapper --upgrade
                    fi

                    listmonk_wrapper
                  permission: null
                  envsubst: null
                - path: /etc/listmonk/config.toml
                  template: |
                    [app]
                    # Interface and port where the app will run its webserver.
                    # Do not change it.
                    address = "0.0.0.0:9000"

                    max_open = 25
                    max_idle = 25
                    max_lifetime = "300s"

                    # Optional space separated Postgres DSN params. eg: "application_name=listmonk gssencmode=disable"
                    params = ""
                  permission: null
                  envsubst: null
          domainKey: LISTMONK_DOMAIN
