-
Notifications
You must be signed in to change notification settings - Fork 0
Add optional mounts #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
08ffeb9
3ae2de2
2cd80fc
46cdf76
fdd1c25
ee85172
850dd60
80e21d4
b063a5c
4122ab7
5fbd1ec
3c98cc1
5582a4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from typing import Annotated, Literal | ||
|
|
||
| from pydantic import AnyUrl, Field, StringConstraints, UrlConstraints | ||
| from pydantic import AnyUrl, Field, StringConstraints, UrlConstraints, model_validator | ||
|
|
||
| from .app import ENTRYPOINT_NAME_REGEX | ||
| from .parent import ParentModel | ||
|
|
@@ -27,9 +27,20 @@ class EntrypointOptions(ParentModel): | |
| mounts: Annotated[ | ||
| list[MountPoint], | ||
| Field( | ||
| description="A list of mount points to add to the container in the form of " | ||
| description="A list of mount points that will result in an error if their " | ||
| "host paths cannot be found. This takes the form of " | ||
| "'host_path[:container_path[:opts]]' where opts (mount options) can be " | ||
| "'ro' or 'rw' and defaults to 'rw'" | ||
| "'ro' or 'rw' and defaults to 'rw'. " | ||
| ), | ||
| ] = [] | ||
|
|
||
| optional_mounts: Annotated[ | ||
| list[MountPoint], | ||
| Field( | ||
| description="A list of mount points that will not be mounted if their host " | ||
| "paths cannot be found (avoiding an error). This takes the form of " | ||
| "'host_path[:container_path[:opts]]' where opts (mount options) " | ||
| "can be 'ro' or 'rw' and defaults to 'rw'." | ||
| ), | ||
| ] = [] | ||
|
|
||
|
|
@@ -42,6 +53,17 @@ class EntrypointOptions(ParentModel): | |
| ), | ||
| ] = [] | ||
|
|
||
| @model_validator(mode="after") | ||
| def check_unique_mounts(self) -> "EntrypointOptions": | ||
| """Ensure that mounts and optional_mounts do not contain duplicates.""" | ||
| duplicate_mounts = set(self.mounts).intersection(set(self.optional_mounts)) | ||
| if duplicate_mounts: | ||
| raise ValueError( | ||
| f"Duplicate paths found in mounts and optional_mounts: " | ||
| f"{duplicate_mounts}" | ||
| ) | ||
| return self | ||
|
|
||
|
|
||
| class Entrypoint(ParentModel): | ||
| """Represents an entrypoint to a command on the Apptainer image. | ||
|
|
@@ -121,3 +143,14 @@ class ApptainerApp(ParentModel): | |
| EntrypointOptions, | ||
| Field(description="Global options that apply to all Entrypoints"), | ||
| ] = EntrypointOptions() | ||
|
|
||
| @model_validator(mode="after") | ||
| def prioritise_entrypoint_mounts(self) -> "ApptainerApp": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this work if you have multiple entrypoints with different mounts?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not work very well with multiple entrypoints. When an entrypoint is removed from mounts, it is removed for all entrypoints. I will investigate a solution outside of the model_validator. Either in validate.py or app_builder.py |
||
| """Allow entrypoint options to override mounts defined in global_options""" | ||
| for entrypoint in self.entrypoints: | ||
| for mount in entrypoint.options.mounts + entrypoint.options.optional_mounts: | ||
| if mount in self.global_options.mounts: | ||
| self.global_options.mounts.remove(mount) | ||
| if mount in self.global_options.optional_mounts: | ||
| self.global_options.optional_mounts.remove(mount) | ||
| return self | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to change this from list to set without affecting the configuration? Or would this be backwards-incompatible?