Support Podman for mocking Lambda (#3702)
* Support Podman for mocking Lambda Podman supports all Docker APIs used in moto since version 3.0. Note that Podman requires pulling the image before creating a container using a fully-qualified image name (e.g., "docker.io/library/busybox" instead of "busybox"). Test plan: $ podman system service -t 0 $ DOCKER_HOST="unix://$XDG_RUNTIME_DIR/podman/podman.sock" pytest Fixes https://github.com/spulec/moto/issues/3276 * Run black * Python 2 compatibility * Address review comments and improve parse_image_ref
This commit is contained in:
parent
d3ad9d6686
commit
2000f6654f
5 changed files with 68 additions and 3 deletions
|
|
@ -2,6 +2,8 @@ import docker
|
|||
import functools
|
||||
import requests.adapters
|
||||
|
||||
from moto import settings
|
||||
|
||||
|
||||
_orig_adapter_send = requests.adapters.HTTPAdapter.send
|
||||
|
||||
|
|
@ -31,3 +33,27 @@ class DockerModel:
|
|||
|
||||
self.docker_client.api.get_adapter = replace_adapter_send
|
||||
return self.__docker_client
|
||||
|
||||
|
||||
def parse_image_ref(image_name):
|
||||
# podman does not support short container image name out of box - try to make a full name
|
||||
# See ParseDockerRef() in https://github.com/distribution/distribution/blob/main/reference/normalize.go
|
||||
parts = image_name.split("/")
|
||||
if len(parts) == 1 or (
|
||||
"." not in parts[0] and ":" not in parts[0] and parts[0] != "localhost"
|
||||
):
|
||||
domain = settings.DEFAULT_CONTAINER_REGISTRY
|
||||
remainder = parts
|
||||
else:
|
||||
domain = parts[0]
|
||||
remainder = parts[1:]
|
||||
# Special handling for docker.io
|
||||
# https://github.com/containers/image/blob/master/docs/containers-registries.conf.5.md#normalization-of-dockerio-references
|
||||
if domain == "docker.io" and len(remainder) == 1:
|
||||
remainder = ["library"] + remainder
|
||||
if ":" in remainder[-1]:
|
||||
remainder[-1], image_tag = remainder[-1].split(":", 1)
|
||||
else:
|
||||
image_tag = "latest"
|
||||
image_repository = "/".join([domain] + remainder)
|
||||
return image_repository, image_tag
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue