Skip to content

Commit

Permalink
feat: Add extra mounts logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Maggio committed Jun 27, 2023
1 parent aa516f7 commit 80f9240
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import Enum
from typing import TYPE_CHECKING, List, Optional, Union

import pydantic
from pydantic import DirectoryPath, Field, FilePath
from typing_extensions import Literal

Expand Down Expand Up @@ -231,3 +232,11 @@ class FileMount(Mount):

type: Literal[MountTypes.FILE]
source_path: FilePath


class ExtraMount(OpentronsBaseModel):
"""Extra bind mounts for a container."""

container_names: List[str]
host_path: DirectoryPath | FilePath
container_path: str
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pathlib
from abc import ABC, abstractmethod
from typing import Optional, Type, cast
from typing import List, Optional, Type, cast

from emulation_system import SystemConfigurationModel
from emulation_system.compose_file_creator import BuildItem, Service
Expand Down Expand Up @@ -199,12 +199,27 @@ def build_service(self) -> Service:
"""Method calling all generate* methods to build Service object."""
intermediate_healthcheck = self.generate_healthcheck()

container_name = self.generate_container_name()
mounts = self.generate_volumes()
extra_mounts = self._config_model.extra_mounts

if len(extra_mounts) > 0:
mounts_to_add: List[str] = []

for mount in extra_mounts:
if container_name in mount.container_names:
mounts_to_add.append(f"{mount.host_path}:{mount.container_path}")
if mounts is not None:
mounts.extend(mounts_to_add)
else:
mounts = mounts_to_add

return Service(
container_name=cast(ServiceContainerName, self.generate_container_name()),
container_name=cast(ServiceContainerName, container_name),
image=cast(ServiceImage, self.generate_image()),
build=cast(ServiceBuild, self.generate_build()),
tty=cast(ServiceTTY, self.is_tty()),
volumes=cast(ServiceVolumes, self.generate_volumes()),
volumes=cast(ServiceVolumes, mounts),
ports=cast(ServicePorts, self.generate_ports()),
environment=cast(ServiceEnvironment, self.generate_env_vars()),
networks=self.generate_networks(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from opentrons_pydantic_base_model import OpentronsBaseModel

from ...source import MonorepoSource, OpentronsModulesSource, OT3FirmwareSource
from ..config_file_settings import EmulationLevels, Hardware
from ..config_file_settings import (
EmulationLevels,
ExtraMount,
Hardware,
)
from ..errors import DuplicateHardwareNameError
from ..types.input_types import Containers, Modules, Robots
from ..types.intermediate_types import IntermediateNetworks
Expand Down Expand Up @@ -43,6 +47,7 @@ class SystemConfigurationModel(OpentronsBaseModel):
opentrons_modules_source: OpentronsModulesSource = Field(
default=OpentronsModulesSource(source_location="latest")
)
extra_mounts: List[ExtraMount] = Field(default=[])

@root_validator(pre=True)
def validate_names(cls, values) -> Dict[str, Dict[str, Containers]]: # noqa: ANN001
Expand Down

0 comments on commit 80f9240

Please sign in to comment.