Blocks

Blocks in Polycrate: template blocks and instances, inheritance via from:, dependencies and versions, and developing your own blocks.

A Polycrate workspace is built from blocks. A block bundles configuration defaults (block.poly), Ansible playbooks, templates, examples (examples.poly) and actions such as install or uninstall, which you run with polycrate run <block> <action>. Ready-made blocks for the Software Delivery Platform — from the Kubernetes cluster (k8s-1.27) to Cilium, cert-manager and CloudNativePG — are available from the Hub.

Template blocks and block instances

Polycrate distinguishes two roles:

  • Template block: a directory containing block.poly and playbooks under blocks/ — pulled from an OCI registry or developed locally. If the name contains slashes (e.g. cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg), Polycrate mirrors that structure under blocks/.
  • Block instance: an entry under blocks: in workspace.poly that points to a template block via from: and overrides only the values that differ in your environment.
# workspace.poly
name: acme-production-1
organization: acme

blocks:
  - name: k8s
    from: cargo.ayedo.cloud/ayedo/linux/k8s-1.27:0.3.24
    config:
      cluster_name: acme-production-1
      flannel:
        disabled: true
      kube_proxy:
        disabled: true
      ansible_host_groups:
        controlplane: k8s_controlplane
        worker: k8s_worker

  - name: cilium
    from: cargo.ayedo.cloud/ayedo/k8s/cilium:0.7.5
    config:
      kube_proxy_replacement: true
      k8s_service_host: 10.0.0.10   # control plane API address
      k8s_service_port: 6443
      hubble:
        enabled: true
polycrate run k8s install
polycrate run cilium install

Before adding a block, look up its options with polycrate hub inspect ayedo/k8s/cilium:<version> (defaults) and polycrate hub inspect ayedo/k8s/cilium:<version> --examples (ready-made scenarios).

Inheritance and merge behaviour

Polycrate deliberately supports exactly one level of inheritance: template block → block instance. from: belongs only on instances in workspace.poly, never in a block.poly. Multi-level chains do not exist.

An instance inherits from its template:

  • config, deep-merged in the order block.poly < workspace.poly < secrets.poly. Maps merge recursively, so only the keys you set change. Lists are replaced as a whole, not appended.
  • actions, which you can override or extend on the instance.
  • Working directory: playbooks and templates run relative to the template block's directory.

Taking the k8s instance above: cluster_name and flannel.disabled come from workspace.poly, while flannel.backend: vxlan and every other default (e.g. k3s.version) stays as defined in the template's block.poly. Inspect the resolved result without running anything via polycrate run k8s install --snapshot (see Snapshot).

An instance can replace individual actions or add new ones:

blocks:
  - name: my-app
    from: my-app-base            # local template block in blocks/my-app-base/
    actions:
      - name: install
        playbook: custom-install.yml   # replaces 'install'
      - name: migrate
        playbook: migrate.yml          # new action

Resolving dependencies and pulling blocks

Every from: is a dependency. Polycrate reads it as follows:

  • Short name without a registry host (from: my-app-base) → local block in blocks/my-app-base/.
  • Full registry path with tag (from: cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg:1.8.7) → OCI artifact in the registry.

Always pin remote blocks with the full path and a fixed SemVer tag — :latest makes runs non-reproducible.

When loading the workspace, Polycrate compares requested and locally installed versions. In an interactive terminal it shows a dialog with the status [MISSING] (not installed), [UPGRADE] (local version older) or [DOWNGRADE] (local version newer). In CI (CI=true) or with --non-interactive, the CLI exits instead and prints the pull commands you need.

# Pull a block at an explicit version
polycrate block pull cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg:1.8.7

# Pull missing blocks automatically before the run (requires a full registry path in from:)
polycrate run postgres install --blocks-auto-pull

For private registries, sign in first with docker login <registry>. Registries, proxying and pushing are covered in Registry & Hub.

One version per template block

