podman-desktop icon indicating copy to clipboard operation
podman-desktop copied to clipboard

feat: create Docker context for Podman machine

Open jeffmaury opened this issue 8 months ago • 6 comments

Fixes #2630

What does this PR do?

Creates a Docker context for each registered Podman machine. Context are prefixed by podman- and is derived from the Podman machine name. If Podman machine starts with podman- is it the Podman machine name otherwise it is the Podman machine name prefixed by podman-

Screenshot / video of UI

N/A

What issues does this PR fix or reference?

#2630

How to test this PR?

Start Podman machine and check the Docker contexts (docker context ls)

  • [x] Tests are covering the bug fix or the new feature

jeffmaury avatar Apr 10 '25 07:04 jeffmaury

hello, I think on macOS it can be only 'podman' as only one machine can be available at runtime

and default name is unix:///Users/<username>/.local/share/containers/podman/machine/podman.sock

Podman Desktop gives me another path which one should I use ?

jeffmaury avatar Apr 10 '25 08:04 jeffmaury

hello, podman.sock is a symlink to the file that probably the API is returning to you

podman.sock -> /var/folders/_s/rlbw3qg15vx0j6vr4l7kd1hm0000gn/T/podman/podman-machine-default-api.sock

inspect returns

"ConnectionInfo": {
               "PodmanSocket": {
                    "Path": "/var/folders/_s/rlbw3qg15vx0j6vr4l7kd1hm0000gn/T/podman/podman-machine-default-api.sock"

benoitf avatar Apr 10 '25 08:04 benoitf

tried and the name of the context is "Podman machine podman-machine-default"

docker context ls

podman            Podman machine podman-machine-default     unix:///var/folders/_s/rlbw3qg15vx0j6vr4l7kd1hm0000gn/T/podman/podman-machine-default-api.sock

AFAIK it should be only "podman" on macOS as we don't care on the machine name as only one can exists being running ?

starting a new machine was not updating the context name

CONTAINERS_MACHINE_PROVIDER=libkrun podman machine ls                                                                                                                                                                                                                                     NAME                    VM TYPE     CREATED        LAST UP            CPUS        MEMORY      DISK SIZE
another                 libkrun     2 minutes ago  Currently running  6           2GiB        100GiB
podman-machine-default  libkrun     7 days ago     44 seconds ago     4           7.451GiB    93GiB
docker context ls                                                                                                                                                                                                                                                                             NAME              DESCRIPTION                               DOCKER ENDPOINT                                                                                  ERROR
default           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
podman            Podman machine podman-machine-default     unix:///var/folders/_s/rlbw3qg15vx0j6vr4l7kd1hm0000gn/T/podman/podman-machine-default-api.sock

(still named podman-machine-default)

benoitf avatar Apr 14 '25 13:04 benoitf

tried and the name of the context is "Podman machine podman-machine-default"

docker context ls

podman            Podman machine podman-machine-default     unix:///var/folders/_s/rlbw3qg15vx0j6vr4l7kd1hm0000gn/T/podman/podman-machine-default-api.sock

AFAIK it should be only "podman" on macOS as we don't care on the machine name as only one can exists being running ?

starting a new machine was not updating the context name

CONTAINERS_MACHINE_PROVIDER=libkrun podman machine ls                                                                                                                                                                                                                                     NAME                    VM TYPE     CREATED        LAST UP            CPUS        MEMORY      DISK SIZE
another                 libkrun     2 minutes ago  Currently running  6           2GiB        100GiB
podman-machine-default  libkrun     7 days ago     44 seconds ago     4           7.451GiB    93GiB
docker context ls                                                                                                                                                                                                                                                                             NAME              DESCRIPTION                               DOCKER ENDPOINT                                                                                  ERROR
default           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
podman            Podman machine podman-machine-default     unix:///var/folders/_s/rlbw3qg15vx0j6vr4l7kd1hm0000gn/T/podman/podman-machine-default-api.sock

(still named podman-machine-default)

Aren't you confusing name and description ?

jeffmaury avatar Apr 14 '25 14:04 jeffmaury

(still named podman-machine-default) Aren't you confusing name and description ?

well, as the podman machine is now called 'another', I expect to no see the name 'podman-machine-default' in the description as it's the name of my other machine being stopped

so I would opt for only name & description using only "Podman" wording (on macOS) (no need to reference the name of the machine as in my case anyway it's outdated)

benoitf avatar Apr 14 '25 14:04 benoitf

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds two DockerExtensionApi methods—createContext(context: DockerContextParsingInfo) and removeContext(context: string)—and exposes them from the Docker extension activate return. Implements creation/removal of Docker context metadata on disk in DockerContextHandler and adds unit tests. Introduces a new podman-docker-context extension that maps Podman container connections to Docker contexts (helpers for name/description/endpoint, DockerContextSynchronizer class, tests, entrypoint), plus build packaging script, Vite/tsconfig, README, and root package.json script updates for build/test/typecheck integration.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • podman-desktop/podman-desktop#14282 — Introduced the DockerExtensionApi package/initial interface that this PR expands with createContext/removeContext.

Suggested labels

area/ci, os/macOS 🍎

Suggested reviewers

  • cdrage
  • feloy
  • axel7083
  • benoitf

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change of creating Docker contexts for Podman machines and aligns with conventional commit style, making it clear and specific to the core update.
Linked Issues Check ✅ Passed The pull request implements the requested behavior from issue #2630 by introducing the DockerContextSynchronizer to create and remove Docker contexts for Podman machines with OS-aware naming and endpoint mapping, includes tests covering macOS expectations, and thus fulfills the linked issue’s objectives.
Out of Scope Changes Check ✅ Passed All introduced changes, including updates to DockerExtensionApi, DockerContextHandler, packaging scripts, and the new podman-docker-context extension, directly support the feature of creating Docker contexts for Podman machines and no unrelated modifications are present.
Description Check ✅ Passed The description clearly references issue #2630, explains the change to create Docker contexts for Podman machines, outlines testing steps, and is directly related to the changeset without being off-topic.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 markdownlint-cli2 (0.18.1)
extensions/podman-docker-context/README.md

markdownlint-cli2 v0.18.1 (markdownlint v0.38.0) Finding: extensions/podman-docker-context/README.md Linting: 1 file(s) Summary: 0 error(s) AggregateError: Unable to import module 'markdownlint-cli2-formatter-summarize'. at importModule (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:91:11) at async Promise.all (index 0) at async outputSummary (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:874:9) at async main (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:1053:25) at async file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2-bin.mjs:12:22 { [errors]: [ Error: Cannot find module 'markdownlint-cli2-formatter-summarize' Require stack: - /usr/local/lib/node_modules/markdownlint-cli2/node_modules/markdownlint/lib/resolve-module.cjs at Module._resolveFilename (node:internal/modules/cjs/loader:1369:15) at resolve (node:internal/modules/help

... [truncated 1157 characters] ...

4:11) at moduleResolve (node:internal/modules/esm/resolve:859:10) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38) at onImport.tracePromise.proto (node:internal/modules/esm/loader:659:36) at TracingChannel.tracePromise (node:diagnostics_channel:344:14) at ModuleLoader.import (node:internal/modules/esm/loader:658:21) { code: 'ERR_MODULE_NOT_FOUND', url: 'file:///markdownlint-cli2-formatter-summarize' } ] }


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Jul 03 '25 14:07 coderabbitai[bot]

@jeffmaury could you please provide more details on How to Test, I'm not sure what is expected on Mac

feloy avatar Aug 01 '25 10:08 feloy

@jeffmaury could you please provide more details on How to Test, I'm not sure what is expected on Mac

on MacOS, as you can have a single machine started, you should have a single Docker context created called podman

jeffmaury avatar Aug 01 '25 14:08 jeffmaury

Please feel free to dismiss my review after questions answered as I am on PTO this upcoming week.

cdrage avatar Aug 15 '25 15:08 cdrage

1.21.0 is out now. Are we good to merging this in? cc @jeffmaury

3 LGTM's + QE can test now after this.

cdrage avatar Aug 26 '25 17:08 cdrage

1.21.0 is out now. Are we good to merging this in? cc @jeffmaury

3 LGTM's + QE can test now after this.

No still one blocking review so delayed to 1.22.0

jeffmaury avatar Aug 26 '25 17:08 jeffmaury

should it be named podman-docker-context (as it's creating docker contexts but for podman) ?

Done in https://github.com/podman-desktop/podman-desktop/pull/12126/commits/426a079ba83409e66699011d5ee16a234f2f8648

jeffmaury avatar Oct 10 '25 08:10 jeffmaury