Skip to content

conf

BuildConfig

Bases: BaseModel

BuildConfig defines the build parameters for constructing a Docker image.

Attributes:

  • base_image (str) –

    Base image for the container. Default is "python:3.10-slim".

  • platform (Optional[str]) –

    Target platform in format os[/arch[/variant]].

  • python_deps_manager (Optional[str]) –

    Package manager for Python dependencies (e.g., pip, conda).

  • python_dependencies (Optional[List[str]]) –

    List of Python packages to install.

  • sys_deps_manager (Optional[str]) –

    Package manager for system dependencies (e.g., apt, yum, apk).

  • sys_dependencies (Optional[List[str]]) –

    List of system packages to install.

  • labels (Optional[List[Tuple[str, str]]]) –

    List of key-value tuples used as labels.

  • uid (Optional[int]) –

    User ID to use inside the container.

  • user (Optional[str]) –

    Username to use inside the container.

  • entrypoint (Optional[List[str]]) –

    Entrypoint command for the container.

  • cmd (Optional[List[str]]) –

    Default command to run in the container.

  • environment (Optional[Dict[str, str]]) –

    Environment variables for the container.

  • copies (Optional[List[Dict[str, str]]]) –

    File copy instructions (each dict should include "src" and "dest").

  • context_dir (Union[str, Path]) –

    Directory for the build context. Defaults to the current working directory.

  • docker_filename (str) –

    Filename for the Dockerfile. Defaults to "Dockerfile".

Examples:

>>> config = BuildConfig()
>>> config.base_image
'python:3.10-slim'

add_label

add_label(key: str, value: str)

Add a label to the build configuration.

Parameters:

  • key (str) –

    The label key.

  • value (str) –

    The label value.

Examples:

>>> config = BuildConfig()
>>> config.add_label("version", "1.0")
>>> config.labels
[("version", "1.0")]
Source code in ures/docker/conf.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def add_label(self, key: str, value: str):
    """
    Add a label to the build configuration.

    Args:
        key (str): The label key.
        value (str): The label value.

    Examples:
        >>> config = BuildConfig()
        >>> config.add_label("version", "1.0")
        >>> config.labels
        [("version", "1.0")]
    """
    logger.info(f"Adding label {key} with value {value}")
    if self.labels is None:
        self.labels = []
    self.labels.append((key, value))

add_copy

add_copy(src: str, dest: str)

Add a file copy instruction to the build configuration.

Parameters:

  • src (str) –

    Source file path.

  • dest (str) –

    Destination path inside the container.

Examples:

>>> config = BuildConfig()
>>> config.add_copy("app.py", "/app/app.py")
>>> config.copies
[{"src": "app.py", "dest": "/app/app.py"}]
Source code in ures/docker/conf.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def add_copy(self, src: str, dest: str):
    """
    Add a file copy instruction to the build configuration.

    Args:
        src (str): Source file path.
        dest (str): Destination path inside the container.

    Examples:
        >>> config = BuildConfig()
        >>> config.add_copy("app.py", "/app/app.py")
        >>> config.copies
        [{"src": "app.py", "dest": "/app/app.py"}]
    """
    logger.info(f"Adding copy {src} to {dest}")
    if self.copies is None:
        self.copies = []
    self.copies.append({"src": src, "dest": dest})

add_environment

add_environment(key: str, value: str)

Add an environment variable to the build configuration.

Parameters:

  • key (str) –

    The environment variable name.

  • value (str) –

    The value for the environment variable.

Examples:

>>> config = BuildConfig()
>>> config.add_environment("DEBUG", "true")
>>> config.environment["DEBUG"]
'true'
Source code in ures/docker/conf.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def add_environment(self, key: str, value: str):
    """
    Add an environment variable to the build configuration.

    Args:
        key (str): The environment variable name.
        value (str): The value for the environment variable.

    Examples:
        >>> config = BuildConfig()
        >>> config.add_environment("DEBUG", "true")
        >>> config.environment["DEBUG"]
        'true'
    """
    logger.info(f"Adding environment variable {key} with value {value}")
    if self.environment is None:
        self.environment = {}
    self.environment[key] = value

set_context_dir

set_context_dir(context_dir: Union[str, Path])

Set the build context directory.

Parameters:

  • context_dir (Union[str, Path]) –

    The directory to be used as the build context.

Raises:

  • ValueError –

    If the provided context directory does not exist or is not a directory.

Examples:

