Skip to content

feat(operations): add docker_cmd parameter and podman proxy operations - #2120

Open
elazar wants to merge 9 commits into
pyinfra-dev:3.xfrom
elazar:fix/podman-aware-docker-operations
Open

elazar wants to merge 9 commits into
pyinfra-dev:3.xfrom
elazar:fix/podman-aware-docker-operations

Conversation

@elazar

@elazar elazar commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Allow Docker-compatible CLI (e.g. Podman) to replace Docker via a docker_cmd parameter on all Docker operations, plus a new pyinfra.operations.podman proxy module that routes every command through podman instead of docker.

Changes

pyinfra/operations/docker.py (commit 9fffb56)

  • Added docker_cmd: str = "docker" parameter to all 10 operations: container, image, build, volume, network, prune, plugin, login, logout, compose
  • build_cmd now derives from docker_cmd when not explicitly provided (f"{docker_cmd} build")
  • compose keeps compose_command: str = "docker compose" (unchanged — already switchable)
  • All operations pass docker_cmd through to generated StringCommands and host.get_fact(...) calls
  • All docker_cmd parameters documented in operation docstrings (+ docker_cmd: Docker-compatible CLI to substitute for ``docker`` (e.g. ``podman``))
  • login docstring: removed hardcoded docker login reference in prose
  • DockerSystemInfo.command() now respects docker_cmd like requires_command() already did

pyinfra/operations/util/docker.py (commit bf67c22)

  • All 16 command builders (_create_container, _remove_container, _start_container, _stop_container, _pull_image, _remove_image, _prune_command, _create_volume, _remove_volume, _create_network, _remove_network, _install_plugin, _remove_plugin, _enable_plugin, _disable_plugin, _set_plugin_options) accept docker_cmd as an explicit StringCommand argument instead of an f"{docker_cmd} ..." prefix

pyinfra/operations/podman.py (commit 5cd2450, new)

  • Thin proxy module wrapping all 10 docker operations
  • Each proxy sets kwargs["docker_cmd"] = "podman" (or compose_command="podman compose" for compose) and delegates via docker.<op>._inner(...)
  • Docstrings document each as a proxy around the equivalent Docker operation

pyinfra/facts/docker.py (commit 580735d)

  • Added _docker_cmd(kwargs) helper — replaced 10 identical kwargs.get("docker_cmd") or "docker" extractions (3 requires_command + 7 command sites)
  • Added _docker_inspect_all(docker_cmd, resource, list_command) helper — replaced 3 identical inspect-all command templates (containers ps -qa, images images -q, plugins plugin ls -q)
  • DockerSystemInfo.command() now respects docker_cmd

pyinfra/facts/podman.py (commit 8a7fe13)

  • Fixed PodmanFactBase docstring (was an unfinished fragment)
  • Updated PodmanSystemInfo and PodmanPs docstrings to match the Docker Returns ... convention

pyinfra-metadata.toml (commit 5cd2450)

  • Registered podman-ops plugin (name="podman", path="src/pyinfra/operations/podman.py", type="operation", tags=["containers"])

Tests (commit 9a3307b)

  • Added docker_cmd="podman" fixtures for login/logout (4 fixtures)
  • Added docker_cmd="podman" fixture for build (build_with_docker_cmd.json)
  • Added 10 podman proxy operation fixture directories (podman.container, podman.image, podman.build, podman.volume, podman.network, podman.plugin, podman.login, podman.logout, podman.prune, podman.compose)
  • Added DockerSystemInfo fact fixtures (default + docker_cmd=podman)
  • Updated 63 existing Docker operation fixtures to include docker_cmd=docker in fact keys

Documentation

  • Regenerated docs/operations/docker.md and docs/operations/podman.md via scripts/generate_operations_docs.py

Commit organization

7 atomic commits (in order):

