The Polycrate Container

How the Debian-based Polycrate container (python:3.12-slim) executes actions deterministically: Docker native mode, mounts, Dockerfile.poly, and debug.

By default, Polycrate executes every action inside an ephemeral Docker container based on the public image cargo.ayedo.cloud/library/polycrate:<version>. This ensures developers, platform teams, and CI/CD pipelines use the exact same reproducible DevOps toolchain without local version conflicts.

Container Lifecycle

sequenceDiagram
    participant User
    participant CLI as Polycrate CLI
    participant Docker as Docker Engine (SDK)
    participant Container as Polycrate Container

    User->>CLI: polycrate run my-block install
    CLI->>CLI: Load workspace + secrets.poly & build snapshot
    alt Dockerfile.poly present
        CLI->>Docker: Build custom image
    end
    CLI->>Docker: Start container (mount /workspace + snapshot)
    Docker->>Container: Execute playbook / action
    Container-->>Docker: Exit code
    Docker->>Container: Restore file ownership to host UID/GID
    CLI->>Docker: Remove container
    CLI-->>User: Result & exit code

Included Toolchain (Debian python:3.12-slim)

The official image is based on Debian (python:3.12-slim) — not Alpine and not Ubuntu. Always use apt-get for custom extensions in Dockerfile.poly.

In v0.71.0, the bundled toolchain includes:

  • Automation & runtime: Python 3.12, Ansible (including community.general, community.docker, kubernetes.core), ansible-polycrate callback and vars plugins
  • Kubernetes & containers: kubectl, helm (including helm-diff), kustomize, cilium, argocd, velero, docker CLI (including buildx and compose v2), skopeo
  • Secrets, backup & encryption: bao (OpenBao), age, restic, kopia
  • Utilities & database clients: yq, jq, git, curl, wget, rsync, openssh-client, sshpass, envsubst, htpasswd, psql (postgresql-client), mariadb-client, sqlite3, dig (dnsutils)
  • Python SDKs: including kubernetes, hcloud, pynetbox, pyvmomi, cryptography, passlib

Mounts and Environment Variables

Default Mounts

Host Path Container Path Notes
Workspace root /workspace Read/Write (config.containerroot)
artifacts/secrets/id_rsa /workspace/artifacts/secrets/id_rsa Automatically used for Ansible/SSH
Temporary snapshot file Path in POLYCRATE_WORKSPACE_SNAPSHOT_YAML Read-only snapshot
Optional: extramounts / -m Configured target path e.g., /var/run/docker.sock:/var/run/docker.sock

For security reasons, the host SSH agent socket (SSH_AUTH_SOCK) is not mounted by default (opt-in via --ssh-agent-mount or config.sshagentmount: true in workspace.poly). → SSH

Key Environment Variables Inside the Container

Variable Meaning
POLYCRATE_WORKSPACE Workspace path inside the container (default: /workspace)
POLYCRATE_BLOCK / POLYCRATE_ACTION Active block and active action
POLYCRATE_WORKSPACE_SNAPSHOT_YAML Path to the mounted snapshot YAML file
POLYCRATE_HOST_UID / POLYCRATE_HOST_GID Host user's UID/GID for automatic ownership restoration
KUBECONFIG / K8S_AUTH_KUBECONFIG Path to the resolved kubeconfig (artifacts/secrets/kubeconfig.yml)
ANSIBLE_INVENTORY Path to inventory.yml
IN_CONTAINER 1 inside the container, 0 with --local

The working directory inside the container is automatically set to the template block directory (e.g., /workspace/blocks/my-block).

Docker Native Mode (Default)

By default, Polycrate communicates directly with the Docker daemon using the native Docker Go SDK (--docker-native / -N defaults to true). This eliminates CLI invocation overhead, provides typed error messages, and enables smooth output streaming with spinner feedback.

If needed, you can fall back to the Docker CLI via --docker-native=false or the environment variable POLYCRATE_DOCKER_NATIVE=false. Global CLI settings are stored in ~/.polycrate/polycrate.yml.

Podman Compatibility

Native mode also works with a Docker-compatible Podman socket:

podman system service --time=0 &
export DOCKER_HOST="unix:///run/user/$(id -u)/podman/podman.sock"
polycrate run my-block install

Custom Images with Dockerfile.poly

When a workspace requires additional tools, Python packages, or Ansible collections, place a Dockerfile.poly in the workspace root (filename configurable via config.dockerfile):

# Dockerfile.poly
FROM cargo.ayedo.cloud/library/polycrate:0.71.0

RUN apt-get update && apt-get install -y --no-install-recommends     redis-tools     && rm -rf /var/lib/apt/lists/*     && pip install --no-cache-dir boto3     && ansible-galaxy collection install amazon.aws

Polycrate automatically detects Dockerfile.poly and builds the image before executing the action (only when changed; can be disabled with --build=false).

Configure additional environment variables and mounts at the top level of workspace.poly (extraenv: / extramounts:) or per invocation using -e KEY=value and -m /host:/container.

Interactive Debugging (polycrate debug)

To interactively inspect the exact container environment (mounts, environment variables, tools, snapshot), start a debug shell:

polycrate debug

# With an additional mount or environment variable
polycrate debug -m /tmp/data:/data -e DEBUG=1

Inside the container, inspect the snapshot directly with yq:

yq '.block.config' "$POLYCRATE_WORKSPACE_SNAPSHOT_YAML"

File Permissions & fix-permissions

Because processes inside the container run as root, Polycrate automatically restores ownership of all workspace files — including .git — back to POLYCRATE_HOST_UID:POLYCRATE_HOST_GID via chown -R when any container exits (success, error, Ctrl+C, and polycrate debug).

If files owned by root still remain after a hard termination (SIGKILL, OOM kill), repair them without sudo:

polycrate workspace fix-permissions --dry-run
polycrate workspace fix-permissions

This command briefly launches the workspace container and fixes file ownership directly through Docker.

See Also