Skip to content

Commit 1004081

Browse files
authored
Adding first shot at new features (x11 and fake home) (#444)
* adding first shot at new features this first commit will add a new feature, x11, which will be null by default. If the value is True, we default to binding ~/.Xauthority. if it is found to be a string, we use that instead. This means if there needs to be some custom bind like ~/.special-Xauthority TO the ~/.Xauthority, both of those need to be represented in the single string. Signed-off-by: vsoch <[email protected]> * adding support for home feature Signed-off-by: vsoch <[email protected]> * adding more docs about features to developer guide; Signed-off-by: vsoch <[email protected]> * small tweaks to docs and adding home feature to biocontainers beast2 Signed-off-by: vsoch <[email protected]> Co-authored-by: vsoch <[email protected]>
1 parent e40b6e7 commit 1004081

File tree

15 files changed

+107
-39
lines changed

15 files changed

+107
-39
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 pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.scom/singularityhub/singularity-hpc/tree/master) (0.0.x)
17+
- New features for X11 and custom home (0.0.33)
1718
- Adding singularity and docker specific options (0.0.32)
1819
- Adding more documentation on aliases
1920
- Bugfix to output error message if path does not exist for inspect

docs/getting_started/developer-guide.rst

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,46 @@ Fields include:
314314
- A list of environment variables to be defined in the container (key value pairs, e.g. var: value)
315315
- false
316316
* - features
317-
- Optional key, value paired set of features to enable for the container. Currently allowed keys: *gpu*. Allowed values: *true*, *false* (default)
318-
- false
317+
- Optional key, value paired set of features to enable for the container. Currently allowed keys: *gpu* *home* and *x11*.
318+
- varies
319+
320+
321+
A complete table of features is shown here. The
322+
323+
Fields include:
319324

325+
.. list-table:: Title
326+
:widths: 20 20 20 10 10 10
327+
:header-rows: 1
328+
329+
* - Name
330+
- Description
331+
- Container.yaml Values
332+
- Settings.yaml Values
333+
- Default
334+
- Supported
335+
* - gpu
336+
- Add flags to the container to enable GPU support (typically amd or nvidia)
337+
- true or false
338+
- null, amd, or nvidia
339+
- null
340+
- Singularity
341+
* - x11
342+
- Indicate to bind an Xauthority file to allow x11
343+
- true or false
344+
- null, true (uses default ~/.Xauthority) or bind path
345+
- null
346+
- Singularity
347+
* - home
348+
- Indicate a custom home to bind
349+
- true or false
350+
- null, or path to a custom home
351+
- null
352+
- Singularity, Docker
353+
354+
355+
For bind paths (e.g., home and x11) you can do a single path to indicate the same
356+
source and destination (e.g., /my/path) or a double for customization of that (e,g., /src:/dest).
320357
Other supported (but not yet developed) fields could include different unique
321358
resource identifiers to pull/obtain other kinds of containers. For this
322359
current version, since we are assuming HPC and Singularity, we will typically

docs/getting_started/user-guide.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,15 @@ option will be added. Currently, the following features are supported:
251251
- If the container technology supports it, add flags to indicate using gpu.
252252
- null
253253
- nvidia, amd, null
254-
254+
* - x11
255+
- Bind mount ~/.Xauthority or a custom path
256+
- null
257+
- true (uses default path ~/.Xauthority), false/null (do not enable) or a custom path to an x11 file
258+
* - home
259+
- Specify and bind mount a custom home path
260+
- null
261+
- custom path for the home, or false/null
262+
255263

256264
Modules Folder
257265
--------------

registry/jupyter/minimal-notebook/container.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ latest:
77
tags:
88
"4.0": sha256:6f9d189494fe091700681eb39b429dfe1420ad0717697c2e2293779fcb80cd1e
99
latest: sha256:be2da9cd312d7a19438fc0410613b1a6078d67305f23083721b2a073bb7d8b85
10+
features:
11+
home: true
1012
aliases:
1113
- name: run-notebook
1214
command: jupyter notebook --no-browser --port=$(shuf -i 2000-65000 -n 1) --ip 0.0.0.0
13-
singularity_options: --home ${HOME} --bind ${HOME}/.local:/home/joyvan/.local --bind $(mktemp -d):/run/user
15+
singularity_options: --home ${HOME} --bind ${HOME}/.local:/home/joyvan/.local --bind $(mktemp -d):/run/user

