Skip to content

Commit

Permalink
fixing entrypoint accounting for WORKDIR (#115)
Browse files Browse the repository at this point in the history
* fixing entrypoint accounting for WORKDIR

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* move WORKDIR to be shared between recipe class

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* fixing bug with workdir/line

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>
  • Loading branch information
vsoch committed May 28, 2019
1 parent 4a37a2f commit 52fc5d2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions spython/main/parse/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 is not None:
runscript = [self.workdir] + [runscript]

# Finish the recipe
recipe += finish_section(runscript, 'runscript')

if self.test is not None:
Expand Down
11 changes: 7 additions & 4 deletions spython/main/parse/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
==========
Expand Down Expand Up @@ -203,7 +205,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
Expand Down Expand Up @@ -318,9 +320,10 @@ 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.install.append(line)
self.workdir = "cd %s" %(''.join(workdir))
self.install.append(self.workdir)


# Entrypoint and Command
Expand Down
1 change: 1 addition & 0 deletions spython/main/parse/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def parse(self):
self.ports = []
self.test = None
self.volumes = []
self.workdir = None

if self.recipe:

Expand Down
2 changes: 1 addition & 1 deletion spython/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 52fc5d2

Please sign in to comment.