Skip to content

Commit 0b83f88

Browse files
committed
start of work to add podman support
Signed-off-by: vsoch <[email protected]>
1 parent bfaa2de commit 0b83f88

File tree

7 files changed

+106
-13
lines changed

7 files changed

+106
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ and **Merged pull requests**. Critical items to know are:
1313

1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

16-
## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/master) (0.0.x)
16+
## [0.0.x](https://github.scom/singularityhub/singularity-hpc/tree/master) (0.0.x)
17+
- Podman support (0.0.25)
1718
- adding namespaces to make module install, show, inspect easier (0.0.24)
1819
- added support for env section to render to bound environment file
1920
- added support for container features like gpu

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
![https://raw.githubusercontent.com/singularityhub/singularity-hpc/main/docs/assets/img/shpc.png](https://raw.githubusercontent.com/singularityhub/singularity-hpc/main/docs/assets/img/shpc.png)
66

7-
Singularity HPC is based off of the [Singularity Registry Client](https://github.com/singularityhub/sregistry-cli), but instead of
8-
being intended for general interaction with Singularity containers and a local database, it's optimized for managing containers
9-
in an HPC environment. Currently, this includes:
7+
Singularity HPC is optimized for managing containers in an HPC environment. Currently, this includes
8+
module technologies:
109

1110
- [LMOD](https://lmod.readthedocs.io/en/latest/)
11+
- [Environment Modules](http://modules.sourceforge.net/)
12+
13+
And container technologies:
14+
15+
- [Singularity](https://github.com/sylabs/singularity)
16+
- [Podman](https://podman.io)
1217

1318
You can use shpc if you are:
1419

@@ -29,11 +34,6 @@ There are other tools that you might be interested in!
2934
- [Community Collections](https://github.com/community-collections/community-collections)
3035
- [Spack](https://spack.readthedocs.io/en/latest/module_file_support.html) installs modules for software built from source (not containers).
3136

32-
## TODOS
33-
34-
- add other registry containers
35-
- the admin that runs shpc should have an easier way to see commands (other than lmod)
36-
- ensure that we print columns to shpc list
3737

3838
## License
3939

shpc/client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def get_parser():
210210
"--container_tech",
211211
dest="container_tech",
212212
help="container technology to use to override settings.yaml",
213-
choices=["singularity"],
213+
choices=["singularity", "podman"],
214214
default=None,
215215
)
216216

shpc/main/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ def get_client(quiet=False, **kwargs):
4040
# Add the container operator
4141
if container == "singularity":
4242
from .container import SingularityContainer
43-
4443
Client._container = SingularityContainer()
4544

45+
elif container == "podman"
46+
from .container import PodmanContainer
47+
Client._container = PodmanContainer()
48+
4649
# Give the user a warning:
4750
if not check_install():
4851
logger.warning("Singularity is not installed, functionality might be limited.")

shpc/main/container.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,95 @@ def _pull_github(self, uri, dest=None):
140140
return self.client.pull(url, name=name, pull_folder=os.path.dirname(dest))
141141

142142

143+
class PodmanContainer(ContainerTechnology):
144+
"""
145+
A Podman container controleer.
146+
"""
147+
148+
# The module technology adds extensions here
149+
templatefile = "podman"
150+
151+
# TODO: how to define gpu for podman
152+
features = {"gpu": {"nvidia": "", "amd": ""}}
153+
154+
def __init__(self):
155+
print("INIT")
156+
import IPython
157+
IPython.embed()
158+
try:
159+
from spython.main import Client
160+
161+
self.client = Client
162+
except:
163+
logger.exit("podman (pip install podman) is required to use podman.")
164+
165+
def shell(self, image):
166+
"""
167+
Interactive shell into a container image.
168+
"""
169+
print("SHELL")
170+
import IPython
171+
IPython.embed()
172+
self.client.shell(image)
173+
174+
def pull(self, uri, dest):
175+
"""
176+
Pull a container to a destination
177+
"""
178+
print("PULL")
179+
import IPython
180+
IPython.embed()
181+
182+
if re.search("^(docker|shub|https)", uri):
183+
return self._pull(uri, dest)
184+
elif uri.startswith("gh://"):
185+
return self._pull_github(uri, dest)
186+
187+
def _pull(self, uri, dest):
188+
"""
189+
Pull a URI that Singularity recognizes
190+
"""
191+
pull_folder = os.path.dirname(dest)
192+
name = os.path.basename(dest)
193+
return self.client.pull(uri, name=name, pull_folder=pull_folder)
194+
195+
def inspect(self, image):
196+
"""
197+
Inspect an image and return metadata.
198+
"""
199+
return self.client.inspect(image)
200+
201+
def _pull_github(self, uri, dest=None):
202+
"""
203+
Pull a singularity-deploy container to a destination
204+
"""
205+
# Assemble the url based on the container uri
206+
uri = uri.replace("gh://", "", 1)
207+
208+
# repository name and image prefix
209+
repo = "/".join(uri.split("/")[0:2])
210+
prefix = repo.replace("/", "-")
211+
212+
# The tag includes release and contianer tag (e.g., 0.0.1:latest)
213+
tag = uri.replace(repo, "", 1).strip("/")
214+
github_tag, container_tag = tag.split(":", 1)
215+
216+
# Assemble the artifact url
217+
url = "https://github.com/%s/releases/download/%s/%s.%s.sif" % (
218+
repo,
219+
github_tag,
220+
prefix,
221+
container_tag,
222+
)
223+
224+
# If no destination, default to present working directory
225+
if not dest:
226+
dest = os.path.basename(url)
227+
name = os.path.basename(dest)
228+
return self.client.pull(url, name=name, pull_folder=os.path.dirname(dest))
229+
230+
231+
143232
class Tags:
144233
"""Make it easy to interact with tags (name and version)"""
145234

shpc/main/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"bindpaths": {"type": ["string", "null"]},
113113
"updated_at": {"type": "string"},
114114
"environment_file": {"type": "string"},
115-
"container_tech": {"type": "string", "enum": ["singularity"]},
115+
"container_tech": {"type": "string", "enum": ["singularity", "podman"]},
116116
"singularity_shell": {"type": "string", "enum": ["/bin/bash", "/bin/sh"]},
117117
"module_sys": {"type": "string", "enum": ["lmod", "tcl", None]},
118118
"container_features": container_features,

shpc/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# please open an issue https://github.com/singularityhub/singularity-hpc
88
module_sys: lmod
99

10-
# set a default container technology (currently only singularity supported)
10+
# set a default container technology (singularity or podman)
1111
container_tech: singularity
1212

1313
# Registry Recipes (currently we support just one path)

0 commit comments

Comments
 (0)