singularityhub / singularity-hpc

Local filesystem registry for containers (intended for HPC) using Lmod or Environment Modules. Works for users and admins.
https://singularity-hpc.readthedocs.io
Mozilla Public License 2.0
109 stars 25 forks source link

auto-generate full path to moduleDir in creation of modulefiles #642

Closed shahzebsiddiqui closed 1 year ago

shahzebsiddiqui commented 1 year ago

Is your feature request related to a problem? Please describe.

Currently the modulefile doesn't show the full command for that is set in modulefile.

Shown below is a generated modulefile from downloading emacs

(singularity-hpc)  ~/gitrepos/singularity-hpc/ [main*] ml show emacs
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   /global/u1/s/siddiq90/gitrepos/singularity-hpc/views/mpi/emacs/28.1.lua:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
help([[This module is a podman container wrapper for ghcr.io/autamus/emacs:28.1 v28.1

Container:

 - ghcr.io/autamus/emacs:28.1

Commands include:

 - emacs-run:
       podman run -it -u `id -u`:`id -g` --rm --env-file <moduleDir>/99-shpc.sh  -v ${PWD} -w ${PWD} <container> "$@"
 - emacs-shell:
       podman run -it -u `id -u`:`id -g` --rm --env-file <moduleDir>/99-shpc.sh  --entrypoint /bin/sh -v ${PWD} -w ${PWD}<container>
 - emacs-exec:
       podman run -it -u `id -u`:`id -g` --rm --entrypoint "" --env-file <moduleDir>/99-shpc.sh   -v ${PWD} -w ${PWD} <container> "$@"
 - emacs-inspect:
       podman inspect <container>
 - emacs-container:
       echo "$PODMAN_CONTAINER"

 - ebrowse:
       podman run -it -u `id -u`:`id -g` --rm --entrypoint /opt/view/bin/ebrowse --env-file <moduleDir>/99-shpc.sh  -v ${PWD} -w ${PWD} <container> "" "$@"
 - emacs:
       podman run -it -u `id -u`:`id -g` --rm --entrypoint /opt/view/bin/emacs --env-file <moduleDir>/99-shpc.sh  -v ${PWD} -w ${PWD} <container> "" "$@"
 - emacsclient:
       podman run -it -u `id -u`:`id -g` --rm --entrypoint /opt/view/bin/emacsclient --env-file <moduleDir>/99-shpc.sh  -v ${PWD} -w ${PWD} <container> "" "$@"
 - etags:
       podman run -it -u `id -u`:`id -g` --rm --entrypoint /opt/view/bin/etags --env-file <moduleDir>/99-shpc.sh  -v ${PWD} -w ${PWD} <container> "" "$@"

For each of the above, you can export:

 - PODMAN_OPTS: to define custom options for podman
 - PODMAN_COMMAND_OPTS: to define custom options for the command
 - PODMAN_CONTAINER: the container unique resource identifier
]])
setenv("PODMAN_CONTAINER","ghcr.io/autamus/emacs:28.1")
conflict("emacs","ghcr.io/autamus/emacs:28.1","ebrowse","emacsclient","etags")
prepend_path("PATH","/global/u1/s/siddiq90/shpc-modules/ghcr.io/autamus/emacs/28.1/bin")
whatis("Name        : emacs")
whatis("Version     : 28.1")

Describe the solution you'd like

shpc already knows the root of moduleDir that can be shown via

(singularity-hpc)  ~/gitrepos/singularity-hpc/ [main*] shpc config get module_base
module_base                    /global/homes/s/siddiq90/shpc-modules

It would be nice if the variable is declared in the modulefile so the full path is set so basically we should have <moduleDir> with full path to directory.

vsoch commented 1 year ago

Just so I understand - what do you want us to add? An environment variable or LMOD variable for the moduleDir? What is the use case? Note that the variable is already defined in the file:

-- directory containing this modulefile, once symlinks resolved (dynamically defined)
local moduleDir = subprocess("realpath " .. myFileName()):match("(.*[/])") or "."
shahzebsiddiqui commented 1 year ago

it just doesnt show this in output like it should say

 - clingo:
       podman run -it -u `id -u`:`id -g` --rm --entrypoint /opt/view/bin/clingo --env-file /global/u1/s/siddiq90/gitrepos/singularity-hpc/modules/ghcr.io/autamus/clingo/5.5.1/99-shpc.sh  -v ${PWD} -w ${PWD} <container> "" "$@"

instead of the <moduleDir> i was hoping to just copy-paste the command for podman commands if i can just run them directly. Can't {PWD} also be calculated automatically. Similarly the <container> can also be replaced by name of container.

vsoch commented 1 year ago

the point of shpc is that you don't need to copy paste podman commands, you just run clingo and that alias script is run for you.

shahzebsiddiqui commented 1 year ago

i see what you mean. Thanks for the clarification