Containerized builds¶
Maturity: preview
The piceli.build-spec.v1 format and the receipt may still change in a minor release, with a changelog entry. See the Roadmap for every feature’s status.
A build.toml describes a build that runs inside a pinned builder image with
docker buildx. Piceli stages the declared inputs, runs the build, extracts
the declared outputs and writes a build receipt. The receipt ties the
output digests to the builder digest and to the git identity of every source
(see Source identity).
To build without a container engine (no Docker Desktop VM on macOS), with the host toolchain and the target node’s facts, see Builds without a VM.
piceli artifacts build-spec preview --spec build.toml
piceli artifacts build-spec run --spec build.toml \
--approve-builder sha256:<builder digest> --out dist/receipt.json
A complete example that builds a small Rust HTTP service for linux/arm64
is in examples/builds/rust-hello/.
Maturity by feature
Feature |
Maturity |
|---|---|
Spec, minimal contexts, pinned builder, receipt |
preview: the receipt fields are a contract; new fields may be added |
Drift checked over the staged files (Drift: what is checked and what is recorded) |
preview (new in this release) |
Streaming |
preview (new); the progress line format is for people, not parsers |
Tag templates |
preview (new) |
Smoke checks (Smoke checks) |
experimental: the isolation flags and limits may change; |
The spec¶
revision = "piceli.build-spec.v1"
name = "rust-hello"
inputs = "inputs.toml" # optional: sources to identify (WP1b.1)
[builder] # the image the build runs in, by digest
image = "docker.io/library/rust:1.97.0-bookworm"
digest = "sha256:8fa55b2f..."
[build]
platforms = ["linux/arm64"] # one or more linux/<arch>
workdir = "/work"
commands = [ # or one `command = [...]`
["cargo", "clean", "--release", "--locked", "--offline", "--package", "rust-hello"],
["cargo", "build", "--release", "--locked", "--offline"],
]
network = "none" # "none" (default) or "default"
source_date_epoch = 0 # default 0; image metadata and output times only
timeout_seconds = 1800 # per docker invocation, at most 3600
env = { CARGO_TERM_COLOR = "never" }
# buildx_builder = "default" # default: the builder of the current docker context
[context.app] # a named build context
source = "piceli" # optional: a source from inputs.toml
path = "examples/builds/rust-hello" # relative to the source (or to this file)
include = ["Cargo.toml", "Cargo.lock", "src/**/*.rs"]
exclude = [] # optional
target = "/work" # where it lands in the builder (default: workdir)
max_files = 64 # default 10000
max_bytes = 1048576 # default 64 MiB
[cache.cargo-registry] # a BuildKit cache mount, never a context
target = "/usr/local/cargo/registry"
id = "cargo-registry" # optional: share across specs
sharing = "shared" # locked (default), shared or private
[cache.target]
target = "/work/target" # default id: piceli-<name>-<cache>-<platform>
[[output.file]] # a file extracted from the build
from = "target/release/rust-hello" # relative to workdir, or absolute
to = "bin/rust-hello"
[[output.image]] # an image loaded into the local engine
name = "rust-hello"
repository = "piceli-examples/rust-hello"
tag = "{image_id:12}" # or a literal such as "dev"; see "Image tags"
base = { image = "docker.io/library/debian:bookworm-slim", digest = "sha256:8820..." }
files = { "bin/rust-hello" = "/usr/local/bin/rust-hello" }
user = "65532:65532"
entrypoint = ["/usr/local/bin/rust-hello"]
# cmd = [...], workdir = "/..."; base may be "scratch"
smoke = { command = ["--self-test"], expect_exit = 0, timeout_seconds = 60 } # optional
Unknown fields are errors. Every image reference must carry a digest.
With several platforms, each image is built once per platform; piceli artifacts publish joins them in one multi-platform image (see
Publish images for other people’s clusters).
What Piceli generates¶
With command/commands, Piceli writes the whole Dockerfile:
FROM <builder>@<digest> AS piceli-build, thenCOPY --from=<context>for each context.One
RUNwith--network=<network>and every cache mount. It runs the commands and then copies each declared output out of the tree. This happens in the same step because a cache-mounted path such astarget/is only visible while its mount exists. The step runs/bin/sh -euc <script>, and every argument is quoted withshlex. The builder image must therefore provide/bin/sh,cpandtouch. The host never runs a shell.A
scratchstagepiceli-fileswith only the declared files. It is exported with--output type=local.One stage per
output.image: the pinned base plus the declared files at their final paths.
The preview shows the rendered Dockerfile and its digest.
Bringing your own Dockerfile¶
[build]
platforms = ["linux/arm64"]
dockerfile = "Containerfile" # a file inside the `context` context
context = "app" # the main (positional) context
builder_arg = "RUST_IMAGE" # receives builder.image@builder.digest
args = { PROFILE = "release" } # plain build args
[images.PYTHON_IMAGE] # extra pinned images passed as build args
image = "docker.io/library/python:3.12-slim"
digest = "sha256:..."
[[output.file]]
stage = "build"
from = "/src/target/release/app"
to = "bin/app"
[[output.image]]
name = "app"
repository = "example/app"
tag = "dev"
target = "runtime"
The Dockerfile must build FROM ${RUST_IMAGE}. Every FROM,
COPY --from and RUN --mount=...,from= must refer to one of these:
a stage
a declared context
scratchan
image@sha256:literala pinned build arg
Piceli rejects # syntax= directives, because they fetch a frontend image,
and remote ADD. Declare caches with RUN --mount=type=cache in the
Dockerfile itself. The pin check is a guardrail against drift, not a sandbox.
Contexts are minimal by construction¶
BuildKit applies .dockerignore only to the main context. A named context
(--build-context name=dir) sends the whole directory, including every
virtualenv and target/ tree below it. Piceli never passes one of your
directories to BuildKit. For each context, it does the following:
It walks the declared directory and selects only files that match
includeand notexclude.*and?match within one path component, and**matches across components. Patterns select files; usedir/**to select a whole subtree.It never enters
.git,target,.venv,venv,node_modules,__pycache__,.cargo,.rustupor the tool caches, unless a pattern names that directory literally (for exampletarget/release/app). A**pattern does not count as naming it.It never stages private paths:
.git,.ssh,.env*,*.key,*.pemandsecrets. It never follows symbolic links, and a link that matches a pattern is an error.It enforces
max_filesandmax_byteswhile scanning.It copies exactly those files into a private temporary directory. Each file is re-hashed as it is copied, and a file that changed since the plan fails the build with
context-changed. Staged files get mode 0644 or 0755 and a modification time derived from their content hash (see below); staged directories get thesource_date_epochtime.
The preview and the receipt report each context’s file count, bytes, digest,
pruned directories and skipped private files and links. The rust-hello
context is 3 files and 2,519 bytes.
Dependency caches such as the Cargo registry, Cargo git checkouts or a
target/ directory are BuildKit cache mounts. They persist in the builder
between builds and are never uploaded. Do not ship ~/.cargo as a context.
An offline build (network = "none") needs its dependencies already in the
cache. Either run once with network = "default" and --allow-network, or
vendor the dependencies into the context.
Cached build outputs and content-derived mtimes. Each staged file’s
modification time is a pure function of its content hash: the same content
always gets the same time, and an edit of any size (including one that keeps
the byte count) gets a different one. The times fall in a window from
2035-08 to 2038-01, later than anything a build cache holds today, so a tool
that decides freshness by mtime, such as Cargo on a cached target/, sees
every changed file as newer than its old output and recompiles it. Two
different contents share a time with probability about 1 in 6.7e7. You no
longer bump source_date_epoch after a source edit; it only fixes the image
metadata and the times of collected outputs.
The trade-off: every staged file is newer than any cached output, so a tool
that compares mtimes also recompiles the packages built from the context
when nothing changed. Dependencies in a cached registry stay cached. The
rust-hello example still runs cargo clean --release --package rust-hello
before cargo build so that its intent is explicit.
Running¶
Python API:
import time
from pathlib import Path
from piceli.artifacts import BuildGrant, BuildSpec
spec = BuildSpec.from_toml(Path("build.toml"))
plan = spec.plan() # reads files, writes nothing, runs nothing
print(plan.preview())
receipt = spec.run(
BuildGrant(spec.builder.digest, time.time() + 3600, plan_hash=plan.plan_hash),
Path("dist"),
)
Path("dist/receipt.json").write_text(receipt.to_json())
run refuses to start unless the grant covers the following:
The exact builder digest. Changing the builder needs a new approval.
The exact plan hash, if one is given. The hash covers the spec, context digests, rendered Dockerfiles and argv.
Network, if the spec needs it (
allow_network).An expiry that has not passed.
During a run, Piceli does the following:
It records the inputs from Source identity, or verifies them against
--lock(source-driftif they differ). A dirty source withoutallow_dirtyis rejected withsource-identity. From then on the build is judged by the files it staged, not by the whole checkout; see Drift: what is checked and what is recorded.It pins the
dockerbinary by SHA-256 and re-verifies it around every call.It runs
dockerwith explicit argv, without a shell, with bounded time and output. The environment is minimal:HOME,DOCKER_CONFIG,DOCKER_CONTEXT,DOCKER_HOSTand the TLS locators, plus aPATHmade of the docker binary’s own directory and the system default.It builds each platform with
docker buildx build --platform <p> --provenance=false --sbom=false --network=<n> --build-arg SOURCE_DATE_EPOCH=<n>. There is one invocation for the files and one per image (--load --tag). The receipt records which platforms were native and which were emulated.It verifies that the extracted files are exactly the declared ones: regular files, within budget, none missing and none extra. It verifies that each loaded image has the expected platform and the config digest BuildKit reported. A templated tag is resolved (Image tags).
It runs each image’s smoke check, if one is declared (Smoke checks).
It re-hashes every staged file and re-reads the spec (Drift: what is checked and what is recorded). Only then are the files published atomically into the output directory and the receipt written.
Build output never goes into the receipt. Pass --log FILE to keep it; it is
written while the build runs (Build log and progress).
Drift: what is checked and what is recorded¶
A long build must not be invalidated by edits to files it never read, and must not be accepted if a file it did read changed underneath it. Piceli therefore separates the two:
Checked (fails the build) |
Recorded (provenance only) |
|
|---|---|---|
What |
The content digest, size and executable bit of every staged file of every context, including a user |
The git identity of each whole source at the start ( |
When |
Each file is hashed at plan time, re-hashed while staged, and re-hashed after the last build step and smoke check. |
At the start, and once more at the end. |
On a difference |
|
The source’s name is listed in |
So, in a busy checkout declared with allow_dirty = true:
editing a Makefile, docs, or any file outside the contexts’ staged set during the build is recorded, never rejected;
editing, deleting or
chmod-ing a staged file is rejected, even if the context has nosource;adding a new file that matches an
includepattern is not drift: it was not staged, so the build did not consume it;editing a comment in
build.tomlis not drift; changing a declared value is.
A --lock is still compared with the whole source at the start: it
states what the operator approved. Use piceli inputs verify --only NAME to
check one source before a build.
Build log and progress¶
--log FILE is appended to while the build runs: complete lines, flushed as
they arrive, so tail -f FILE follows a long compile. A partial line is
written when its step ends. Each run starts with ### run <name> <time>, and
each step is framed by ### <platform> <kind> started and
### <platform> <kind> <state> <seconds>s. The file is created with mode
0600 because build output can contain anything the build printed. It never
goes into the receipt or the JSON result.
On stderr, --progress chooses what you see while the build runs:
|
stderr during the build |
|---|---|
|
One line when each step starts and ends, e.g. |
|
The step lines plus the raw build output as it arrives. |
|
Nothing until the result. |
The machine-readable result is always the one JSON object on stdout: the
receipt on success, or {"state": "failed" | "rejected", "reason": "<code>", "message": "…", "steps": […]} on failure. stderr is human text only (progress
and a summary). Before 0.4.0 the failure object was the last stderr line.
In Python, pass log=Path(...), progress=callable(str) and
raw_output=callable(bytes) to BuildSpec.run.
Smoke checks¶
An image output may declare a check that runs after the image is built:
smoke = { command = ["--self-test"], expect_exit = 0, timeout_seconds = 60 }
A server that prints its version, checked by its output:
smoke = { command = ["--version"], expect_stdout = '^api \d+\.\d+\.\d+$' }
A shell-entrypoint image whose self-test needs an environment variable:
[output.image.smoke]
entrypoint = ["/bin/sh", "-c"]
command = ['test "$APP_MODE" = self-test && echo ok']
env = { APP_MODE = "self-test" }
expect_stdout = "^ok$"
Field |
Meaning |
|---|---|
|
Arguments after the image, so they replace |
|
The exit code that passes, 0 to 255 (default 0). A check such as “starts and fails only at a declared later step” expects that step’s code. |
|
At most 600 (default 60). |
|
Optional. Plain environment values for the check, at most 64. Names are |
|
Optional. Replaces the image’s entrypoint (a non-empty list). As with |
|
Optional. A Python regular expression (1 to 1024 characters) that must be found ( |
It runs once per platform as
docker run --rm --name piceli-smoke-<nonce>-<n> --pull never --platform <p> --network none --read-only --tmpfs /tmp:rw,nosuid,nodev,noexec,size=64m --cap-drop ALL --security-opt no-new-privileges --pids-limit 256 --memory 512m [--env=NAME=value ...] [--entrypoint=<entrypoint[0]>] <image_id> [<entrypoint[1:]>...] <command...>, as the image’s own user. env and
entrypoint only add options; the isolation flags are the same with or without
them. It references the image by ID, so no tag and no registry are involved.
An emulated platform needs a binfmt handler on the engine.
The step is recorded in steps as kind = "smoke:<name>"; its output goes to
the log only. A different exit code fails the run with smoke-failed, and a
timeout with smoke-timed-out (the container is then removed). When the exit
code matches but an expect_stdout/expect_stderr pattern is not found, the
run fails with smoke-output-mismatch: the failed step lists the streams in
unmatched (for example ["stdout"]), and stderr and the build log show a
short, escaped excerpt of the start of each unmatched stream (never the JSON
result, the error message or a receipt). Either way no file is published and
no receipt is written. The image itself stays loaded, so you can inspect it.
Smoke env is not secret. The whole smoke table, env included, is part of
the spec digest and the plan hash (changing it changes the plan you approve),
and it is printed by preview and recorded in the receipt under smoke. Give
the check a plain value or a self-test mode that needs no credentials. A value
that looks like a reference to secret material (secret://…, vault://…,
op://…, secret:… and similar store schemes) is refused with
smoke-env-secret; the error names the variable, never the value.
The same check is available in the Python pipeline API as
Build.dockerfile(..., smoke={"api": Smoke(["--version"], expect_stdout=r"^api \d+")})
(see Deploy an app from source).
CLI¶
Command |
Purpose |
|---|---|
|
Print the plan as JSON: contexts, Dockerfiles, argv, |
|
Build and write the receipt to |
run also accepts the following options:
--inputsand--lock: identify sources, or verify them against a lock.--approve-plan: require an exact plan hash.--allow-network: grant network access to the build.--dockertogether with--docker-sha256: use a pinned docker binary. Without them, Piceli usesdockerfromPATHand records its digest.--log: stream the build output to a file (Build log and progress).--progress steps|plain|quiet: what stderr shows during the build.--max-seconds: the grant lifetime.
Exit codes: 0 success, 1 a build step or smoke check failed or timed out
(stderr lists the steps, never their output), 2 rejected. stdout is
{"state": "failed" | "rejected", "reason": "<code>", "message": "…"} with a
fixed code (each is explained in Error codes and by
piceli explain <code>); message is the code’s title. Paths are never
echoed.
Code |
Exit |
Cause |
Fix |
|---|---|---|---|
|
2 |
The spec is malformed: unknown field, bad value, bad tag template or smoke table. |
Correct |
|
2 |
|
Check the path. |
|
2 |
The declaration in |
Rebuild; do not edit declared values while a build runs. |
|
2 |
|
Pass |
|
2 |
|
Review the builder and approve its digest. |
|
2 |
|
Re-run |
|
2 |
|
Grant network, or build offline. |
|
2 |
The grant expired before or during the build. |
Raise |
|
2 |
Only one of |
Give both, or neither. |
|
2 |
A context directory is missing or unreadable. |
Fix |
|
2 |
|
Fix the patterns. |
|
2 |
A pattern matches a symbolic link. |
Exclude it or copy the file. |
|
2 |
More than |
Narrow |
|
2 |
A staged file changed, vanished or changed mode between plan, staging and the end of the build. |
Rebuild once the files are stable. Edits elsewhere are not drift. |
|
2 |
A user Dockerfile references an unpinned image or a remote |
Pin it by digest or pass it as a pinned arg. |
|
2 |
The sources differ from |
Re-record the lock, or restore the sources. |
|
2 |
A source is not a git root, has no commit, misses its |
Fix the checkout or |
|
2 |
|
Fix the file. |
|
2 |
|
Install docker/buildx; check the context. |
|
2 |
Extracted files are missing, extra, not regular or too large. |
Fix |
|
2 |
The loaded image cannot be inspected, has another platform, or differs from what BuildKit reported. |
Rebuild; check for a concurrent build of the same tag. |
|
2 |
The run was cancelled (Python API). |
— |
|
1 |
A |
Read |
|
1 |
A step exceeded |
Raise |
|
1 |
A smoke check exited with another code than |
Read |
|
1 |
A smoke check exceeded its |
Fix the image or raise the timeout (at most 600). |
|
1 |
A smoke check exited as expected, but |
Read the excerpt on stderr or |
|
2 |
A smoke |
Use a plain, non-secret value. |
|
2 |
Any other unreadable or malformed input (the detail is withheld so no path or output leaks). |
Run |
Receipt schema (piceli.build-receipt.v1)¶
Field |
Meaning |
|---|---|
|
|
|
Digest of the normalized spec (not of the file’s bytes). |
|
Digest of the spec, context digests, Dockerfiles and argv. |
|
|
|
Other pinned images ( |
|
The built platforms, e.g. |
|
The engine’s platform and the platforms built under emulation. |
|
|
|
Names of sources whose whole-checkout identity differed at the end ( |
|
Digest of the inputs declaration, or |
|
Per context: |
|
Per platform: digest of the Dockerfile that was built. |
|
As built. |
|
|
|
|
|
|
|
Only when an image declares one: |
|
Per invocation and smoke check: |
|
|
A receipt from the rust-hello example (abridged):
{
"revision": "piceli.build-receipt.v1",
"spec_sha256": "sha256:dbf9f2dba0e048410535dd479a67932fe65ab0666089576ba1919e9b305694db",
"builder": {
"image": "docker.io/library/rust:1.97.0-bookworm",
"digest": "sha256:8fa55b2f3ddf97471ab6a767bfa3f37e6bad0986ba823e75fea57e2a2a5c3073",
"platform_manifests": {"linux/arm64": "sha256:b9e35fea1df440fc548fe293354d8dd74b2a762b117752c7471df8b3f25ee872"}
},
"platforms": ["linux/arm64"],
"native_platform": "linux/arm64",
"sources": [{
"name": "piceli", "repository": "piceli", "subpath": "examples/builds/rust-hello",
"commit": "fcc01a17dd08dff73b2b31ae64c2720dc09850a5", "dirty": true,
"diff_sha256": "sha256:39bad9a9...", "changed_paths": 5, "...": "..."
}],
"contexts": {"app": {"files": 3, "bytes": 2519, "sha256": "sha256:65745046..."}},
"outputs": {
"files": {"bin/rust-hello": "sha256:bc297a0476d30d539e56c0ef6818640f14528f272f2406195836cddd421a5aa4"},
"images": {"rust-hello": {
"image_id": "sha256:b6d80dd1d0360f7d6aebfb1d950ba674f896f91c03a2149a29b9ea140df96f58",
"digest": null, "platform": "linux/arm64", "ref": "piceli-examples/rust-hello:b6d80dd1d036"
}}
},
"sources_changed_during_build": [],
"steps": [
{"platform": "linux/arm64", "kind": "files", "state": "succeeded", "exit_code": 0, "seconds": 0.602},
{"platform": "linux/arm64", "kind": "image:rust-hello", "state": "succeeded", "exit_code": 0, "seconds": 1.002},
{"platform": "linux/arm64", "kind": "smoke:rust-hello", "state": "succeeded", "exit_code": 0, "seconds": 0.654}
],
"started_at": "2026-09-24T17:06:49Z",
"finished_at": "2026-09-24T17:06:50Z"
}
Reproducibility¶
Rebuilding the same spec gives the same output digests:
Files. The file digest is the same with a warm cache. It is also the same after
--no-cachewith an emptytarget/cache, as long as the compiler output is deterministic.rust-hellosetscodegen-units = 1andstrip = true, and builds in a fixed/work.Images. The image ID is the same with a warm cache, and after a
--no-cacherebuild. The following choices make this work:SOURCE_DATE_EPOCHfixes the config and history timestamps.The build step lays each image’s files out at their final paths and sets every entry, directories included, to the epoch.
The image stage copies that tree into the base in one layer.
Without the last two steps, the layer records the build-time modification time of existing parent directories such as
/usr/local/bin. Older BuildKit (before 0.13) cannot rewrite those timestamps.The manifest digest. It depends on the exporter. Docker’s classic store keeps no manifest (
digest: null). An OCI or registry export would add a compressed manifest whose digest depends on the compression settings. Compareimage_idvalues, not manifest digests, across engines.Your own Dockerfile. You are responsible for the timestamps in your own stages.
Measured on an arm64 Mac (Docker Desktop, buildx 0.11.2, BuildKit 0.11.6):
Run |
Time |
|---|---|
First run of |
5.6 s |
Warm rerun |
1.2 to 1.7 s |
Cold |
under 3 s |
All runs produced the same file digest and image ID.
Not in scope yet¶
Build secrets (
--secret).Pushing from the build itself. Deliver the built image with
piceli artifacts deliver --to oci://…; see Image delivery.A single multi-platform manifest list. Each platform is loaded separately, because the classic Docker store cannot hold an index.