Skip to content

Docker registry customisation #12590

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions localstack-core/localstack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ def populate_edge_configuration(
# b) json dict mapping the <runtime> to an image, e.g. {"python3.9": "custom-repo/lambda-py:thon3.9"}
LAMBDA_RUNTIME_IMAGE_MAPPING = os.environ.get("LAMBDA_RUNTIME_IMAGE_MAPPING", "").strip()


# PUBLIC: 0 (default)
# Whether to disable usage of deprecated runtimes
LAMBDA_RUNTIME_VALIDATION = int(os.environ.get("LAMBDA_RUNTIME_VALIDATION") or 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,20 @@ class DockerRunFlags:
dns: Optional[List[str]]


class RegistryResolverStrategy(Protocol):
def resolve(self, image_name: str) -> str: ...


class HardCodedResolver:
def resolve(self, image_name: str) -> str: # noqa
return image_name


# TODO: remove Docker/Podman compatibility switches (in particular strip_wellknown_repo_prefixes=...)
# from the container client base interface and introduce derived Podman client implementations instead!
class ContainerClient(metaclass=ABCMeta):
registry_resolver_strategy: RegistryResolverStrategy = HardCodedResolver()

@abstractmethod
def get_system_info(self) -> dict:
"""Returns the docker system-wide information as dictionary (``docker info``)."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def copy_from_container(

def pull_image(self, docker_image: str, platform: Optional[DockerPlatform] = None) -> None:
cmd = self._docker_cmd()
docker_image = self.registry_resolver_strategy.resolve(docker_image)
cmd += ["pull", docker_image]
if platform:
cmd += ["--platform", platform]
Expand Down Expand Up @@ -518,6 +519,7 @@ def inspect_image(
pull: bool = True,
strip_wellknown_repo_prefixes: bool = True,
) -> Dict[str, Union[dict, list, str]]:
image_name = self.registry_resolver_strategy.resolve(image_name)
try:
result = self._inspect_object(image_name)
if strip_wellknown_repo_prefixes:
Expand Down Expand Up @@ -656,6 +658,7 @@ def has_docker(self) -> bool:
return False

def create_container(self, image_name: str, **kwargs) -> str:
image_name = self.registry_resolver_strategy.resolve(image_name)
cmd, env_file = self._build_run_create_cmd("create", image_name, **kwargs)
LOG.debug("Create container with cmd: %s", cmd)
try:
Expand All @@ -674,6 +677,7 @@ def create_container(self, image_name: str, **kwargs) -> str:
Util.rm_env_vars_file(env_file)

def run_container(self, image_name: str, stdin=None, **kwargs) -> Tuple[bytes, bytes]:
image_name = self.registry_resolver_strategy.resolve(image_name)
cmd, env_file = self._build_run_create_cmd("run", image_name, **kwargs)
LOG.debug("Run container with cmd: %s", cmd)
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ def copy_from_container(
def pull_image(self, docker_image: str, platform: Optional[DockerPlatform] = None) -> None:
LOG.debug("Pulling Docker image: %s", docker_image)
# some path in the docker image string indicates a custom repository

docker_image = self.registry_resolver_strategy.resolve(docker_image)
try:
self.client().images.pull(docker_image, platform=platform)
except ImageNotFound:
Expand Down Expand Up @@ -465,6 +467,7 @@ def inspect_image(
pull: bool = True,
strip_wellknown_repo_prefixes: bool = True,
) -> Dict[str, Union[dict, list, str]]:
image_name = self.registry_resolver_strategy.resolve(image_name)
try:
result = self.client().images.get(image_name).attrs
if strip_wellknown_repo_prefixes:
Expand Down Expand Up @@ -778,6 +781,8 @@ def create_container(
if volumes:
mounts = Util.convert_mount_list_to_dict(volumes)

image_name = self.registry_resolver_strategy.resolve(image_name)

def create_container():
return self.client().containers.create(
image=image_name,
Expand Down
Loading