@@ -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 )
0 commit comments