Commit Type Scope What
580735d refactor(facts.docker) add docker_cmd helpers dedup 10 kwargs.get("docker_cmd") or "docker" extractions + 3 inspect-all templates; DockerSystemInfo.command() now respects docker_cmd
8a7fe13 docs(facts.podman) fix incomplete docstrings complete PodmanFactBase fragment; update PodmanSystemInfo/PodmanPs
9fffb56 feat(operations.docker) add docker_cmd parameter thread docker_cmd through all 10 docker operations
bf67c22 refactor(operations.docker.util) split f-strings into explicit StringCommand args 16 command builders use StringCommand(docker_cmd, "subcommand", ...)
5cd2450 feat(operations) add podman proxy operations new operations/podman.py + podman-ops metadata plugin
9a3307b test add docker_cmd and podman fixtures 80 test files: 63 updated + 17 new fixture files
3a7e563 resolve upstream 3.x merge conflicts merge conflict resolution resolved conflicts with upstream 3.x in facts/podman.py, operations/docker.py, operations/util/docker.py

Verification

  • uv run pytest tests/test_operations.py tests/test_facts.py → 1428 passed
  • uv run ruff check → pass (only pre-existing E402 on docker.py:22 from base commit)
  • uv run ruff format --check → pass
  • uv run mypy → pass

Checklist

  • Pull request is based on the default branch (3.x at this time)
  • Pull request includes tests for any new/updated operations/facts
  • Pull request includes documentation for any new/updated operations/facts
  • Tests pass (see scripts/dev-test.sh)
  • Type checking & code style passes (see scripts/dev-lint.sh)
  • Pull request title follows the conventional commits format (feat(operations.docker): allow podman to replace docker via docker_cmd)
  • Commit scope follows allowed scopes (operations.docker)

Notes for reviewers

  • DockerAuths fact intentionally does not accept docker_cmd — it reads ${DOCKER_CONFIG:-$HOME/.docker}/config.json directly, which is shared between docker and podman (both honor DOCKER_CONFIG and default to ~/.docker/config.json).
  • compose keeps its own compose_command: str = "docker compose" default (with space) since docker compose/podman compose is a subcommand invocation, not a bare binary name.
  • login/logout hardcode neither docker nor podman in generated commands; docker_cmd controls the binary. Prose in the login docstring no longer says docker login.
  • Podman facts (facts/podman.py) remain standalone; they do not proxy to Docker facts because the fact framework lacks the _inner escape hatch that operations use.

Matthew Turland added 6 commits November 26, 2026 13:37
Extract _docker_cmd() and _docker_inspect_all() helpers to deduplicate
identical docker_cmd extraction and inspect-all command templates across
Docker facts. DockerSystemInfo.command() now respects docker_cmd like
requires_command() already did.
Complete the unfinished PodmanFactBase docstring fragment and update
PodmanSystemInfo/PodmanPs to match the Docker Returns ... docstring
convention.
Add docker_cmd: str = "docker" parameter to all 10 docker operations
(container, image, build, volume, network, prune, plugin, login, logout,
compose). Each operation passes docker_cmd through to generated commands
and host.get_fact() calls so podman can replace docker. build_cmd now
derives from docker_cmd when not explicitly provided.
…ngCommand args

Replace f"{docker_cmd} ..." single-string prefixes with explicit
StringCommand(docker_cmd, "subcommand", ...) arguments in all 16 command
builders. No behavior change, generated commands are identical.
Add pyinfra.operations.podman proxy module wrapping all 10 docker
operations. Each proxy sets docker_cmd="podman" (or
compose_command="podman compose" for compose) and delegates via
docker.<op>._inner(...). Register podman-ops plugin in metadata.
Add docker_cmd="podman" fixtures for login/logout/build operations,
update 63 existing Docker operation fixtures to include docker_cmd=docker
in fact keys, and add 10 podman proxy operation fixture directories plus
DockerSystemInfo fact fixtures (default + podman).
@wowi42 wowi42 added new feature operations Issues with operations. CLI CLI mode specific issues. facts Issues with facts. labels Nov 26, 2026
Resolve conflicts in facts/podman.py (took upstream version with
_parse_podman_json helper and new podman facts), operations/docker.py
(volume gets both options and docker_cmd params), and operations/util
docker.py (_create_volume gets both options and docker_cmd).

@wowi42 wowi42 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a split and another pass before merge. The docker_cmd change and new Podman API are separate features. I found injection and compatibility blockers inline.

Also, container_exec is missing both docker_cmd and a Podman proxy, most changed fact commands lack custom-command fixtures, and the root mr-description.md artifact should be removed.

return kwargs.get("docker_cmd") or "docker"


