# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: n8n-starter-custom-libs
spec:
    description: n8n v2 with PostgreSQL and Custom Python Task Runner (Supports custom pip packages).
    coverImage: https://i.imgur.com/Hm4GdsP.png
    icon: https://i.imgur.com/KUcP61Z.png
    variables:
        - key: POSTGRES_PASSWORD
          type: STRING
          name: Database Password
          description: 'Password for the PostgreSQL database (Default suggestion: n8npassword)'
        - key: N8N_ENCRYPTION_KEY
          type: STRING
          name: n8n Encryption Key
          description: 'Key for n8n credential encryption (Default suggestion: n8nkey123)'
        - key: TASK_RUNNER_AUTH_TOKEN
          type: STRING
          name: Task Runner Auth Token
          description: 'Shared secret between n8n and task runners (Default suggestion: n8nrunnersecret)'
    readme: |
        # n8n Starter with Custom Python Libraries

        A simplified n8n v2 setup designed for education and customization.

        ## Features
        - **n8n Main**: Workflow automation engine.
        - **PostgreSQL**: Robust database.
        - **Custom Task Runner**: **Git-based deployment** allows you to install ANY Python library (pandas, numpy, etc.) by editing `task-runner/Dockerfile` or `requirements.txt`.

        ## How to install Custom Libraries?
        1. Fork this repository.
        2. Edit `task-runner/Dockerfile`.
        3. Add your `pip install` commands.
        4. Zeabur will automatically rebuild the runner.
    services:
        - name: postgresql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            id: postgresql
            source:
                image: postgres:15-alpine
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/data
            instructions:
                - title: Connection String
                  content: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DB}
                - title: PostgreSQL Connect Command
                  content: psql "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DB}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USER}
                - title: PostgresSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgresSQL database
                  content: ${POSTGRES_DB}
                - title: PostgreSQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                PGDATA:
                    default: /var/lib/postgresql/data/pgdata
                POSTGRES_DB:
                    default: n8n
                POSTGRES_PASSWORD:
                    default: ${POSTGRES_PASSWORD}
                POSTGRES_USER:
                    default: postgres
        - name: n8n-app
          icon: https://i.imgur.com/KUcP61Z.png
          template: PREBUILT
          spec:
            id: n8n-app
            source:
                image: n8nio/n8n:2.2.3
            ports:
                - id: web
                  port: 5678
                  type: HTTP
                - id: taskbroker
                  port: 5679
                  type: TCP
            volumes:
                - id: n8n-data
                  dir: /home/node/.n8n
            instructions:
                - title: n8n Webhook URL
                  content: https://${ZEABUR_WEB_URL}
            env:
                DB_POSTGRESDB_CONNECTION_TIMEOUT:
                    default: "30000"
                DB_POSTGRESDB_DATABASE:
                    default: n8n
                DB_POSTGRESDB_HOST:
                    default: postgresql
                DB_POSTGRESDB_PASSWORD:
                    default: ${POSTGRES_PASSWORD}
                DB_POSTGRESDB_PORT:
                    default: "5432"
                DB_POSTGRESDB_USER:
                    default: postgres
                DB_TYPE:
                    default: postgresdb
                N8N_ENCRYPTION_KEY:
                    default: ${N8N_ENCRYPTION_KEY}
                N8N_HOST:
                    default: ${ZEABUR_WEB_DOMAIN}
                N8N_RUNNERS_AUTH_TOKEN:
                    default: ${TASK_RUNNER_AUTH_TOKEN}
                N8N_RUNNERS_BROKER_LISTEN_ADDRESS:
                    default: 0.0.0.0
                N8N_RUNNERS_ENABLED:
                    default: "true"
                N8N_RUNNERS_MODE:
                    default: external
                WEBHOOK_URL:
                    default: ${ZEABUR_WEB_URL}
        - name: n8n-python-runner
          icon: https://i.imgur.com/KUcP61Z.png
          template: GIT
          spec:
            id: n8n-python-runner
            source:
                source: GITHUB
                repo: 1128871803
                branch: main
                rootDirectory: task-runner
            env:
                N8N_RUNNERS_AUTH_TOKEN:
                    default: ${TASK_RUNNER_AUTH_TOKEN}
                N8N_RUNNERS_MAX_CONCURRENCY:
                    default: "5"
                N8N_RUNNERS_TASK_BROKER_URI:
                    default: http://n8n-app:5679
