Skip to content

Commit 3404fd0

Browse files
misterbrandonwalkerBrandon Walker
andauthored
rename singularity image (#1956)
Co-authored-by: Brandon Walker <[email protected]>
1 parent a84911d commit 3404fd0

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

cwltool/singularity.py

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,29 +171,44 @@ def get_image(
171171
cache_folder = create_tmp_dir(tmp_outdir_prefix)
172172

173173
absolute_path = os.path.abspath(cache_folder)
174-
dockerfile_path = os.path.join(absolute_path, "Dockerfile")
175-
singularityfile_path = dockerfile_path + ".def"
176-
# if you do not set APPTAINER_TMPDIR will crash
177-
# WARNING: 'nodev' mount option set on /tmp, it could be a
178-
# source of failure during build process
179-
# FATAL: Unable to create build: 'noexec' mount option set on
180-
# /tmp, temporary root filesystem won't be usable at this location
181-
with open(dockerfile_path, "w") as dfile:
182-
dfile.write(dockerRequirement["dockerFile"])
183-
184-
singularityfile = SingularityWriter(DockerParser(dockerfile_path).parse()).convert()
185-
with open(singularityfile_path, "w") as file:
186-
file.write(singularityfile)
187-
188-
os.environ["APPTAINER_TMPDIR"] = absolute_path
189-
singularity_options = ["--fakeroot"] if not shutil.which("proot") else []
190-
Client.build(
191-
recipe=singularityfile_path,
192-
build_folder=absolute_path,
193-
sudo=False,
194-
options=singularity_options,
195-
)
196-
found = True
174+
if "dockerImageId" in dockerRequirement:
175+
image_name = dockerRequirement["dockerImageId"]
176+
image_path = os.path.join(absolute_path, image_name)
177+
if os.path.exists(image_path):
178+
found = True
179+
if found is False:
180+
dockerfile_path = os.path.join(absolute_path, "Dockerfile")
181+
singularityfile_path = dockerfile_path + ".def"
182+
# if you do not set APPTAINER_TMPDIR will crash
183+
# WARNING: 'nodev' mount option set on /tmp, it could be a
184+
# source of failure during build process
185+
# FATAL: Unable to create build: 'noexec' mount option set on
186+
# /tmp, temporary root filesystem won't be usable at this location
187+
with open(dockerfile_path, "w") as dfile:
188+
dfile.write(dockerRequirement["dockerFile"])
189+
190+
singularityfile = SingularityWriter(DockerParser(dockerfile_path).parse()).convert()
191+
with open(singularityfile_path, "w") as file:
192+
file.write(singularityfile)
193+
194+
os.environ["APPTAINER_TMPDIR"] = absolute_path
195+
singularity_options = ["--fakeroot"] if not shutil.which("proot") else []
196+
if "dockerImageId" in dockerRequirement:
197+
Client.build(
198+
recipe=singularityfile_path,
199+
build_folder=absolute_path,
200+
image=dockerRequirement["dockerImageId"],
201+
sudo=False,
202+
options=singularity_options,
203+
)
204+
else:
205+
Client.build(
206+
recipe=singularityfile_path,
207+
build_folder=absolute_path,
208+
sudo=False,
209+
options=singularity_options,
210+
)
211+
found = True
197212
elif "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement:
198213
match = re.search(pattern=r"([a-z]*://)", string=dockerRequirement["dockerPull"])
199214
img_name = _normalize_image_id(dockerRequirement["dockerPull"])
@@ -326,7 +341,13 @@ def get_from_requirements(
326341
if not self.get_image(cast(Dict[str, str], r), pull_image, tmp_outdir_prefix, force_pull):
327342
raise WorkflowException("Container image {} not found".format(r["dockerImageId"]))
328343

329-
return os.path.abspath(cast(str, r["dockerImageId"]))
344+
if "CWL_SINGULARITY_CACHE" in os.environ:
345+
cache_folder = os.environ["CWL_SINGULARITY_CACHE"]
346+
img_path = os.path.join(cache_folder, cast(str, r["dockerImageId"]))
347+
else:
348+
img_path = cast(str, r["dockerImageId"])
349+
350+
return os.path.abspath(img_path)
330351

331352
@staticmethod
332353
def append_volume(runtime: List[str], source: str, target: str, writable: bool = False) -> None:

0 commit comments

Comments
 (0)