Skip to content

Commit 0e31930

Browse files
authored
Merge pull request #47 from DataCrunch-io/feature/shared-file-system-mount
Feature/shared file system mount
2 parents 5c1338a + 6b1e696 commit 0e31930

File tree

7 files changed

+96
-21
lines changed

7 files changed

+96
-21
lines changed

.github/workflows/code_style.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-22.04
1212
strategy:
1313
matrix:
14-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
14+
python-version: ['3.10', '3.11', '3.12', '3.13']
1515

1616
steps:
1717
- uses: actions/checkout@v2

.github/workflows/unit_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-22.04
1212
strategy:
1313
matrix:
14-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
14+
python-version: ['3.10', '3.11', '3.12', '3.13']
1515

1616
steps:
1717
- uses: actions/checkout@v2

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added `SharedFileSystemMount` class for container sfs support
13+
- Added `SecretMount` and `GeneralStorageMount` classes that inherit from base `VolumeMount`
14+
15+
### Changed
16+
17+
- Removed support for python 3.9 as it doesn't support `kw_only` and reaches EOS state in 2 months
18+
1019
## [1.13.2] - 2025-06-04
1120

1221
### Changed

datacrunch/containers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
EntrypointOverridesSettings,
88
VolumeMount,
99
SecretMount,
10+
SharedFileSystemMount,
11+
GeneralStorageMount,
1012
VolumeMountType,
1113
Container,
1214
ContainerRegistryCredentials,

datacrunch/containers/containers.py

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
from dataclasses import dataclass, field
1010
from 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
1212
from enum import Enum
1313

1414
from 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

4849
class ContainerRegistryType(str, Enum):
@@ -119,25 +120,88 @@ class EnvVar:
119120
@dataclass_json(undefined=Undefined.EXCLUDE)
120121
@dataclass
121122
class 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

examples/containers/container_deployments_example.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
QueueLoadScalingTrigger,
2121
UtilizationScalingTrigger,
2222
HealthcheckSettings,
23-
VolumeMount,
23+
GeneralStorageMount,
2424
SecretMount,
25+
SharedFileSystemMount,
2526
ContainerRegistrySettings,
2627
Deployment,
27-
VolumeMountType,
2828
ContainerDeploymentStatus,
2929
)
3030

@@ -97,23 +97,24 @@ def main() -> None:
9797
path="/health"
9898
),
9999
volume_mounts=[
100-
# Shared memory volume
101-
VolumeMount(
102-
type=VolumeMountType.SCRATCH,
100+
GeneralStorageMount(
103101
mount_path="/data"
104102
),
105-
# Fileset secret
103+
# Optional: Fileset secret
106104
SecretMount(
107105
mount_path="/path/to/mount",
108106
secret_name="my-fileset-secret" # This fileset secret must be created beforehand
109-
)
107+
),
108+
# Optional: Mount an existing shared filesystem volume
109+
SharedFileSystemMount(
110+
mount_path="/sfs", volume_id="<ID-OF-THE-SFS-VOLUME>"),
110111
],
111112
env=[
112113
# Secret environment variables needed to be added beforehand
113114
EnvVar(
114115
name="HF_TOKEN",
115116
# This is a reference to a secret already created
116-
value_or_reference_to_secret="hf_token",
117+
value_or_reference_to_secret="hf-token",
117118
type=EnvVarType.SECRET
118119
),
119120
# Plain environment variables can be added directly

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
},
3131
classifiers=[
3232
"Programming Language :: Python :: 3",
33-
'Programming Language :: Python :: 3.9',
3433
'Programming Language :: Python :: 3.10',
3534
'Programming Language :: Python :: 3.11',
3635
'Programming Language :: Python :: 3.12',
@@ -41,5 +40,5 @@
4140
"Operating System :: OS Independent",
4241
"Natural Language :: English"
4342
],
44-
python_requires='>=3.9',
43+
python_requires='>=3.10',
4544
)

0 commit comments

Comments
 (0)