# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: n8n
spec:
    description: |
        n8n is the fair-code workflow automation platform. Connect any app with
        any API and automate tasks visually with 400+ integrations — no code
        required. Deploys with SQLite persistence and an auto-generated
        encryption key.
    icon: https://files.catbox.moe/3lwjoe.svg
    variables:
        - key: N8N_DOMAIN
          type: DOMAIN
          name: Domain
          description: Custom domain to bind to n8n (optional — a free zeabur.app domain is assigned by default)
    tags:
        - Automation
        - Workflow
        - No-Code
    readme: |
        # n8n on Zeabur

        Deploy [n8n](https://n8n.io/) — the fair-code workflow automation platform — on Zeabur with automatic volume persistence.

        ## Features

        - **Self-hosted** — source-available license, deploy on your own infrastructure
        - **400+ integrations** — HTTP, databases, AI models, Slack, GitHub, and more
        - **Visual editor** — build workflows by dragging and connecting nodes
        - **Persistent data** — workflows, credentials, and the SQLite database live on a persistent volume
        - **Auto-generated encryption key** — credentials are encrypted at rest out of the box

        ## Getting Started

        1. Click the **Deploy** button on the template page and pick a region.
        2. Wait for the service to start (first boot takes 30–60 seconds).
        3. Open the generated `https://<service>.zeabur.app` URL (or your custom domain) and create your n8n account.

        ## Configuration

        | Variable | Default | Description |
        |----------|---------|-------------|
        | `N8N_ENCRYPTION_KEY` | auto-generated | Encrypts credentials stored in workflows. **Set it manually and never change it** — changing it will make saved credentials unreadable. |
        | `GENERIC_TIMEZONE` | `UTC` | Timezone used by the scheduler, e.g. `America/New_York` |
        | `N8N_BASIC_AUTH_ACTIVE` | `false` | Set to `true` to require basic auth on the editor (pair with `N8N_BASIC_AUTH_USER` / `N8N_BASIC_AUTH_PASSWORD`) |
        | `N8N_PORT` | `5678` | Port n8n listens on (Zeabur maps this automatically) |

        All variables can be edited later in **Project → Variables**.

        ## Data Persistence

        A persistent volume is mounted at `/home/node/.n8n`, storing workflows,
        credentials, and the embedded SQLite database. Data survives redeploys and
        restarts.

        ## Troubleshooting

        - **Credentials fail to decrypt after redeploy** — the encryption key changed. Restore the original `N8N_ENCRYPTION_KEY`.
        - **Slow first load** — n8n downloads and indexes nodes on first start; subsequent loads are fast.
        - **Custom domain** — bind one via the template's *Domain* field, or add it later in **Service → Networking**.

        ## License

        n8n is licensed under the Sustainable Use License (fair-code). See [n8n.io/legal](https://n8n.io/legal/).
    resourceRequirement:
        minConfig:
            cpu: 1
            ram: 1
        recommendedConfig:
            cpu: 2
            ram: 2
    services:
        - name: n8n
          template: PREBUILT_V2
          spec:
            id: n8n
            source:
                image: n8nio/n8n:2.33.4
            ports:
                - id: web
                  port: 5678
                  type: HTTP
            volumes:
                - id: n8n-data
                  dir: /home/node/.n8n
            env:
                GENERIC_TIMEZONE:
                    default: UTC
                N8N_BASIC_AUTH_ACTIVE:
                    default: "false"
                N8N_ENCRYPTION_KEY:
                    default: ${PASSWORD}
                N8N_PORT:
                    default: "5678"
                NODE_ENV:
                    default: production
            init:
                - id: fix-volume-permissions
                  image: null
                  command:
                    - /bin/bash
                    - -c
                    - |
                      mkdir -p /home/node/.n8n
                      chown -R node:node /home/node/.n8n 2>/dev/null || chown -R 1000:1000 /home/node/.n8n 2>/dev/null || true
                  volumes: null
          domainKey: N8N_DOMAIN