def _docker_inspect_all(docker_cmd: str, resource: str, list_command: str) -> str:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new docker_cmd value is interpolated directly into shell text here and in operation commands. A value with shell metacharacters can execute injected syntax. Please quote the executable with QuoteString and add hostile-input fixtures.

Comment thread src/pyinfra/operations/podman.py Outdated
yield from docker.prune._inner(*args, **kwargs)


@operation()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podman has no plugin command. The network proxy can also pass --scope, --ingress, --attachable, and --aux-address, which podman network create does not support. Please remove or gate unsupported commands and flags and test against the real CLI.

@@ -759,7 +800,7 @@ def login(
command_bits: list = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auth fact only reads Docker's config, even when docker_cmd is Podman. Podman login normally writes ${XDG_RUNTIME_DIR}/containers/auth.json, so login/logout idempotency will be wrong. Please use command-aware auth state and cover the Podman path.

Comment thread src/pyinfra/operations/podman.py Outdated
yield from docker.network._inner(*args, **kwargs)


@operation()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proxy functions expose only *args and **kwargs, so their public signatures and parameter docs are lost. prune and compose also lose the target operations' non-idempotent decorator setting. Please preserve the wrapped API and metadata.

Matthew Turland added 2 commits November 30, 2026 11:38
Format the QuoteString(docker_cmd) wrapping introduced by ruff format
and remove the mr-description.md artifact requested by the reviewer.
@elazar

elazar commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Resolved ✅ — @wowi42

docker_cmd is now shell-quoted everywhere it reaches a shell command:

  • operations/util/docker.py: all 16 command builders pass QuoteString(docker_cmd) as the first StringCommand bit instead of the bare docker_cmd string.
  • operations/docker.py: build_cmd default is f"{shlex.quote(docker_cmd)} build"; container_exec uses QuoteString(docker_cmd).
  • facts/docker.py: _docker_cmd() returns shlex.quote(...), and all DockerSingleMixin-derived fact commands quote the executable.

A hostile value like podman; rm -rf / now renders as 'podman; rm -rf /' and cannot inject syntax.

Added hostile-input fixtures:

  • tests/operations/docker.container/add_container_with_hostile_docker_cmd.json
  • tests/operations/docker.login/login_with_hostile_docker_cmd.yaml

Fixes committed and pushed to fix/podman-aware-docker-operations (commits a80632c0, 9e4ee6b1). Tests: 1746 passed; ruff/mypy/arguments-sync clean.

@elazar

elazar commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Resolved ✅ — @wowi42

operations/podman.py was rewritten with explicit signatures:

  • podman.plugin proxy removed — Podman has no plugin command (fixture deleted).
  • podman.network now gates unsupported flags — scope, ingress, attachable, aux_addresses raise OperationError(...) before delegating.

Remaining proxies route through podman via docker_cmd="podman".

@elazar

elazar commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Resolved ✅ — @wowi42

DockerAuths.command() now accepts docker_cmd:

  • docker (default): reads ${DOCKER_CONFIG:-$HOME/.docker}/config.json (unchanged).
  • podman: reads ${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/containers/auth.json, matching where podman login writes auth state.

docker.login/docker.logout now call host.get_fact(DockerAuths, docker_cmd=docker_cmd). All 9 login/logout fixtures updated their DockerAuths fact keys to "docker_cmd=docker", plus new tests/facts/docker.DockerAuths/with_auths_podman.json.

@elazar

elazar commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Resolved ✅ — @wowi42

The proxies now declare explicit parameter signatures matching the wrapped docker operations, with full docstrings. Each delegates via docker.<op>._inner(...) with named arguments.

  • prune and compose keep @operation(is_idempotent=False).
  • container_exec added to both docker (new docker_cmd param) and podman proxies, with fixtures in tests/operations/docker.container_exec/ and tests/operations/podman.container_exec/.

Summary of remaining review points:

  • container_exec missing docker_cmd + podman proxy → added for both.
  • Most changed fact commands lacked custom-command fixtures → added docker_cmd=podman fixtures for all changed fact commands.
  • Root mr-description.md artifact → deleted.
  • Split into separate features → both kept in this PR since they share the docker_cmd plumbing; happy to split into two PRs if you'd prefer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI CLI mode specific issues. facts Issues with facts. new feature operations Issues with operations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants