Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug with container add #656

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/main) (0.0.x)
- Fix bug with container add not respecting container_base (0.1.24)
- Labels with newlines need additional parsing (0.1.23)
- Do not write directly to output with shpc show (0.1.22)
- Podman template bug (0.1.21)
Expand Down
16 changes: 8 additions & 8 deletions shpc/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ def get_parser():
help="path to an existing container image for this software",
nargs="?",
)

install.add_argument(
"--keep-path",
help="if installing a local container, do not copy the container - use the provided path.",
default=False,
action="store_true",
)

install.add_argument(
"--no-view",
dest="no_view",
Expand Down Expand Up @@ -377,6 +369,14 @@ def get_parser():
action="store_true",
)

for command in install, add:
command.add_argument(
"--keep-path",
help="if using a local container, do not copy the container - use the provided path.",
default=False,
action="store_true",
)

for command in update, sync:
command.add_argument(
"--dry-run",
Expand Down
6 changes: 5 additions & 1 deletion shpc/client/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ def main(args, parser, extra, subparser):
cli.reload_registry()

# If we don't have a module name, we derive from container URI
cli.add(args.container_uri, args.module_id)
cli.add(
args.container_uri,
args.module_id,
keep_path=args.keep_path,
)
37 changes: 27 additions & 10 deletions shpc/main/container/singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def get(self, module_name, env_file=False):
logger.exit("Found more than one sif in module folder.")
return sif[0]

def add(self, module_name, image, config, container_yaml, **kwargs):
def add(
self, module_name, image, config, container_yaml, keep_path=False, **kwargs
):
"""
Manually add a registry container, e.g., generating a container.yaml
for an existing container file. container_yaml is the destination file.
Expand All @@ -96,7 +98,7 @@ def add(self, module_name, image, config, container_yaml, **kwargs):
):
return

# Destination for container in registry
# Destination for container in registry for container.yaml
dest_dir = os.path.dirname(container_yaml)
utils.mkdir_p(dest_dir)

Expand All @@ -107,7 +109,13 @@ def add(self, module_name, image, config, container_yaml, **kwargs):
)
else:
config = self._add_local_image(
module_name, tag, image, config, container_yaml, **kwargs
module_name,
tag,
image,
config,
container_yaml,
keep_path=keep_path,
**kwargs,
)

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

def _add_local_image(self, name, tag, image, config, container_yaml, **kwargs):
def _add_local_image(
self, name, tag, image, config, container_yaml, keep_path=False, **kwargs
):
"""
A subtype of "add" that adds a local image, e.g.,:

Expand All @@ -128,14 +138,21 @@ def _add_local_image(self, name, tag, image, config, container_yaml, **kwargs):
logger.exit(f"{image} does not exist.")

digest = utils.get_file_hash(image)
container_digest = "sha256:%s" % digest

# Destination for container in registry
dest_dir = os.path.dirname(container_yaml)
if keep_path:
dest_container = image
container_name = os.path.basename(image)

# The destination container in the registry folder
container_digest = "sha256:%s" % digest
container_name = "%s.sif" % container_digest
dest_container = os.path.join(dest_dir, container_name)
else:
# Destination for container in registry
container_dir = self.container_dir(name)
dest_dir = container_dir or os.path.dirname(container_yaml)
utils.mkdir_p(dest_dir)

# The destination container in the registry folder
container_name = "%s.sif" % container_digest
dest_container = os.path.join(dest_dir, container_name)

# Update the config path and latest
config.set("path", container_name)
Expand Down
9 changes: 7 additions & 2 deletions shpc/main/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def remove(self, image=None, force=False):
print()
logger.info("Removal complete!")

def add(self, image, module_name=None, **kwargs):
def add(self, image, module_name=None, keep_path=False, **kwargs):
"""
Add a container to the registry to enable install.
"""
Expand Down Expand Up @@ -246,7 +246,12 @@ def add(self, image, module_name=None, **kwargs):
registry.FilesystemResult(module_name, template), validate=False
)
return self.container.add(
module_name, image, config, container_yaml=dest, **kwargs
module_name,
image,
config,
container_yaml=dest,
keep_path=keep_path,
**kwargs,
)

def get(self, module_name, env_file=False):
Expand Down
4 changes: 2 additions & 2 deletions shpc/main/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def container_dir(self):
self._container_dir = self.container.container_dir(self.module_basepath)
return self._container_dir

def add_container(self, container_image=None):
def add_container(self, container_image=None, keep_path=False):
"""
Ensure a container is pulled (or provided)

Expand All @@ -82,7 +82,7 @@ def add_container(self, container_image=None):
# First preference goes to provided image (actual file)
# This is only allowed for Singularity containers
if container_image and os.path.exists(container_image):
self.add_local_container(container_image)
self.add_local_container(container_image, keep_path=keep_path)

# If we have a sif URI provided by path, the container needs to exist
elif self.config.path:
Expand Down
2 changes: 1 addition & 1 deletion shpc/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__copyright__ = "Copyright 2021-2023, Vanessa Sochat"
__license__ = "MPL 2.0"

__version__ = "0.1.23"
__version__ = "0.1.24"
AUTHOR = "Vanessa Sochat"
EMAIL = "vsoch@users.noreply.github.com"
NAME = "singularity-hpc"
Expand Down