From 42ceb4f6f7fe93a547a3ad2f176df169e4650a10 Mon Sep 17 00:00:00 2001 From: Vanessa Sochat Date: Tue, 28 May 2019 09:25:52 -0400 Subject: [PATCH 1/3] fixing entrypoint accounting for WORKDIR Signed-off-by: Vanessa Sochat --- CHANGELOG.md | 1 + spython/main/parse/converters.py | 10 ++++++++-- spython/main/parse/docker.py | 10 +++++++--- spython/version.py | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a84d995..6e522b66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The client here will eventually be released as "spython" (and eventually to singularity on pypi), and the versions here will coincide with these releases. ## [master](https://github.com/singularityhub/singularity-cli/tree/master) + - working directory, the last one defined, should be added to runscript (0.0.61) - adding deprecation message for image.export (0.0.60) - adding --force option to build - fixing warning for files, only relevant for sources (0.0.59) diff --git a/spython/main/parse/converters.py b/spython/main/parse/converters.py index af77d276..6965da4e 100644 --- a/spython/main/parse/converters.py +++ b/spython/main/parse/converters.py @@ -92,11 +92,11 @@ def create_runscript(self, default="/bin/bash", force=False): # Entrypoint should use exec if not entrypoint.startswith('exec'): - entrypoint = "exec %s" %entrypoint + entrypoint = "exec %s" % entrypoint # Should take input arguments into account if not re.search('"?[$]@"?', entrypoint): - entrypoint = '%s "$@"' %entrypoint + entrypoint = '%s "$@"' % entrypoint return entrypoint @@ -209,6 +209,12 @@ def docker2singularity(self, runscript="/bin/bash", force=False): # Take preference for user, entrypoint, command, then default runscript = self._create_runscript(runscript, force) + + # If a working directory was used, add it as a cd + if self.workdir != None: + runscript = [self.workdir] + [runscript] + + # Finish the recipe recipe += finish_section(runscript, 'runscript') if self.test is not None: diff --git a/spython/main/parse/docker.py b/spython/main/parse/docker.py index c99be13a..a57bf350 100644 --- a/spython/main/parse/docker.py +++ b/spython/main/parse/docker.py @@ -19,7 +19,9 @@ class DockerRecipe(Recipe): def __init__(self, recipe=None): '''a Docker recipe parses a Docker Recipe into the expected fields of - labels, environment, and install/runtime commands + labels, environment, and install/runtime commands. We save working + directory as we parse, and the last one can be added to the runscript + of a Singularity recipe. Parameters ========== @@ -27,6 +29,7 @@ def __init__(self, recipe=None): ''' self.name = "docker" + self.workdir = None super(DockerRecipe, self).__init__(recipe) @@ -203,7 +206,7 @@ def expandPath(path): return os.getcwd() if path == "." else path # Warn the user Singularity doesn't support expansion - if source.contains('*'): + if '*' in source: bot.warning("Singularity doesn't support expansion, * found in %s" % source) # Warning if file/folder (src) doesn't exist @@ -318,8 +321,9 @@ def _workdir(self, line): line: the line from the recipe file to parse for WORKDIR ''' + # Save the last working directory to add to the runscript workdir = self._setup('WORKDIR', line) - line = "cd %s" %(''.join(workdir)) + self.workdir = "cd %s" %(''.join(workdir)) self.install.append(line) diff --git a/spython/version.py b/spython/version.py index 291b69ac..efa2f80f 100644 --- a/spython/version.py +++ b/spython/version.py @@ -6,7 +6,7 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -__version__ = "0.0.60" +__version__ = "0.0.61" AUTHOR = 'Vanessa Sochat' AUTHOR_EMAIL = 'vsochat@stanford.edu' NAME = 'spython' From 54a21b01dc243e1fd33dff2494afc91db6f7a640 Mon Sep 17 00:00:00 2001 From: Vanessa Sochat Date: Tue, 28 May 2019 09:32:12 -0400 Subject: [PATCH 2/3] move WORKDIR to be shared between recipe class Signed-off-by: Vanessa Sochat --- spython/main/parse/docker.py | 1 - spython/main/parse/recipe.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/spython/main/parse/docker.py b/spython/main/parse/docker.py index a57bf350..8343eaf5 100644 --- a/spython/main/parse/docker.py +++ b/spython/main/parse/docker.py @@ -29,7 +29,6 @@ def __init__(self, recipe=None): ''' self.name = "docker" - self.workdir = None super(DockerRecipe, self).__init__(recipe) diff --git a/spython/main/parse/recipe.py b/spython/main/parse/recipe.py index f0a3692e..c632da62 100644 --- a/spython/main/parse/recipe.py +++ b/spython/main/parse/recipe.py @@ -117,6 +117,7 @@ def parse(self): self.ports = [] self.test = None self.volumes = [] + self.workdir = None if self.recipe: From d840f4e191c9cb1f219dee611fceb1c895af9ca3 Mon Sep 17 00:00:00 2001 From: Vanessa Sochat Date: Tue, 28 May 2019 10:28:48 -0400 Subject: [PATCH 3/3] fixing bug with workdir/line Signed-off-by: Vanessa Sochat --- spython/main/parse/converters.py | 2 +- spython/main/parse/docker.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spython/main/parse/converters.py b/spython/main/parse/converters.py index 6965da4e..5ad360af 100644 --- a/spython/main/parse/converters.py +++ b/spython/main/parse/converters.py @@ -211,7 +211,7 @@ def docker2singularity(self, runscript="/bin/bash", force=False): runscript = self._create_runscript(runscript, force) # If a working directory was used, add it as a cd - if self.workdir != None: + if self.workdir is not None: runscript = [self.workdir] + [runscript] # Finish the recipe diff --git a/spython/main/parse/docker.py b/spython/main/parse/docker.py index 8343eaf5..df403353 100644 --- a/spython/main/parse/docker.py +++ b/spython/main/parse/docker.py @@ -323,7 +323,7 @@ def _workdir(self, line): # Save the last working directory to add to the runscript workdir = self._setup('WORKDIR', line) self.workdir = "cd %s" %(''.join(workdir)) - self.install.append(line) + self.install.append(self.workdir) # Entrypoint and Command