-
Notifications
You must be signed in to change notification settings - Fork 124
fix: podman.domain.containers.run pulls image if not found #600
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,13 @@ | |
| from contextlib import suppress | ||
| from typing import Any, Union | ||
| from collections.abc import MutableMapping | ||
| import requests | ||
|
|
||
| from podman import api | ||
| from podman.domain.containers import Container | ||
| from podman.domain.images import Image | ||
| from podman.domain.pods import Pod | ||
| from podman.domain.secrets import Secret | ||
| from podman.errors import ImageNotFound | ||
|
|
||
| logger = logging.getLogger("podman.containers") | ||
|
|
||
|
|
@@ -361,7 +361,6 @@ def create( | |
| A Container object. | ||
|
|
||
| Raises: | ||
| ImageNotFound: when Image not found by Podman service | ||
| APIError: when Podman service reports an error | ||
| """ | ||
| if isinstance(image, Image): | ||
|
|
@@ -379,7 +378,18 @@ def create( | |
| headers={"content-type": "application/json"}, | ||
| data=payload, | ||
| ) | ||
| response.raise_for_status(not_found=ImageNotFound) | ||
| if response.status_code == requests.codes.not_found: | ||
| self.podman_client.images.pull( | ||
| image, | ||
| auth_config=kwargs.get("auth_config"), | ||
| platform=kwargs.get("platform"), | ||
| policy=kwargs.get("policy", "missing"), | ||
| ) | ||
| response = self.client.post( | ||
| "/containers/create", | ||
| headers={"content-type": "application/json"}, | ||
| data=payload, | ||
| ) | ||
|
Comment on lines
+381
to
+392
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was curious to see what podman cli does when you call therefore I would simply remove the if and try to pull every time you create
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct me if I'm wrong, but podman cli default pull policy should be "missing", thus, it should not pull if the image is cached: I guess |
||
|
|
||
| container_id = response.json()["Id"] | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would check for an
ImageNotFounderror, not only404.