# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Logto
spec:
    description: The better identity infrastructure for developers
    icon: https://dev-to-uploads.s3.amazonaws.com/uploads/organization/profile_image/6720/caee4597-8613-4fdc-902a-955dea9855b4.png
    variables:
        - key: ENDPOINT_DOMAIN
          type: DOMAIN
          name: Logto API URL
          description: The URL of the Logto API
        - key: ADMIN_ENDPOINT_DOMAIN
          type: DOMAIN
          name: Logto Admin Console URL
          description: The URL of the Logto Admin Console
    tags:
        - Website
        - Database
        - API
    readme: |
        # Logto

        Logto (Designed by Silverhand Inc.) is an Auth0 alternative designed for modern apps and SaaS products. It offers a seamless developer experience and is well-suited for individuals and growing companies.

        ## Features

        Logto provides a comprehensive frontend-to-backend identity solution that enables OIDC-based authentication with SDKs, supports passwordless sign-in and various social sign-in options, and offers customizable UI components with an active community for support.

        Logto's out-of-the-box infrastructure includes a ready-to-use Management API, SDKs for seamless integration across platforms, and flexible connectors that support SAML, OAuth, and OIDC protocols.

        For enterprise solutions, Logto provides role-based access control, facilitates user management with audit logs, supports single sign-on (SSO) and multi-factor authentication, and enables easy multi-tenancy app development with Logto organizations.

        ## Deployment

        It is a out-of-the-box template. To change your domain, just bind a new domain and restart your service. `_DOMAIN` variables are only for the domain binding and you can feel free to not change them.

        The upgrade of Logto should be *careful*. [Check Logto's documentation for more information](https://docs.logto.io/docs/recipes/deployment/#how-can-i-upgrade-logto-safely).

        For the detailed deployment steps, [check our documentation](https://zeabur.com/docs/marketplace/logto).
    services:
        - name: postgresql
          icon: https://cdn.zeabur.com/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:
                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: Logto
          icon: https://dev-to-uploads.s3.amazonaws.com/uploads/organization/profile_image/6720/caee4597-8613-4fdc-902a-955dea9855b4.png
          template: PREBUILT
          spec:
            id: logto
            source:
                image: svhd/logto:1.29
                command:
                    - sh
                args:
                    - -c
                    - npm run cli db seed -- --swe && npm start
            ports:
                - id: web
                  port: 3001
                  type: HTTP
                - id: console
                  port: 3002
                  type: HTTP
            env:
                ADMIN_ENDPOINT:
                    default: ${ZEABUR_CONSOLE_URL}
                DB_URL:
                    default: postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                ENDPOINT:
                    default: ${ZEABUR_WEB_URL}
                TRUST_PROXY_HEADER:
                    default: "true"
          domainKey:
            - port: web
              variable: ENDPOINT_DOMAIN
            - port: console
              variable: ADMIN_ENDPOINT_DOMAIN