>>> from pathlib import Path
>>> config = BuildConfig()
>>> temp_dir = Path("/tmp")
>>> config.set_context_dir(temp_dir)
>>> config.context_dir == temp_dir
True
Source code in ures/docker/conf.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def set_context_dir(self, context_dir: Union[str, Path]):
    """
    Set the build context directory.

    Args:
        context_dir (Union[str, Path]): The directory to be used as the build context.

    Raises:
        ValueError: If the provided context directory does not exist or is not a directory.

    Examples:
        >>> from pathlib import Path
        >>> config = BuildConfig()
        >>> temp_dir = Path("/tmp")
        >>> config.set_context_dir(temp_dir)
        >>> config.context_dir == temp_dir
        True
    """
    logger.info(f"Setting context directory to {context_dir}")
    if isinstance(context_dir, str):
        context_dir = Path(context_dir)
    if not context_dir.is_dir():
        raise ValueError(f"Context directory {context_dir} is not a directory")
    self.context_dir = context_dir

add_python_dependency

add_python_dependency(dependency: str)

Add a Python dependency to be installed in the image.

Parameters:

  • dependency (str) –

    The Python package dependency (e.g., "flask==2.0.1").

Examples:

>>> config = BuildConfig()
>>> config.add_python_dependency("flask")
>>> "flask" in config.python_dependencies
True
Source code in ures/docker/conf.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def add_python_dependency(self, dependency: str):
    """
    Add a Python dependency to be installed in the image.

    Args:
        dependency (str): The Python package dependency (e.g., "flask==2.0.1").

    Examples:
        >>> config = BuildConfig()
        >>> config.add_python_dependency("flask")
        >>> "flask" in config.python_dependencies
        True
    """
    logger.info(f"Adding Python dependency: '{dependency}'")
    if self.python_dependencies is None:
        self.python_dependencies = []
    self.python_dependencies.append(dependency)

add_system_dependency

add_system_dependency(dependency: str)

Add a system dependency to be installed in the image.

Parameters:

  • dependency (str) –

    The system package dependency (e.g., "curl").

Examples:

>>> config = BuildConfig()
>>> config.add_system_dependency("curl")
>>> "curl" in config.sys_dependencies
True
Source code in ures/docker/conf.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def add_system_dependency(self, dependency: str):
    """
    Add a system dependency to be installed in the image.

    Args:
        dependency (str): The system package dependency (e.g., "curl").

    Examples:
        >>> config = BuildConfig()
        >>> config.add_system_dependency("curl")
        >>> "curl" in config.sys_dependencies
        True
    """
    logger.info(f"Adding system dependency: '{dependency}'")
    if self.sys_dependencies is None:
        self.sys_dependencies = []
    self.sys_dependencies.append(dependency)

add_run_command

add_run_command(command: str)

Add a command to be run during the build process.

Parameters:

  • command (str) –

    The command to run (e.g., "apt-get update").

Examples:

>>> config = BuildConfig()
>>> config.add_run_command("apt-get update")
>>> "apt-get update" in config.run_commands
True
Source code in ures/docker/conf.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
def add_run_command(self, command: str):
    """
    Add a command to be run during the build process.

    Args:
        command (str): The command to run (e.g., "apt-get update").

    Examples:
        >>> config = BuildConfig()
        >>> config.add_run_command("apt-get update")
        >>> "apt-get update" in config.run_commands
        True
    """
    logger.info(f"Adding run command: '{command}'")
    if self.run_commands is None:
        self.run_commands = []
    self.run_commands.append(command)

set_entrypoint

set_entrypoint(entrypoint: Union[str, List[str]])

Set the entrypoint for the container.

Parameters:

  • entrypoint (Union[str, List[str]]) –

    The entrypoint command(s). If a string is provided, it will be converted to a list.

Examples:

>>> config = BuildConfig()
>>> config.set_entrypoint("python app.py")
>>> config.entrypoint
["python app.py"]
Source code in ures/docker/conf.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def set_entrypoint(self, entrypoint: Union[str, List[str]]):
    """
    Set the entrypoint for the container.

    Args:
        entrypoint (Union[str, List[str]]): The entrypoint command(s). If a string is provided,
                                            it will be converted to a list.

    Examples:
        >>> config = BuildConfig()
        >>> config.set_entrypoint("python app.py")
        >>> config.entrypoint
        ["python app.py"]
    """
    if isinstance(entrypoint, str):
        entrypoint = [entrypoint]
    logger.info(f"Setting entrypoint to: '{entrypoint}'")
    self.entrypoint = entrypoint

set_cmd

set_cmd(cmd: Union[str, List[str]])

Set the command for the container.

Parameters:

  • cmd (Union[str, List[str]]) –

    The command(s) to run. If a string is provided, it will be converted to a list.

Examples:

>>> config = BuildConfig()
>>> config.set_cmd("python -m myapp")
>>> config.cmd
["python -m myapp"]
Source code in ures/docker/conf.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def set_cmd(self, cmd: Union[str, List[str]]):
    """
    Set the command for the container.

    Args:
        cmd (Union[str, List[str]]): The command(s) to run. If a string is provided,
                                     it will be converted to a list.

    Examples:
        >>> config = BuildConfig()
        >>> config.set_cmd("python -m myapp")
        >>> config.cmd
        ["python -m myapp"]
    """
    if isinstance(cmd, str):
        cmd = [cmd]
    logger.info(f"Setting command to: '{cmd}'")
    self.cmd = cmd

