Skip to content

Commit

Permalink
added "--add" command line option to add tar files as docker layers.
Browse files Browse the repository at this point in the history
not currently supported with singularity.
  • Loading branch information
Vbitz committed Feb 2, 2024
1 parent f90b77f commit 1eed895
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
16 changes: 16 additions & 0 deletions neurodocker/cli/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ def _get_common_renderer_params() -> list[click.Parameter]:
" The last path is always the destination path in the container."
),
),
OptionEatAll(
["--add"],
multiple=True,
type=tuple,
help=(
"Extract a tar file as a layer in the container. Provide a source and destination path."
),
),
OptionEatAll(
["--env"],
multiple=True,
Expand Down Expand Up @@ -340,6 +348,14 @@ def _get_instruction_for_param(ctx: click.Context, param: click.Parameter, value
raise click.ClickException("expected at least two values for --copy")
source, destination = list(value[:-1]), value[-1]
d = {"name": param.name, "kwds": {"source": source, "destination": destination}}
# add
elif param.name == "add":
if not isinstance(value, tuple):
raise ValueError("expected this value to be a tuple (contact developers)")
if len(value) < 2:
raise click.ClickException("expected at least two values for --add")
source, destination = value
d = {"name": param.name, "kwds": {"source": source, "destination": destination}}
# env
elif param.name == "env":
value = dict(value)
Expand Down
18 changes: 18 additions & 0 deletions neurodocker/reproenv/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ def copy(
destination: PathType | list[PathType],
) -> _Renderer:
raise NotImplementedError()

def add(
self,
source: PathType,
destination: PathType,
) -> _Renderer:
raise NotImplementedError()

def env(self, **kwds: str) -> _Renderer:
raise NotImplementedError()
Expand Down Expand Up @@ -484,6 +491,17 @@ def copy(
self._parts.append(s)
return self

@_log_instruction
def add(
self,
source: PathType,
destination: PathType,
) -> DockerRenderer:
"""Add a Dockerfile `ADD` instruction."""
s = f"ADD {source} {destination}"
self._parts.append(s)
return self

@_log_instruction
def env(self, **kwds: str) -> DockerRenderer:
"""Add a Dockerfile `ENV` instruction."""
Expand Down
36 changes: 35 additions & 1 deletion neurodocker/reproenv/schemas/renderer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
{
"$ref": "#/definitions/copy"
},
{
"$ref": "#/definitions/add"
},
{
"$ref": "#/definitions/env"
},
Expand Down Expand Up @@ -169,6 +172,37 @@
"examples": [],
"additionalProperties": false
},
"add": {
"required": [
"name",
"kwds"
],
"properties": {
"name": {
"enum": [
"add"
]
},
"kwds": {
"type": "object",
"required": [
"source",
"destination"
],
"properties": {
"source": {
"type": "string"
},
"destination": {
"type": "string"
}
},
"additionalProperties": false
}
},
"examples": [],
"additionalProperties": false
},
"env": {
"required": [
"name",
Expand Down Expand Up @@ -394,4 +428,4 @@
"additionalProperties": false
}
}
}
}

0 comments on commit 1eed895

Please sign in to comment.