registry/quay.io/biocontainers/beast2/container.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ aliases:
1313
treeannotator: /usr/local/bin/treeannotator
1414
env:
1515
DISPLAY: ""
16+
features:
17+
home: true

shpc/main/container/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,20 @@ def get_features(self, config_features, settings_features, extra=None):
159159
# If the container technology has the feature and is defined in settings
160160
if key in self.features and key in settings_features:
161161

162-
# And if the settings feature is known to the container technology
162+
# Case 1: the feature is known to the container technology
163163
if settings_features[key] in self.features[key]:
164164

165-
# Add the feature to be given to the container!
166165
features[key] = self.features[key][settings_features[key]]
167166

167+
# Case 2: the exact value isn't known, but the feature accepts a string
168+
elif type(settings_features[key]) in self.features[key]:
169+
170+
# Add the feature to be given to the container!
171+
value = self.features[key][type(settings_features[key])]
172+
if value == "[use-self]":
173+
value = settings_features[key]
174+
features[key] = value
175+
168176
return features
169177

170178
def __str__(self):

shpc/main/container/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DockerContainer(ContainerTechnology):
2222
# The module technology adds extensions here
2323
templatefile = "docker"
2424
command = "docker"
25-
features = {}
25+
features = {"home": {str: "[use-self]"}}
2626

2727
def __init__(self):
2828
if shpc.utils.which(self.command)["return_code"] != 0:

shpc/main/container/singularity.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ class SingularityContainer(ContainerTechnology):
2525
templatefile = "singularity"
2626

2727
# Singularity container features
28-
features = {"gpu": {"nvidia": "--nv", "amd": "--rocm"}}
28+
features = {
29+
"gpu": {"nvidia": "--nv", "amd": "--rocm"},
30+
"x11": {True: "~/.Xauthority", str: "[use-self]"},
31+
"home": {str: "[use-self]"},
32+
}
2933

3034
def __init__(self):
3135
try:

shpc/main/modules/templates/docker.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ Container:
1616
Commands include:
1717
1818
- {|module_name|}-run:
19-
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}-v ${PWD} -w ${PWD} <container> "$@"
19+
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %}-v ${PWD} -w ${PWD} <container> "$@"
2020
- {|module_name|}-shell:
21-
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}--entrypoint {{ shell }} -v ${PWD} -w ${PWD}<container>
21+
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %}--entrypoint {{ shell }} -v ${PWD} -w ${PWD}<container>
2222
- {|module_name|}-exec:
23-
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint "" {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v ${PWD} -w ${PWD} <container> "$@"
23+
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint "" {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v ${PWD} -w ${PWD} <container> "$@"
2424
- {|module_name|}-inspect:
2525
{{ command }} inspect <container>
2626
2727
{% if aliases %}{% for alias in aliases %} - {{ alias.name }}:
28-
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ alias.entrypoint }} {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if alias.docker_options %}{{ alias.docker_options }} {% endif %} -v ${PWD} -w ${PWD} <container> "{{ alias.args }}"
28+
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ alias.entrypoint }} {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %}{% if alias.docker_options %}{{ alias.docker_options }} {% endif %} -v ${PWD} -w ${PWD} <container> "{{ alias.args }}"
2929
{% endfor %}{% endif %}
3030
3131
For each of the above, you can export:
@@ -44,10 +44,10 @@ local MODULEPATH="{{ module_dir }}"
4444
-- interactive shell to any container, plus exec for aliases
4545
local containerPath = '{{ image }}'
4646

47-
local shellCmd = "{{ command }} ${PODMAN_OPTS} run -i{% if tty %}t{% endif %} ${PODMAN_COMMAND_OPTS} -u `id -u`:`id -g` --rm --entrypoint {{ shell }} {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v ${PWD} -w ${PWD} " .. containerPath
47+
local shellCmd = "{{ command }} ${PODMAN_OPTS} run -i{% if tty %}t{% endif %} ${PODMAN_COMMAND_OPTS} -u `id -u`:`id -g` --rm --entrypoint {{ shell }} {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v ${PWD} -w ${PWD} " .. containerPath
4848
-- execCmd needs entrypoint to be the executor
49-
local execCmd = "{{ command }} ${PODMAN_OPTS} run ${PODMAN_COMMAND_OPTS} -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v ${PWD} -w ${PWD} "
50-
local runCmd = "{{ command }} ${PODMAN_OPTS} run ${PODMAN_COMMAND_OPTS} -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v ${PWD} -w ${PWD} " .. containerPath
49+
local execCmd = "{{ command }} ${PODMAN_OPTS} run ${PODMAN_COMMAND_OPTS} -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v ${PWD} -w ${PWD} "
50+
local runCmd = "{{ command }} ${PODMAN_OPTS} run ${PODMAN_COMMAND_OPTS} -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v ${PWD} -w ${PWD} " .. containerPath
5151
local inspectCmd = "{{ command }} ${PODMAN_OPTS} inspect ${PODMAN_COMMAND_OPTS} " .. containerPath
5252

