Skip to content

[BUG] pull() progress_bar=True does not work show JSON output as intended for compact mode #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
D3vil0p3r opened this issue Jan 6, 2025 · 0 comments · Fixed by #500
Closed

Comments

@D3vil0p3r
Copy link
Contributor

D3vil0p3r commented Jan 6, 2025

I wrote this small Python code to test Podman-py pull progress bar:

import podman
from podman import PodmanClient
import json

client = podman.from_env()
client.ping()

repository = "docker.io/ohmyzsh/zsh"

resp = client.images.pull(repository, progress_bar=True, stream=True)
for line in resp:
    print(line)

progress_bar description says:

            progress_bar (bool) - Display a progress bar with the image pull progress (uses
                the compat endpoint). Default: False

so Uses the compat endpoint, that should refer the podman API parameter compatMode=true. Generally, if I invoke directly the Podman API pull by setting compatMode=true by:

curl -XPOST --unix-socket /run/user/1000/podman/podman.sock -H content-type:application/json "http://d/v4.0.0/libpod/images/pull?reference=docker.io/athenaos/base&compatMode=true"

we get the JSON progress bar, that is right:

{"status":"Pulling fs layer","progressDetail":{},"id":"30babffc8f09"}
{"status":"Downloading","progressDetail":{"current":3373319,"total":152137719},"progress":"[=\u003e                                                 ]  3.373MB/152.1MB","id":"30babffc8f09"}
{"status":"Downloading","progressDetail":{"current":6650119,"total":152137719},"progress":"[==\u003e                                                ]   6.65MB/152.1MB","id":"30babffc8f09"}
{"status":"Downloading","progressDetail":{"current":9386247,"total":152137719},"progress":"[===\u003e
...

If I use Podman Py by setting progress_bar=True (so compactMode=true), sadly I don't get the JSON output but we directly get the "animated" progress bar.
Image

The problem of it, is that we cannot manipulate this response (i.e., if I want to manipulate the output). Can you please implement a way that Podman Py pull function can show the JSON output in compact mode as occurs for Docker Py?

@D3vil0p3r D3vil0p3r changed the title [BUG] pull() progress_bar=True does not work as intended [BUG] pull() progress_bar=True does not work show JSON output as intended for compact mode Jan 6, 2025
D3vil0p3r added a commit to D3vil0p3r/podman-py that referenced this issue Jan 7, 2025
Fix containers#492

Added `compatMode` param to `pull()` function. Default as `True` in order to give a well-structured JSON output like:
```
...
{'status': 'Pulling fs layer', 'progressDetail': {}, 'id': 'ef3afbc03436'}
{'status': 'Downloading', 'progressDetail': {'current': 1862903, 'total': 37308955}, 'progress': '[==>                                                ]  1.863MB/37.31MB', 'id': '1546de61b6c3'}
{'status': 'Download complete', 'progressDetail': {}, 'id': 'fa424c11eb04'}
{'status': 'Pulling fs layer', 'progressDetail': {}, 'id': '3d3d38ab8766'}
{'status': 'Downloading', 'progressDetail': {'current': 1441042, 'total': 3248294}, 'progress': '[======================>                            ]  1.441MB/3.248MB', 'id': 'ef3afbc03436'}
...
```
while `compatMode=False` still keep the one-field JSON output:
```
{'stream': 'Copying blob sha256:30babffc8f090f7c78c263b9a1b683b34ca5f73da74911ffe942d4d8225dca57\n'}
```
This approach differs from the already present `progress_bar=True` because does not show the "fancy" progress bar but a raw JSON output, useful for devs want to manipulate pull output.

Furthermore, the PR fixes `tls_verify` initialization in `pull()` because, according to its description, its Default should be `True`, but it was actually as `None`.

Signed-off-by: Antonio <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant