From 1eed895fcb801b2788e241587231413eb416af2e Mon Sep 17 00:00:00 2001 From: Joshua Scarsbrook Date: Fri, 2 Feb 2024 01:10:53 +0000 Subject: [PATCH] added "--add" command line option to add tar files as docker layers. not currently supported with singularity. --- neurodocker/cli/generate.py | 16 ++++++++++ neurodocker/reproenv/renderers.py | 18 +++++++++++ neurodocker/reproenv/schemas/renderer.json | 36 +++++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/neurodocker/cli/generate.py b/neurodocker/cli/generate.py index 3e1cd6a9..c0fce1c0 100644 --- a/neurodocker/cli/generate.py +++ b/neurodocker/cli/generate.py @@ -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, @@ -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) diff --git a/neurodocker/reproenv/renderers.py b/neurodocker/reproenv/renderers.py index 4217d75a..83e1591b 100644 --- a/neurodocker/reproenv/renderers.py +++ b/neurodocker/reproenv/renderers.py @@ -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() @@ -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.""" diff --git a/neurodocker/reproenv/schemas/renderer.json b/neurodocker/reproenv/schemas/renderer.json index d01880de..a9b1ba23 100644 --- a/neurodocker/reproenv/schemas/renderer.json +++ b/neurodocker/reproenv/schemas/renderer.json @@ -50,6 +50,9 @@ { "$ref": "#/definitions/copy" }, + { + "$ref": "#/definitions/add" + }, { "$ref": "#/definitions/env" }, @@ -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", @@ -394,4 +428,4 @@ "additionalProperties": false } } -} +} \ No newline at end of file