5353
-- set_shell_function takes bashStr and cshStr

shpc/main/modules/templates/docker.tcl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ proc ModulesHelp { } {
1515
puts stderr " - {{ image }}"
1616
puts stderr "Commands include:"
1717
puts stderr " - {|module_name|}-run:"
18-
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v . -w . <container>"
18+
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v . -w . <container>"
1919
puts stderr " - {|module_name|}-shell:"
20-
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ shell }} {% if envfile %} --env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v . -w . <container>"
20+
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ shell }} {% if envfile %} --env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v . -w . <container>"
2121
puts stderr " - {|module_name|}-exec:"
22-
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint \"\" {% if envfile %} --env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v . -w . <container> $*"
22+
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint \"\" {% if envfile %} --env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v . -w . <container> $*"
2323
puts stderr " - {|module_name|}-inspect:"
2424
puts stderr " {{ command }} inspect <container>"
2525
{% if aliases %}{% for alias in aliases %} puts stderr " - {{ alias.name }}:"
26-
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} --rm -u `id -u`:`id -g` --entrypoint {{ alias.entrypoint | replace("$", "\$") }} {% if envfile %}--envfile {{ module_dir }}/{{ envfile }} {% endif %}{% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if alias.docker_options %}{{ alias.docker_options | replace("$", "\$") }} {% endif %} -v . -w . <container> {{ alias.args | replace("$", "\$") }}"
26+
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} --rm -u `id -u`:`id -g` --entrypoint {{ alias.entrypoint | replace("$", "\$") }} {% if envfile %}--envfile {{ module_dir }}/{{ envfile }} {% endif %}{% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %}{% if alias.docker_options %}{{ alias.docker_options | replace("$", "\$") }} {% endif %} -v . -w . <container> {{ alias.args | replace("$", "\$") }}"
2727
{% endfor %}{% endif %}
2828

2929
puts stderr "For each of the above, you can export:"
@@ -56,11 +56,11 @@ conflict {{ name }}
5656
{% endfor %}{% endif %}
5757

5858
# interactive shell to any container, plus exec for aliases
59-
set shellCmd "{{ command }} \${PODMAN_OPTS} run \${PODMAN_COMMAND_OPTS} -u `id -u`:`id -g` --rm -i{% if tty %}t{% endif %} --entrypoint {{ shell }} {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v $workdir -w $workdir ${containerPath}"
59+
set shellCmd "{{ command }} \${PODMAN_OPTS} run \${PODMAN_COMMAND_OPTS} -u `id -u`:`id -g` --rm -i{% if tty %}t{% endif %} --entrypoint {{ shell }} {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v $workdir -w $workdir ${containerPath}"
6060

6161
# execCmd needs entrypoint to be the executor
6262
set execCmd "{{ command }} \${PODMAN_OPTS} run -i{% if tty %}t{% endif %} \${PODMAN_COMMAND_OPTS} -u `id -u`:`id -g` --rm {% if envfile %} --env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }}{% endif %} -v $workdir -w $workdir"
63-
set runCmd "{{ command }} \${PODMAN_OPTS} run -i{% if tty %}t{% endif %} \${PODMAN_COMMAND_OPTS} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v $workdir -w $workdir ${containerPath}"
63+
set runCmd "{{ command }} \${PODMAN_OPTS} run -i{% if tty %}t{% endif %} \${PODMAN_COMMAND_OPTS} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v $workdir -w $workdir ${containerPath}"
6464
set inspectCmd "{{ command }} \${PODMAN_OPTS} inspect ${containerPath}"
6565

6666
# set_shell_function takes bashStr and cshStr

0 commit comments

Comments
 (0)