Skip to content
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

Use image mapper in docker executor #1177

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Changed
- Make processing container startup script ``Python`` 3.12 compatible
- Fix stop null executor processing in the preparation phase
- Reduce the maximal number of threads for downolad data in the init container
- Respect image mapper in ``list_docker_images`` management command
- Use image mapper in docker executor

Fixed
-----
Expand Down
33 changes: 24 additions & 9 deletions resolwe/flow/executors/docker/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ def _processing_volumes(self) -> Dict:
]
return dict([self._new_volume(*mount_point) for mount_point in mount_points])

def _map_docker_image(self, docker_image: str) -> str:
"""Transform the given Docker image according to the mapper.

If image starts with the prefix in the mapper keys, it is replaced with the
corresponding value. If no prefix matches, the image is returned unchanged.
"""
for prefix, replacement in SETTINGS.get("FLOW_CONTAINER_IMAGE_MAP", {}).items():
if docker_image.startswith(prefix):
return replacement + docker_image[len(prefix) :]
return docker_image

async def start(self):
"""Start process execution."""
memory = (
Expand All @@ -316,16 +327,20 @@ async def start(self):
else:
network_mode = "none"

processing_image = self.requirements.get(
"image",
SETTINGS.get(
"FLOW_DOCKER_DEFAULT_PROCESSING_CONTAINER_IMAGE",
"public.ecr.aws/s4q6j6e8/resolwe/base:ubuntu-20.04",
),
processing_image = self._map_docker_image(
self.requirements.get(
"image",
SETTINGS.get(
"FLOW_DOCKER_DEFAULT_PROCESSING_CONTAINER_IMAGE",
"public.ecr.aws/s4q6j6e8/resolwe/base:ubuntu-20.04",
),
)
)
communicator_image = SETTINGS.get(
"FLOW_DOCKER_COMMUNICATOR_IMAGE",
"public.ecr.aws/s4q6j6e8/resolwe/com:latest",
communicator_image = self._map_docker_image(
SETTINGS.get(
"FLOW_DOCKER_COMMUNICATOR_IMAGE",
"public.ecr.aws/s4q6j6e8/resolwe/com:latest",
)
)
ulimits = []
if (
Expand Down
19 changes: 19 additions & 0 deletions resolwe/flow/management/commands/list_docker_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ def add_arguments(self, parser):
help="Don't fail whenever a Docker image can't be pulled",
)

def _map_image(self, docker_image: str, mapper: dict[str, str]) -> str:
"""Transform the given Docker image according to the mapper.

If image starts with the prefix in the mapper keys, it is replaced with the
corresponding value. If no prefix matches, the image is returned unchanged.
"""
for prefix, replacement in mapper.items():
if docker_image.startswith(prefix):
return replacement + docker_image[len(prefix) :]
return docker_image

def _map_images(self, docker_images: set[str]) -> set[str]:
"""Map the docker images in the given set according to the settings."""
mapper = getattr(settings, "FLOW_CONTAINER_IMAGE_MAP", {})
return {self._map_image(image, mapper) for image in docker_images}

def handle(self, *args, **options):
"""Handle command list_docker_images."""
verbosity = int(options.get("verbosity"))
Expand Down Expand Up @@ -83,6 +99,9 @@ def handle(self, *args, **options):
)
)

# Map the Docker images according to the settings.
unique_docker_images = self._map_images(unique_docker_images)

# Pull images if requested or just output the list in specified format
if options["pull"]:
# Remove set of already pulled images.
Expand Down
Loading