Skip to content

Commit df9bdd0

Browse files
committed
adding build options to support fakeroot, remote, etc.
Signed-off-by: Vanessa Sochat <[email protected]>
1 parent b184871 commit df9bdd0

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pypi.
1515

1616
## [0.0.x](https://github.com/singularityhub/singularity-compose/tree/master) (0.0.x)
17+
- adding more build options to build as build-flags (0.0.13)
1718
- when not using sudo, need to set --network=none, and catching exec error (0.0.12)
1819
- pyaml version should be for newer kind, and still check for attribute (0.0.11)
1920
- alpha release with simple (single container) working example (0.0.1)

docs/spec/spec-1.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ field (not defined above).|
111111
|build| a section to define how and where to build the base container from.|
112112
|build.context| the folder with the Singularity file (and other relevant files). Must exist.
113113
|build.recipe| the Singularity recipe in the build context folder. It defaults to `Singularity`|
114+
|build.options| a list of one or more options (single strings for boolean, or key value pairs for arguments) to provide to build. |
114115
|image| is looked for after a build entry. It can be a unique resource identifier, or container binary. |
115116
|volumes| one or more files or files to bind to the instance when it's started.|
116117
|volumes_from| shared volumes that are defined for other instances|

scompose/project/instance.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,18 @@ def build(self, working_dir):
281281
if not os.path.exists(self.recipe):
282282
bot.exit('%s not found for build' % self.recipe)
283283

284-
# This will require sudo
284+
# This will likely require sudo, unless --remote or --fakeroot in options
285285
try:
286+
options = self.get_build_options()
287+
288+
# If remote or fakeroot included, don't need sudo
289+
sudo = not ("--fakeroot" in options or "--remote" in options)
290+
286291
bot.info('Building %s' % self.name)
287292
self.client.build(image=sif_binary,
288-
recipe=self.recipe)
293+
recipe=self.recipe,
294+
options=options,
295+
sudo=sudo)
289296

290297
except:
291298
build = "sudo singularity build %s %s" % (os.path.basename(sif_binary),
@@ -299,6 +306,32 @@ def build(self, working_dir):
299306
else:
300307
bot.exit("neither image and build defined for %s" % self.name)
301308

309+
def get_build_options(self):
310+
''''get build options will parse through params, and return build
311+
options (if they exist)
312+
'''
313+
options = []
314+
315+
if "build" in self.params:
316+
if "options" in self.params['build']:
317+
for option in self.params['build']['options']:
318+
319+
# if the option is a string, it's a boolean flag
320+
if isinstance(option, str):
321+
options.append('--%s' % option)
322+
323+
# Otherwise, the user set a boolean with a value or an arg
324+
elif isinstance(option, dict):
325+
for key, val in option.items():
326+
if val is True:
327+
options.append('--%s' % key)
328+
elif val is False:
329+
continue
330+
else:
331+
options += ['--%s' % key, val]
332+
333+
return options
334+
302335
# State
303336

304337
def exists(self):

scompose/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
'''
1919

20-
__version__ = "0.0.12"
20+
__version__ = "0.0.13"
2121
AUTHOR = 'Vanessa Sochat'
2222
AUTHOR_EMAIL = '[email protected]'
2323
NAME = 'singularity-compose'

0 commit comments

Comments
 (0)