UbuntuDockerRuntime

class UbuntuDockerRuntime(DockerRuntime):

A specialized Docker runtime for Ubuntu-based environments.

This runtime includes specific configurations and setup for Ubuntu containers, including proper Python path handling and environment setup. It provides methods for executing Python files, managing the container lifecycle, and handling file operations within the Ubuntu container.

Attributes: python_path (str): Path to the Python interpreter in the container docker_config (dict): Configuration dict for Docker container setup

init

def __init__(
    self,
    image: str,
    port: int = 0,
    remove: bool = True,
    python_path: str = '/usr/bin/python3',
    **kwargs
):

Initialize the Ubuntu Docker Runtime.

Parameters:

  • image (str): Docker image name to use
  • port (int, optional): Port to expose. Defaults to 0 (random port) (default: 0 (random port)
  • remove (bool, optional): Whether to remove container after use. Defaults to True
  • python_path (str, optional): Path to Python interpreter. Defaults to “/usr/bin/python3” **kwargs: Additional arguments passed to DockerRuntime

add

def add(
    self,
    funcs: Union[FunctionTool, List[FunctionTool]],
    entrypoint: str,
    redirect_stdout: bool = False,
    arguments: Optional[dict] = None
):

Add functions to the runtime with Ubuntu-specific modifications.

Returns:

Self for method chaining

_setup_default_mounts

def _setup_default_mounts(self):

Setup default volume mounts for the container.

This method can be extended to add Ubuntu-specific volume mounts.

build

def build(self, time_out: int = 15):

Build and initialize the Ubuntu container with proper setup.

Parameters:

  • time_out (int): Timeout in seconds for build operation

Returns:

Self for method chaining

exec_python_file

def exec_python_file(
    self,
    local_file_path: str,
    container_path: Optional[str] = None,
    args: Optional[List[str]] = None,
    env: Optional[dict] = None,
    callback: Optional[Callable[[str], None]] = None
):

Execute a Python file inside the Docker container.

Parameters:

  • env: Additional environment variables to set for the execution
  • callback: Optional function to process each line of output If None, output is printed to stdout

_create_archive_from_file

def _create_archive_from_file(self, file_path: Union[str, Path]):

Create a tar archive from a single file for docker.put_archive().

Parameters:

  • file_path: Path to the file to archive

Returns:

bytes: The tar archive as bytes