Skip to content

Commit 66f5595

Browse files
committed
fix bug with container add
and expose keep_path to add Signed-off-by: vsoch <[email protected]>
1 parent 2a2e30c commit 66f5595

File tree

7 files changed

+53
-26
lines changed

7 files changed

+53
-26
lines changed

Diff for: CHANGELOG.md

+1
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.com/singularityhub/singularity-hpc/tree/main) (0.0.x)
17+
- Fix bug with container add not respecting container_base (0.1.24)
1718
- Labels with newlines need additional parsing (0.1.23)
1819
- Do not write directly to output with shpc show (0.1.22)
1920
- Podman template bug (0.1.21)

Diff for: shpc/client/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ def get_parser():
103103
help="path to an existing container image for this software",
104104
nargs="?",
105105
)
106-
107-
install.add_argument(
108-
"--keep-path",
109-
help="if installing a local container, do not copy the container - use the provided path.",
110-
default=False,
111-
action="store_true",
112-
)
113-
114106
install.add_argument(
115107
"--no-view",
116108
dest="no_view",
@@ -377,6 +369,14 @@ def get_parser():
377369
action="store_true",
378370
)
379371

372+
for command in install, add:
373+
command.add_argument(
374+
"--keep-path",
375+
help="if using a local container, do not copy the container - use the provided path.",
376+
default=False,
377+
action="store_true",
378+
)
379+
380380
for command in update, sync:
381381
command.add_argument(
382382
"--dry-run",

Diff for: shpc/client/add.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ def main(args, parser, extra, subparser):
2626
cli.reload_registry()
2727

2828
# If we don't have a module name, we derive from container URI
29-
cli.add(args.container_uri, args.module_id)
29+
cli.add(
30+
args.container_uri,
31+
args.module_id,
32+
keep_path=args.keep_path,
33+
)

Diff for: shpc/main/container/singularity.py

+29-12
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def get(self, module_name, env_file=False):
7575
logger.exit("Found more than one sif in module folder.")
7676
return sif[0]
7777

78-
def add(self, module_name, image, config, container_yaml, **kwargs):
78+
def add(
79+
self, module_name, image, config, container_yaml, keep_path=False, **kwargs
80+
):
7981
"""
8082
Manually add a registry container, e.g., generating a container.yaml
8183
for an existing container file. container_yaml is the destination file.
@@ -96,9 +98,11 @@ def add(self, module_name, image, config, container_yaml, **kwargs):
9698
):
9799
return
98100

99-
# Destination for container in registry
100-
dest_dir = os.path.dirname(container_yaml)
101-
utils.mkdir_p(dest_dir)
101+
# Destination for container in registry, either the container.yaml
102+
# path or the container base, if a custom path is desired
103+
if not self.settings.container_base and not keep_path:
104+
dest_dir = os.path.dirname(container_yaml)
105+
utils.mkdir_p(dest_dir)
102106

103107
# Add a docker (or local image) and return the config
104108
if image.startswith("docker://"):
@@ -107,7 +111,13 @@ def add(self, module_name, image, config, container_yaml, **kwargs):
107111
)
108112
else:
109113
config = self._add_local_image(
110-
module_name, tag, image, config, container_yaml, **kwargs
114+
module_name,
115+
tag,
116+
image,
117+
config,
118+
container_yaml,
119+
keep_path=keep_path,
120+
**kwargs,
111121
)
112122

113123
# Final save of config, and tell the user we're done!
@@ -118,7 +128,9 @@ def add(self, module_name, image, config, container_yaml, **kwargs):
118128
print(container_yaml)
119129
return container_yaml
120130

121-
def _add_local_image(self, name, tag, image, config, container_yaml, **kwargs):
131+
def _add_local_image(
132+
self, name, tag, image, config, container_yaml, keep_path=False, **kwargs
133+
):
122134
"""
123135
A subtype of "add" that adds a local image, e.g.,:
124136
@@ -128,14 +140,19 @@ def _add_local_image(self, name, tag, image, config, container_yaml, **kwargs):
128140
logger.exit(f"{image} does not exist.")
129141

130142
digest = utils.get_file_hash(image)
143+
container_digest = "sha256:%s" % digest
131144

132-
# Destination for container in registry
133-
dest_dir = os.path.dirname(container_yaml)
145+
if keep_path:
146+
dest_container = image
147+
container_name = os.path.basename(image)
134148

135-
# The destination container in the registry folder
136-
container_digest = "sha256:%s" % digest
137-
container_name = "%s.sif" % container_digest
138-
dest_container = os.path.join(dest_dir, container_name)
149+
else:
150+
# Destination for container in registry
151+
dest_dir = self.settings.container_base or os.path.dirname(container_yaml)
152+
153+
# The destination container in the registry folder
154+
container_name = "%s.sif" % container_digest
155+
dest_container = os.path.join(dest_dir, container_name)
139156

140157
# Update the config path and latest
141158
config.set("path", container_name)

Diff for: shpc/main/modules/base.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def remove(self, image=None, force=False):
213213
print()
214214
logger.info("Removal complete!")
215215

216-
def add(self, image, module_name=None, **kwargs):
216+
def add(self, image, module_name=None, keep_path=False, **kwargs):
217217
"""
218218
Add a container to the registry to enable install.
219219
"""
@@ -246,7 +246,12 @@ def add(self, image, module_name=None, **kwargs):
246246
registry.FilesystemResult(module_name, template), validate=False
247247
)
248248
return self.container.add(
249-
module_name, image, config, container_yaml=dest, **kwargs
249+
module_name,
250+
image,
251+
config,
252+
container_yaml=dest,
253+
keep_path=keep_path,
254+
**kwargs,
250255
)
251256

252257
def get(self, module_name, env_file=False):

Diff for: shpc/main/modules/module.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def container_dir(self):
7373
self._container_dir = self.container.container_dir(self.module_basepath)
7474
return self._container_dir
7575

76-
def add_container(self, container_image=None):
76+
def add_container(self, container_image=None, keep_path=False):
7777
"""
7878
Ensure a container is pulled (or provided)
7979
@@ -82,7 +82,7 @@ def add_container(self, container_image=None):
8282
# First preference goes to provided image (actual file)
8383
# This is only allowed for Singularity containers
8484
if container_image and os.path.exists(container_image):
85-
self.add_local_container(container_image)
85+
self.add_local_container(container_image, keep_path=keep_path)
8686

8787
# If we have a sif URI provided by path, the container needs to exist
8888
elif self.config.path:

Diff for: shpc/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright 2021-2023, Vanessa Sochat"
33
__license__ = "MPL 2.0"
44

5-
__version__ = "0.1.23"
5+
__version__ = "0.1.24"
66
AUTHOR = "Vanessa Sochat"
77
88
NAME = "singularity-hpc"

0 commit comments

Comments
 (0)