A registry template block exists in a workspace in exactly one version. All instances of that template share it. CloudNativePG is a typical case, where both the operator and a database cluster are instances of the same block:

blocks:
  - name: cnpg-operator
    from: cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg:1.8.7
    config:
      operator:
        enabled: true

  - name: app-db
    from: cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg:1.8.7
    config:
      namespace: app
      cluster:
        enabled: true
        instances: 3
        storage:
          size: 20Gi

To upgrade, run polycrate block pull <path>:<new-version>. Polycrate replaces the template under blocks/ and rewrites the from: tag of every matching instance in workspace.poly. Then validate and roll out the instances one by one:

polycrate block pull cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg:<new-version>
polycrate validate workspace-poly ./workspace.poly
polycrate run cnpg-operator install
polycrate run app-db install

To run two versions of the same block side by side (for a canary upgrade, say), use separate workspaces such as acme-staging-1 ahead of acme-production-1.

Developing your own blocks

Create a new block with polycrate block init. The scaffold includes block.poly, CHANGELOG.poly, README.md, examples.poly and matching playbooks. A short name is expanded to the full registry path {registry}/{org}/{category}/{name}.

# Kubernetes application block (default: --kind k8sapp)
polycrate block init my-app

# Minimal generic block, e.g. for Linux tasks
polycrate block init my-helper --kind generic

# With a full registry path
polycrate block init registry.acme.corp/acme/k8s/my-app

The CLI prints the binding conventions for block authors (playbook layout, automatic kubeconfig, labels, validation): polycrate block manual --no-pager.

Directory layout

blocks/registry.acme.corp/acme/k8s/my-app/
├── block.poly        # configuration and actions (required)
├── CHANGELOG.poly    # version history (required for push)
├── examples.poly     # configuration examples (required for push)
├── README.md
├── install.yml       # Ansible playbook
├── uninstall.yml
└── templates/
    └── values.yaml.j2

block.poly

name: registry.acme.corp/acme/k8s/my-app
display_name: "ACME Web App"
description: "Internal web application on Kubernetes"
version: 1.2.0
app_version: "4.1.0"
kind: k8sapp

config:
  namespace: my-app
  replicas: 2

actions:
  - name: install
    playbook: install.yml
  - name: uninstall
    playbook: uninstall.yml
    prompt:
      message: "Really remove my-app?"

Key metadata:

Field Meaning
name Technical name; for registry blocks the full path without tag
display_name, description Title and short description for the Hub and CLI
version SemVer version of the block logic
app_version Version of the installed upstream application
kind k8sapp, k8scluster, linuxapp, dockerapp, library or generic
type, flavor, implementation Functional classification, e.g. db-provider / postgres / cnpg
license, website_url, documentation_url Upstream references

examples.poly

examples.poly documents named configurations that users can copy as-is. A block cannot be pushed without it:

# examples.poly
single-replica:
  config:
    namespace: my-app
    replicas: 1

ha:
  config:
    namespace: my-app
    replicas: 3
polycrate block examples my-app --no-pager

Versioning and publishing

Do not edit CHANGELOG.poly entries or the version: in block.poly by hand — use the block release (polycrate release --block <name> update followed by polycrate release block-finalize). block-finalize sets the version and pushes the block to the registry. On push, Polycrate checks that the name is a full registry path, that CHANGELOG.poly has an entry for the version and that examples.poly contains at least one example. The flow is described in Spec-Driven Development.

Useful block commands

Command Purpose
polycrate block list List the blocks in the workspace
polycrate block inspect <block> Show the resolved block
polycrate block readme <block> Show the README
polycrate block examples <block> Show examples.poly
polycrate block changelog <block> Show CHANGELOG.poly
polycrate block validate <block> Check structure and configuration
polycrate block verify <block> Compare local content with the registry image (--diff lists differences)
polycrate block pull <path>:<version> Pull a block and update from: on all instances
polycrate block manual --no-pager Cookbook for block authors

polycrate block and polycrate blocks are interchangeable.

See also