Best Practices
Conventions for Polycrate workspaces and blocks: layout, one environment per workspace, naming rules, versions, security and logging.
This page collects the conventions that keep Polycrate workspaces and blocks clear, reproducible and secure across a team. The linked pages cover each concept in detail.
Organising workspaces
Location and layout
Keep workspaces under $HOME/.polycrate/workspaces/<organization>/<workspace>/. Scripts and colleagues then find every workspace in the same place, and you can refer to it with -w acme/acme-production-1.
acme-production-1/
├── workspace.poly
├── secrets.poly.age # encrypted secrets.poly
├── inventory.yml # exactly one inventory per workspace
├── CHANGELOG.poly
├── Dockerfile.poly # optional
├── blocks/
└── artifacts/
├── secrets/ # kubeconfig.yml.age, id_rsa.age, ...
└── blocks/
One environment, one workspace
Production, staging and development are separate workspaces with their own explicit values. .poly files do not evaluate environment variables or templates, so there is deliberately no way to switch environments through a variable.
# acme-production-1/workspace.poly
name: acme-production-1
organization: acme
blocks:
- name: app-db
from: cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg:1.8.7
config:
cluster:
enabled: true
instances: 3
acme-staging-1 contains the same block with instances: 1. Test new block versions in staging first, then pull them into production.
Inventory and kubeconfig
Each workspace has exactly one inventory and one kubeconfig:
- Ansible inventory:
inventory.ymlin the workspace root. - Kubeconfig:
artifacts/secrets/kubeconfig.yml(encrypted along with everything else bypolycrate workspace encrypt).
Polycrate hands both to every action run automatically. References such as kubeconfig.from or inventory.from on block instances are a legacy pattern and not needed in new workspaces. → Kubernetes · Artifacts
Literals instead of YAML anchors
YAML anchors (&/*) are read, but they are lost whenever Polycrate writes workspace.poly itself — for example during polycrate block pull or polycrate release finalize. Spell out repeated values explicitly.
Versioning
Version workspaces with Git (see Git) and record changes through workspace releases in CHANGELOG.poly (see Spec-Driven Development). The two are independent: a release creates no commits or tags.
Names
Slugs
Polycrate validates the following identifiers against the slug pattern ^[a-z][a-z0-9-]*$:
nameandorganizationinworkspace.poly- the
nameof every action - the
nameof every workflow and workflow step
A slug starts with a lowercase letter and then contains only lowercase letters, digits and hyphens.
| Examples | |
|---|---|
| Valid | acme, acme-production-1, install, deploy-platform |
| Invalid | _install, 123-test, Acme-Prod, my app, my_app |
For workspaces, use the pattern <org>-<purpose>-<number>, e.g. acme-production-1, acme-staging-1, acme-dev-1.
Block names
Block names are either local short names (my-app) or full registry paths (cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg). The directory under blocks/ matches the name: in block.poly (without tag). Name instances in workspace.poly after their role (app-db, ingress, monitoring) rather than after the template.
Blocks
- Pin versions: always use the full registry path and a fixed SemVer tag in
from:(cargo.ayedo.cloud/ayedo/k8s/cert-manager:0.10.2), never:latestin production. - One version per template: after
polycrate block pull, Polycrate updatesfrom:on every instance. Check the result withpolycrate validate workspace-poly ./workspace.poly. → Blocks - Override minimally: put only values that differ from the block defaults into
workspace.poly.polycrate hub inspect <block>:<version>shows the defaults,--examplesshows typical scenarios. - Reuse existing blocks: check the Hub for a suitable block before writing your own. Do not fork a registry block to change a single value — override it on the instance.
- Scope your own blocks: a Kubernetes application block wraps exactly one application. Databases and caches are separate blocks. Scaffold with
polycrate block init, read the conventions withpolycrate block manual --no-pager.
Actions and workflows
- Use the common action names (
install,upgrade,uninstall,backup,restore,status). - Write idempotent playbooks.
- Protect destructive actions with
prompt.message; in pipelines,--forceskips the prompt. - Model recurring sequences as workflows and set
allow_failureonly on workflows whose steps are all non-critical.
Security
- Sensitive values belong in
secrets.polyor underartifacts/secrets/, never in plain text inworkspace.poly. - Encrypt before every commit with
polycrate workspace encryptand keep the pre-commit hook enabled. → Workspace Encryption - Each workspace has its own SSH keys under
artifacts/secrets/id_rsa(generated byworkspace init). → SSH
Container
The image cargo.ayedo.cloud/library/polycrate:<version> is based on Debian. Extend it in Dockerfile.poly with apt-get and pin the base image to a fixed version. → The Polycrate Container
Logging
--loglevel |
Use |
|---|---|
0 |
CI, minimal output |
1 |
Default |
2 |
Troubleshooting individual actions |
3 |
Detailed trace |
polycrate --loglevel 2 run app-db install
Examples in this documentation
Generic examples use the fictitious organization acme, workspaces such as acme-production-1 and the sample registry registry.acme.corp. Block examples refer to real blocks from the Hub under cargo.ayedo.cloud/ayedo/….