RuntimeConfig

Bases: BaseModel

RuntimeConfig defines the runtime parameters for running a Docker container.

Attributes:

  • image_name (str) –

    Name of the Docker image in the format "image:tag".

  • name (Optional[str]) –

    Container name.

  • platform (Optional[str]) –

    Platform for the container.

  • detach (bool) –

    Whether to run the container in detached mode.

  • user (Optional[str]) –

    User under which to run the container.

  • remove (bool) –

    Whether to remove the container after it stops.

  • cpus (Optional[int]) –

    Number of CPUs to allocate.

  • gpus (Optional[List[str]]) –

    List of GPUs to allocate.

  • gpu_driver (str) –

    Driver to use for GPUs. Default is "nvidia".

  • memory (Optional[str]) –

    Memory limit for the container (e.g., "2g").

  • entrypoint (Optional[List[Union[str, float, int, Path]]]) –

    Entrypoint command(s).

  • command (Optional[List[Union[int, float, str, Path]]]) –

    Command(s) to run.

  • env (Optional[Dict[str, str]]) –

    Environment variables.

  • volumes (Optional[Dict[str, Dict[str, str]]]) –

    Volume mappings.

  • subnet (Optional[str]) –

    Subnet for container networking.

  • ipv4 (Optional[str]) –

    Specific IPv4 address for the container.

  • subnet_mask (Optional[str]) –

    Subnet mask (e.g., "172.17.0.0/16").

  • subnet_gateway (Optional[str]) –

    Subnet gateway.

  • network_mode (Optional[str]) –

    Docker network mode.

  • out_dir (Path) –

    Output directory for logs and cache.

Examples:

>>> config = RuntimeConfig()
>>> config.image_name
'model-runner'

log_dir property

log_dir: Path

Get the log directory within the output directory. If it does not exist, it is created.

Returns:

  • Path ( Path ) –

    The path to the log directory.

Examples:

>>> config = RuntimeConfig()
>>> log_directory = config.log_dir
>>> log_directory.exists()
True

cache property

cache: Path

Get the cache directory within the output directory. If it does not exist, it is created.

Returns:

  • Path ( Path ) –

    The path to the cache directory.

Examples:

>>> config = RuntimeConfig()
>>> cache_directory = config.cache
>>> cache_directory.exists()
True

add_volume

add_volume(host_path: Union[str, Path], container_path: Union[str, Path], mode: str = 'rw')

Add a volume mapping for the container.

Parameters:

  • host_path (Union[str, Path]) –

    The path on the host machine.

  • container_path (Union[str, Path]) –

    The destination path inside the container.

  • mode (str, default: 'rw' ) –

    The mode for the volume mapping (e.g., "rw" or "ro"). Defaults to "rw".

Examples:

>>> config = RuntimeConfig()
>>> config.add_volume("/host/data", "/container/data", mode="rw")
>>> "/host/data" in config.volumes
True
Source code in ures/docker/conf.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
def add_volume(
    self,
    host_path: Union[str, Path],
    container_path: Union[str, Path],
    mode: str = "rw",
):
    """
    Add a volume mapping for the container.

    Args:
        host_path (Union[str, Path]): The path on the host machine.
        container_path (Union[str, Path]): The destination path inside the container.
        mode (str, optional): The mode for the volume mapping (e.g., "rw" or "ro"). Defaults to "rw".

    Examples:
        >>> config = RuntimeConfig()
        >>> config.add_volume("/host/data", "/container/data", mode="rw")
        >>> "/host/data" in config.volumes
        True
    """
    logger.info(f"Adding volume {host_path} to {container_path} with mode {mode}")
    if self.volumes is None:
        self.volumes = {}
    self.volumes[str(host_path)] = {"bind": str(container_path), "mode": mode}

add_env

add_env(key: str, value: str)

Add an environment variable for the container.

Parameters:

  • key (str) –

    The environment variable name.

  • value (str) –

    The value for the environment variable.

Examples:

>>> config = RuntimeConfig()
>>> config.add_env("DEBUG", "1")
>>> config.env["DEBUG"]
'1'
Source code in ures/docker/conf.py
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
def add_env(self, key: str, value: str):
    """
    Add an environment variable for the container.

    Args:
        key (str): The environment variable name.
        value (str): The value for the environment variable.

    Examples:
        >>> config = RuntimeConfig()
        >>> config.add_env("DEBUG", "1")
        >>> config.env["DEBUG"]
        '1'
    """
    logger.info(f"Adding environment variable {key} with value {value}")
    if self.env is None:
        self.env = {}
    self.env[key] = value