Component contracts (piceli.toml)¶
Maturity: preview (the API may change before 1.0).
The main way to compose repositories is in Python, in the composition
repository: a Pipeline per environment and a host build whose contexts
read the other repositories (see Compositions in Python). This page is the
optional alternative for simple components: each repository describes
its own components in a piceli.toml, and the composition only places them.
A composition deploys components that live in several Git repositories.
Each repository says how its components are built and run, in a
piceli.toml at its root (the component contract); a separate module,
usually infra.py in its own repository, says where they run and when
they deploy. A push to a component repository deploys by the composition’s
rules, and only the components whose files changed are rebuilt and rolled.
shop repo catalog repo infra repo
├── piceli.toml ├── piceli.toml └── infra.py
├── web/ … └── catalog/ … Source, Component, Stack,
└── api/ … Environment, Cluster
The example in examples/composition/ is this layout: shop/ and
catalog/ are the contents of the two component repositories, infra.py the
composition. The kind test tests/integration/test_composition_kind.py runs
it end to end.
The composition module¶
from piceli.envs import Branches, Environment, Stack, Tag
from piceli.infra import Cluster, Component, Source
from piceli.pipeline import Registry
cluster = Cluster(
"my-cluster",
api="https://10.0.0.10:6443",
credentials="my-cluster",
registry=Registry.in_cluster(on="node-a", repository="shop"),
)
shop = Source("https://git.example.com/team/shop.git") # name "shop"
catalog = Source("git@git.example.com:team/catalog.git")
web = Component("web", source=shop, settings={"greeting": "hi"})
api = Component("api", source=shop)
items = Component("catalog", source=catalog)
cache = Component.image(
"docker.io/library/redis:7.2",
pin="sha256:<64 hex>",
name="cache",
contract={"ports": {"redis": 6379}, "health": {"ready": "TCP redis"}},
)
full = Stack("full", [web, api, items, cache])
small = Stack("small", [web, items])
environments = [
Environment(
"main",
namespace="shop-main",
stack=full,
cluster=cluster,
follow={shop: "main", catalog: "main"},
auto_approve=True,
),
Environment(
"rc",
namespace="shop-rc",
stack=full,
cluster=cluster,
follow={shop: Tag("v*-rc*"), catalog: Tag("v*")},
),
Environment.per_branch(
Branches("wp-*"),
namespace="shop-{branch}",
stack=small,
cluster=cluster,
follow={shop: "{branch}", catalog: "main"},
on_nodes=["node-b"],
limit=2,
idle_stop="24h",
auto_approve=True,
),
]
Source(url, name=None, records=()): a Git repository; its name defaults to the repository name of the URL. Never put credentials in the URL: every source is fetched with one Git Secret (--credentials-secretofgitops enable, and the build Job’spiceli-build-git).records(0.99.0): paths whose pushes start no run, see Records-only commits (0.99.0).Component(name, source=…, settings={…}): the contract is the[component.<name>]table of the source’spiceli.tomlat the commit the environment deploys, so a contract change ships with the code.settingsoverride the contract’s.Component.image(ref, pin="sha256:…", name=…, contract={…}): a third-party image. The controller copiesref@pininto the in-cluster registry when it syncs; nodes pull it from there, never from a hosted registry at run time.contracttakes the keys below exceptbuild(andimage.base/image.dirs).Stack(name, [components]): the components an environment runs (an environment without a stack runs every component).stack.componentslists them.Environment(name, namespace=…, follow={Source: rule}, stack=…, cluster=…, on_nodes=…, quota=…, auto_approve=…, secrets=[…], settings={component: {key: value}}): a named environment. A rule is a branch name ("main", orBranch("main"): every push),Tag("v*")(the latest matching tag; a new one deploys),Promote()(piceli promote ENV BRANCH@SHA), or a list of them. The environment follows every source its components come from (composition-invalidotherwise).Environment.per_branch(Branches("wp-*", fallback="main"), namespace="<prefix>{branch}", follow={…}, …): one environment per branch of the sources that follow"{branch}"; a source that follows"{branch}"but lacks the branch deploysfallback. It takesstack,on_nodes(since 0.20.0 not applied to DaemonSets: a node agent runs on every node its ownnode_selectorallows),quota,limit(at most this many run),idle_stop,claim_sizes,allow_egress,auto_approve,secretsandsettings(theEnvConfigfields of the same meaning). The environment is removed with its branch.Optional
name = "shop": the app name of everything deployed (default: the module file’s stem).
A single-source Environment(follow=Branch("main")) in an EnvConfig keeps
its 0.14 meaning; the new fields change no existing plan hash.
The piceli.toml format¶
[component.api]
build = { rust = "crates/api", bin = "api", page_size = "from node" }
image = { base = "docker.io/library/debian@sha256:<64 hex>", user = 10001, dirs = { "/var/lib/api" = "0700" } }
ports = { http = 18080, graph-tls = 18443 }
health = { ready = "GET /health", check = ["api", "check-config"] }
upgrade_check = ["api", "store", "verify", "--read-only", "/var/lib/api"]
volumes = { data = { path = "/var/lib/api", size = "8Gi", retained = true } }
needs = ["cache?", "secret:api-token", "component:db"]
settings = { memory_soft_limit = "auto", retention = "default" }
emits = ["otlp:metrics", "otlp:logs"]
Only [component.<name>] tables are allowed, and only these keys: any other
key, a bad value or an unpinned base is refused with
component-contract-invalid. A component the environment runs that has no
table at the deployed commit is component-contract-missing.
Key |
Meaning |
|---|---|
|
Exactly one recipe (below). Required, except for |
|
|
|
|
|
|
|
A command run in the new image with the workload’s settings before it rolls out (a pre-rollout check, see Pre-rollout checks). |
|
A command run in the new image with the retained volumes mounted read-only before it rolls out (the pre-rollout upgrade check). Needs a retained volume. |
|
|
|
|
|
|
|
Informational ( |
Build recipes¶
Builds are host builds (Builds without a VM): no container VM, a staged context of exactly the files the build reads, the image assembled as OCI layers on the pinned base.
Recipe |
Keys |
What runs |
|---|---|---|
|
|
|
|
|
The package at |
|
|
The files and directories at their image paths, nothing compiled. |
|
|
Accepted in the contract; it needs a Docker engine, so the controller and its build Job refuse it ( |
paths lists what the build reads, relative to the repository root. The
default: rust the crate, Cargo.toml and Cargo.lock; python the
package directory; files the listed sources; dockerfile the context. List
the other crates of a workspace a binary depends on.
Change-aware builds¶
Each component has a source digest: a hash of its build and image
tables and of the Git object id of each of its paths at the deployed
commit. Two commits that leave those untouched give the same digest, so:
the controller builds a component only when no image exists for its digest (images are kept per digest on the controller’s volume), and mirrors a
Component.imageonce perref@pin;the environment is rendered with every component’s image; a component whose image did not change renders the same objects and applies as a no-op, so only changed components roll.
settings, ports or health changes need no rebuild: they change only
the rendered objects. piceli gitops sync ENV --component NAME rebuilds one
component even when its digest has an image.
Deploying a composition¶
piceli login my-cluster --kubeconfig ~/my-cluster.yaml # once per machine
piceli registry install … # the in-cluster registry
piceli gitops enable infra.py --image REPO@sha256:… \
--credentials-secret git-token --builder-image REPO@sha256:… # plan, then --approve HASH
piceli gitops status
piceli gitops sync main --component web
piceli promote rc main@abc1234 # when rc follows Promote()
gitops enable infra.py imports the module on your machine and puts its
plain-data form (sources, components, environments, the registry; never
credentials) into the controller’s config, so the install plan hash covers
every rule; the controller never imports your code. Change the module and
run gitops enable again. Without --kubeconfig it uses the cluster’s
credentials profile.
The controller (see GitOps: Piceli’s controller and manifest export) polls every source with git ls-remote,
resolves each environment’s follow to one commit per source (its
revision), and deploys an environment when a followed branch moved, a
new matching tag appeared (tags present at the first poll are the baseline),
on promote or on sync. It reads the contracts at the revision, checks
the needs, builds only changed components in one build Job on the
builder node (it fetches every source it needs at its commit, with the one
Git Secret, and pushes to the in-cluster registry), renders the environment
and applies it with the environment’s approval (auto_approve=True and the
default approval policy: creates and updates; otherwise piceli gitops approve ENV HASH). Without --builder-image the controller mirrors
third-party images but cannot build. piceli gitops run --once --local-build --kubeconfig F --context C --config config.json --state-dir DIR runs one
poll on your machine instead, building with the local host tools and
pushing through a port-forward to the registry. Since 0.22.0 it builds
every platform the controller is enabled with, like the build Job and build
hosts (another architecture cross-compiles: a Rust build with cargo zigbuild), and pushes one OCI index per image over them; with one platform
it pushes that platform’s image alone, as before.
Records-only commits (0.99.0)¶
Some pushes change only records: release signatures, build records and the like. They change nothing an environment runs, yet each one used to start a full run. Declare those paths on the source:
hosts = Source(
"https://git.example.org/org/hosts.git",
records=["config/release-signatures/**", "config/build-record.json"],
)
Each entry is a glob of repository paths, relative to the repository root (no leading
/, no..).*matches within one path segment,**any number of segments (config/**is everything belowconfig), and a pattern ending in/is a directory.When a followed branch moves forward (the old head is in the history of the new one) and every changed path matches, the move starts no run. The controller logs
ENV: push SOURCE/BRANCH touches records only (N files); no run.Anything else still runs as before: a push that also changes another path, a forced push, the first sight of a branch, a tag, a
sync, a push to another source in the same poll, or a Git error while comparing.The commit counts as verified as the commit the environment last ran (its base), so a promotion gate (
Promotion, A promotion gate and piceli promote (0.25.0)) accepts it without a new run.In a composition that follows its own repository, a
Sourcewith the repository’s URL gives itsrecordsto that repository too. A records-only push still reloads the composition module; it only starts no run.
Caution. A path that the composition module, a build or a component reads at run time is not a record: a change to it would not be deployed until the next real push.
Status¶
The status (piceli gitops status --json, ConfigMap piceli-gitops-status,
schema piceli.gitops-status.v1) gains, for a composition controller:
sources.<name>:url,refs({"refs/heads/main": sha, "refs/tags/v1.0.0": sha}, the followed ones) andlast_poll(error, a code, when the lastls-remotefailed);recordswhen the source declares them (0.99.0);envs.<env>.revision:{source: sha},refs:{source: ref}, andlast_sync: when it last finished deploying;records_only_last(0.99.0): the last records-only push,{source, commit, base, files};envs.<env>.components.<name>:source,commit,digest(the image’s manifest digest),source_digest(the build cache key),image,state(building,rolling,synced,unchanged,failed),healthandupdated_at;controller.composition(its name) andcontroller.environments.
The other keys are those of a single-repository controller; an environment is keyed by its name (a branch environment by its branch).
Not yet¶
Stack(extra=…), component variants and replica pairs are not modelled: declare a second component inpiceli.tomlinstead.Branch environments of a composition are not seeded from restore points.
A
dockerfilebuild needs a Docker engine (component-build-unsupported).The deployed image is the first build platform’s (
--platform); nodes of another architecture need their own environment.