88import os
99from dataclasses import dataclass , field
1010from dataclasses_json import dataclass_json , Undefined # type: ignore
11- from typing import List , Optional , Dict , Any
11+ from typing import List , Optional , Dict , Any , Union
1212from enum import Enum
1313
1414from datacrunch .http_client .http_client import HTTPClient
@@ -43,6 +43,7 @@ class VolumeMountType(str, Enum):
4343 SCRATCH = "scratch"
4444 SECRET = "secret"
4545 MEMORY = "memory"
46+ SHARED = "shared"
4647
4748
4849class ContainerRegistryType (str , Enum ):
@@ -119,25 +120,88 @@ class EnvVar:
119120@dataclass_json (undefined = Undefined .EXCLUDE )
120121@dataclass
121122class VolumeMount :
122- """Volume mount configuration for containers .
123+ """Base class for volume mount configurations .
123124
124125 Attributes:
125126 type: Type of volume mount.
126127 mount_path: Path where the volume should be mounted in the container.
127- size_in_mb: Size of the memory volume in megabytes, only used for memory volume mounts
128+ size_in_mb: Size of the volume in megabytes. Deprecated: use MemoryMount for memory volumes instead.
128129 """
129130
130131 type : VolumeMountType
131132 mount_path : str
132- size_in_mb : Optional [int ] = None
133+ # Deprecated: use MemoryMount for memory volumes instead.
134+ size_in_mb : Optional [int ] = field (default = None , kw_only = True )
133135
134136
135- @dataclass_json
137+ @dataclass_json ( undefined = Undefined . EXCLUDE )
136138@dataclass
137- class SecretMount :
138- mount_path : str
139+ class GeneralStorageMount (VolumeMount ):
140+ """General storage volume mount configuration.
141+ """
142+
143+ def __init__ (self , mount_path : str ):
144+ """Initialize a general scratch volume mount.
145+
146+ Args:
147+ mount_path: Path where the volume should be mounted in the container.
148+ """
149+ super ().__init__ (type = VolumeMountType .SCRATCH , mount_path = mount_path )
150+
151+
152+ @dataclass_json (undefined = Undefined .EXCLUDE )
153+ @dataclass
154+ class SecretMount (VolumeMount ):
155+ """Secret volume mount configuration.
156+
157+ A secret volume mount allows mounting secret files into the container.
158+
159+ Attributes:
160+ secret_name: The name of the fileset secret to mount. This secret must be created in advance, for example using `create_fileset_secret_from_file_paths`
161+ file_names: List of file names that are part of the fileset secret.
162+ """
163+
139164 secret_name : str
140- type : VolumeMountType = VolumeMountType .SECRET
165+ file_names : Optional [List [str ]] = None
166+
167+ def __init__ (self , mount_path : str , secret_name : str , file_names : Optional [List [str ]] = None ):
168+ self .secret_name = secret_name
169+ self .file_names = file_names
170+ super ().__init__ (type = VolumeMountType .SECRET , mount_path = mount_path )
171+
172+
173+ @dataclass_json (undefined = Undefined .EXCLUDE )
174+ @dataclass
175+ class MemoryMount (VolumeMount ):
176+ """Memory volume mount configuration.
177+
178+ A memory volume mount provides high-speed, ephemeral in-memory storage inside your container.
179+ The mount path is currently hardcoded to /dev/shm and cannot be changed.
180+
181+ Attributes:
182+ size_in_mb: Size of the memory volume in megabytes.
183+ """
184+
185+ size_in_mb : int
186+
187+ def __init__ (self , size_in_mb : int ):
188+ super ().__init__ (type = VolumeMountType .MEMORY , mount_path = '/dev/shm' )
189+ self .size_in_mb = size_in_mb
190+
191+
192+ @dataclass_json (undefined = Undefined .EXCLUDE )
193+ @dataclass
194+ class SharedFileSystemMount (VolumeMount ):
195+ """Shared filesystem volume mount configuration.
196+
197+ A shared filesystem volume mount allows mounting a shared filesystem into the container.
198+ """
199+
200+ volume_id : str # The ID of the shared filesystem volume to mount, needs to be created first
201+
202+ def __init__ (self , mount_path : str , volume_id : str ):
203+ super ().__init__ (type = VolumeMountType .SHARED , mount_path = mount_path )
204+ self .volume_id = volume_id
141205
142206
143207@dataclass_json
@@ -155,7 +219,7 @@ class Container:
155219 volume_mounts: Optional list of volume mounts.
156220 """
157221
158- image : str
222+ image : Union [ str , dict ]
159223 exposed_port : int
160224 name : Optional [str ] = None
161225 healthcheck : Optional [HealthcheckSettings ] = None
0 commit comments