# Template file format

> Learn the fields in template.yaml and the substitution rules for manifests.yaml to write template files.

A template is installed per project and can be installed many times. A component, in contrast, is installed once for the whole cluster and used by every project.

A template consists of `template.yaml` and `manifests.yaml`. Define template information in `template.yaml`, and use the permitted field substitutions in `manifests.yaml`.

## template.yaml

The following is a minimal example. For the complete list of fields, see the [template schema](https://github.com/zeabur-oss/catalog/blob/v0.6.3/schema/v1/template.schema.json). For template requirements, see [Template standards](https://oss.zeabur.com/docs/catalog/reference/template-standards).

```yaml
apiVersion: catalog.zeabur.com/v1
kind: Template
metadata:
  name: PostgreSQL
  # renovate: depName=ghcr.io/cloudnative-pg/postgresql
  version: "18-standard-trixie"     # the tag of the main image in manifests.yaml
  summary: A PostgreSQL 18 database.
  locales:
    zh-TW: {summary: "PostgreSQL 18 資料庫。"}
    zh-CN: {summary: "PostgreSQL 18 数据库。"}
  license: PostgreSQL AND Apache-2.0
  # From n8n: each LicenseRef- id in license needs the URL of its text.
  # licenseUrls: {LicenseRef-n8n-sustainable-use: https://docs.n8n.io/sustainable-use-license/}
  homepage: https://www.postgresql.org/
  docs: https://www.postgresql.org/docs/18/   # upstream usage docs

requires: [{component: cloudnative-pg}]

services:                         # the workloads in manifests.yaml
  - name: postgresql
    podSecurity: restricted       # or baseline
    ports: [{name: postgresql, port: 5432}]
    resources: {requests: {cpu: 100m, memory: 256Mi}, limits: {cpu: "1", memory: 1Gi}}

inputs:
  - name: databaseName            # the person installing gives it
    label: Database name
    description: Name of the database to create.
    locales:
      zh-TW: {label: 資料庫名稱, description: "要建立的資料庫名稱。"}
      zh-CN: {label: 数据库名称, description: "要创建的数据库名称。"}
    required: true
    validation: {pattern: '^[a-z][a-z0-9_]{0,62}$'}
  # From n8n: the installer generates this value into a Secret.
  # - name: encryptionKey
  #   description: Deploy-time random secret; preserve it across upgrades.
  #   generate: {type: random, bytes: 32, encoding: base64url}
  #   secret: {name: n8n-secrets, key: encryption-key}
  #   validation: {pattern: '^[A-Za-z0-9_-]{43}$'}

security: {...}      # summary, risks with mitigations, unauthenticated services
smoke: []            # resource condition, then an HTTP or SQL check
```

## manifests.yaml

`manifests.yaml` supports only field substitution, with the following rules:

- The only permitted substitution fields are `{{ .Namespace }}`, `{{ .Domain }}`, `{{ .ClusterIssuer }}`, and `{{ .Inputs.<name> }}` for input values that aren't automatically generated.
- Conditions, functions, pipelines, and whitespace-trimming markers aren't permitted.
- Missing input values use `default`; without a `default`, the value is empty.
- When a template needs options, use input fields with a `default`.
- Rendered objects must reference a Secret and must not contain automatically generated values.

[How clients render templates](https://oss.zeabur.com/docs/catalog/reference/template-clients) gives the checks before rendering and the labels every object gets.
