# Copyright 2020-2025 ETH Zurich and the SeBS authors. All rights reserved.
"""Docker container management for OpenWhisk functions in SeBS.
Its primary focus is supporting both DockerHub and custom, local Docker registries.
The latter make development and prototyping much faster and easier.
They also allow users to push new images.
Classes:
OpenWhiskContainer: OpenWhisk-specific Docker container management
"""
import docker
from typing import Tuple
from sebs.faas.container import DockerContainer
from sebs.config import SeBSConfig
from sebs.openwhisk.config import OpenWhiskConfig
[docs]
class OpenWhiskContainer(DockerContainer):
"""
OpenWhisk-specific Docker container management.
Attributes:
config: OpenWhisk configuration containing registry settings
Example:
>>> container = OpenWhiskContainer(
... sys_config, ow_config, docker_client, True
... )
>>> registry, repo, tag, uri = container.registry_name(
... "benchmark", "python", "3.8", "x86_64"
... )
"""
[docs]
@staticmethod
def name() -> str:
"""
Get the platform name identifier.
Returns:
Platform name as string
"""
return "openwhisk"
[docs]
@staticmethod
def typename() -> str:
"""
Get the container type name.
Returns:
Container type name as string
"""
return "OpenWhisk.Container"
def __init__(
self,
system_config: SeBSConfig,
config: OpenWhiskConfig,
docker_client: docker.client.DockerClient,
experimental_manifest: bool,
) -> None:
"""
Initialize OpenWhisk container manager.
Args:
system_config: Global SeBS system configuration
config: OpenWhisk-specific configuration settings
docker_client: Docker client for container operations
experimental_manifest: Whether to use experimental manifest features
"""
super().__init__(system_config, docker_client, experimental_manifest)
self.config = config
[docs]
def registry_name(
self, benchmark: str, language_name: str, language_version: str, architecture: str
) -> Tuple[str, str, str, str]:
"""
Generate Docker registry information for a benchmark image.
This method creates the appropriate registry name, repository name, image tag,
and complete image URI based on the benchmark parameters and OpenWhisk
configuration. It handles both custom registries and Docker Hub.
Args:
benchmark: Name of the benchmark
language_name: Programming language (e.g., 'python', 'nodejs')
language_version: Language version (e.g., '3.8', '14')
architecture: Target architecture (e.g., 'x86_64')
Returns:
Tuple containing:
- Registry name (e.g., "my-registry.com" or "Docker Hub")
- Full repository name with registry prefix
- Image tag
- Complete image URI
"""
registry_name = self.config.resources.docker_registry
# We need to retag created images when pushing to registry other
# than default or to a different repository on DockerHub.
repository_name = self.system_config.docker_repository()
image_tag = self.system_config.benchmark_image_tag(
self.name(), benchmark, language_name, language_version, architecture
)
if registry_name is not None and registry_name != "":
repository_name = f"{registry_name}/{repository_name}"
else:
registry_name = "Docker Hub"
if self.config.dockerhub_repository is not None:
repository_name = self.config.dockerhub_repository
image_uri = f"{repository_name}:{image_tag}"
return registry_name, repository_name, image_tag, image_uri