Skip to content

rename singularity image #1956

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 45 additions & 24 deletions cwltool/singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,29 +171,44 @@ def get_image(
cache_folder = create_tmp_dir(tmp_outdir_prefix)

absolute_path = os.path.abspath(cache_folder)
dockerfile_path = os.path.join(absolute_path, "Dockerfile")
singularityfile_path = dockerfile_path + ".def"
# if you do not set APPTAINER_TMPDIR will crash
# WARNING: 'nodev' mount option set on /tmp, it could be a
# source of failure during build process
# FATAL: Unable to create build: 'noexec' mount option set on
# /tmp, temporary root filesystem won't be usable at this location
with open(dockerfile_path, "w") as dfile:
dfile.write(dockerRequirement["dockerFile"])

singularityfile = SingularityWriter(DockerParser(dockerfile_path).parse()).convert()
with open(singularityfile_path, "w") as file:
file.write(singularityfile)

os.environ["APPTAINER_TMPDIR"] = absolute_path
singularity_options = ["--fakeroot"] if not shutil.which("proot") else []
Client.build(
recipe=singularityfile_path,
build_folder=absolute_path,
sudo=False,
options=singularity_options,
)
found = True
if "dockerImageId" in dockerRequirement:
image_name = dockerRequirement["dockerImageId"]
image_path = os.path.join(absolute_path, image_name)
if os.path.exists(image_path):
found = True
if found is False:
dockerfile_path = os.path.join(absolute_path, "Dockerfile")
singularityfile_path = dockerfile_path + ".def"
# if you do not set APPTAINER_TMPDIR will crash
# WARNING: 'nodev' mount option set on /tmp, it could be a
# source of failure during build process
# FATAL: Unable to create build: 'noexec' mount option set on
# /tmp, temporary root filesystem won't be usable at this location
with open(dockerfile_path, "w") as dfile:
dfile.write(dockerRequirement["dockerFile"])

singularityfile = SingularityWriter(DockerParser(dockerfile_path).parse()).convert()
with open(singularityfile_path, "w") as file:
file.write(singularityfile)

os.environ["APPTAINER_TMPDIR"] = absolute_path
singularity_options = ["--fakeroot"] if not shutil.which("proot") else []
if "dockerImageId" in dockerRequirement:
Client.build(
recipe=singularityfile_path,
build_folder=absolute_path,
image=dockerRequirement["dockerImageId"],
sudo=False,
options=singularity_options,
)
else:
Client.build(
recipe=singularityfile_path,
build_folder=absolute_path,
sudo=False,
options=singularity_options,
)
found = True
elif "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement:
match = re.search(pattern=r"([a-z]*://)", string=dockerRequirement["dockerPull"])
img_name = _normalize_image_id(dockerRequirement["dockerPull"])
Expand Down Expand Up @@ -326,7 +341,13 @@ def get_from_requirements(
if not self.get_image(cast(Dict[str, str], r), pull_image, tmp_outdir_prefix, force_pull):
raise WorkflowException("Container image {} not found".format(r["dockerImageId"]))

return os.path.abspath(cast(str, r["dockerImageId"]))
if "CWL_SINGULARITY_CACHE" in os.environ:
cache_folder = os.environ["CWL_SINGULARITY_CACHE"]
img_path = os.path.join(cache_folder, cast(str, r["dockerImageId"]))
else:
img_path = cast(str, r["dockerImageId"])

return os.path.abspath(img_path)

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