Skip to content

Added singularity in a few places. Runs but permanentfails #487

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

Closed
Show file tree
Hide file tree
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
59 changes: 32 additions & 27 deletions cwltool/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,44 @@
def get_image(dockerRequirement, pull_image, dry_run=False):
# type: (Dict[Text, Text], bool, bool) -> bool
found = False

if "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement:
dockerRequirement["dockerImageId"] = dockerRequirement["dockerPull"]

for ln in subprocess.check_output(
["docker", "images", "--no-trunc", "--all"]).decode('utf-8').splitlines():
try:
m = re.match(r"^([^ ]+)\s+([^ ]+)\s+([^ ]+)", ln)
sp = dockerRequirement["dockerImageId"].split(":")
if len(sp) == 1:
sp.append("latest")
elif len(sp) == 2:
# if sp[1] doesn't match valid tag names, it is a part of repository
if not re.match(r'[\w][\w.-]{0,127}', sp[1]):
sp[0] = sp[0] + ":" + sp[1]
sp[1] = "latest"
elif len(sp) == 3:
if re.match(r'[\w][\w.-]{0,127}', sp[2]):
sp[0] = sp[0] + ":" + sp[1]
sp[1] = sp[2]
del sp[2]

# check for repository:tag match or image id match
if ((sp[0] == m.group(1) and sp[1] == m.group(2)) or dockerRequirement["dockerImageId"] == m.group(3)):
found = True
break
except ValueError:
pass
#DEBUG: CHECKS IMAGE REGISTRY FOR IDS. SINGULARITY EQ WOULD BE TO CHECK THE FOLDER FOR IMG.
#'node:slim'
imageString = dockerRequirement["dockerPull"].split(":")
imageHit = "{}-{}.img".format(imageString[0], imageString[1])
if imageHit:
found = True
# for ln in subprocess.check_output(
# ["docker", "images", "--no-trunc", "--all"]).decode('utf-8').splitlines():
# try:
# m = re.match(r"^([^ ]+)\s+([^ ]+)\s+([^ ]+)", ln)
# sp = dockerRequirement["dockerImageId"].split(":")
# if len(sp) == 1:
# sp.append("latest")
# elif len(sp) == 2:
# # if sp[1] doesn't match valid tag names, it is a part of repository
# if not re.match(r'[\w][\w.-]{0,127}', sp[1]):
# sp[0] = sp[0] + ":" + sp[1]
# sp[1] = "latest"
# elif len(sp) == 3:
# if re.match(r'[\w][\w.-]{0,127}', sp[2]):
# sp[0] = sp[0] + ":" + sp[1]
# sp[1] = sp[2]
# del sp[2]
#
# # check for repository:tag match or image id match
# if ((sp[0] == m.group(1) and sp[1] == m.group(2)) or dockerRequirement["dockerImageId"] == m.group(3)):
# found = True
# break
# except ValueError:
# pass

if not found and pull_image:
cmd = [] # type: List[Text]
if "dockerPull" in dockerRequirement:
cmd = ["docker", "pull", str(dockerRequirement["dockerPull"])]
cmd = ["singularity", "pull", "docker://" + str(dockerRequirement["dockerPull"])]
_logger.info(Text(cmd))
if not dry_run:
subprocess.check_call(cmd, stdout=sys.stderr)
Expand Down Expand Up @@ -103,7 +108,7 @@ def get_from_requirements(r, req, pull_image, dry_run=False):
if r:
errmsg = None
try:
subprocess.check_output(["docker", "version"])
subprocess.check_output(["singularity", "--version"])
except subprocess.CalledProcessError as e:
errmsg = "Cannot communicate with docker daemon: " + Text(e)
except OSError as e:
Expand Down
44 changes: 24 additions & 20 deletions cwltool/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,25 +316,25 @@ def add_volumes(self, pathmapper, runtime, stage_output):
containertgt = vol.target
if vol.type in ("File", "Directory"):
if not vol.resolved.startswith("_:"):
runtime.append(u"--volume=%s:%s:ro" % (docker_windows_path_adjust(vol.resolved), docker_windows_path_adjust(containertgt)))
runtime.append(u"--bind=%s:%s:ro" % (docker_windows_path_adjust(vol.resolved), docker_windows_path_adjust(containertgt)))
elif vol.type == "WritableFile":
if self.inplace_update:
runtime.append(u"--volume=%s:%s:rw" % (docker_windows_path_adjust(vol.resolved), docker_windows_path_adjust(containertgt)))
runtime.append(u"--bind=%s:%s:rw" % (docker_windows_path_adjust(vol.resolved), docker_windows_path_adjust(containertgt)))
else:
shutil.copy(vol.resolved, vol.target)
elif vol.type == "WritableDirectory":
if vol.resolved.startswith("_:"):
os.makedirs(vol.target, 0o0755)
else:
if self.inplace_update:
runtime.append(u"--volume=%s:%s:rw" % (docker_windows_path_adjust(vol.resolved), docker_windows_path_adjust(containertgt)))
runtime.append(u"--bind=%s:%s:rw" % (docker_windows_path_adjust(vol.resolved), docker_windows_path_adjust(containertgt)))
else:
shutil.copytree(vol.resolved, vol.target)
elif vol.type == "CreateFile":
createtmp = os.path.join(host_outdir, os.path.basename(vol.target))
with open(createtmp, "wb") as f:
f.write(vol.resolved.encode("utf-8"))
runtime.append(u"--volume=%s:%s:ro" % (docker_windows_path_adjust(createtmp), docker_windows_path_adjust(vol.target)))
runtime.append(u"--bind=%s:%s:ro" % (docker_windows_path_adjust(createtmp), docker_windows_path_adjust(vol.target)))


def run(self, pull_image=True, rm_container=True,
Expand All @@ -348,6 +348,7 @@ def run(self, pull_image=True, rm_container=True,
try:
env = cast(MutableMapping[Text, Text], os.environ)
if docker_req and kwargs.get("use_container") is not False:
print "Req docker"
img_id = docker.get_from_requirements(docker_req, True, pull_image)
if img_id is None:
find_default_container = self.builder.find_default_container
Expand All @@ -370,25 +371,28 @@ def run(self, pull_image=True, rm_container=True,

self._setup()

runtime = [u"docker", u"run", u"-i"]
runtime = [u"singularity", u"exec"]

runtime.append(u"--volume=%s:%s:rw" % (docker_windows_path_adjust(os.path.realpath(self.outdir)), self.builder.outdir))
runtime.append(u"--volume=%s:%s:rw" % (docker_windows_path_adjust(os.path.realpath(self.tmpdir)), "/tmp"))
runtime.append(u"--bind=%s:%s:rw" % (docker_windows_path_adjust(os.path.realpath(self.outdir)), self.builder.outdir))
runtime.append(u"--bind=%s:%s:rw" % (docker_windows_path_adjust(os.path.realpath(self.tmpdir)), "/tmp"))

self.add_volumes(self.pathmapper, runtime, False)
if self.generatemapper:
self.add_volumes(self.generatemapper, runtime, True)

runtime.append(u"--workdir=%s" % (docker_windows_path_adjust(self.builder.outdir)))
runtime.append(u"--read-only=true")
runtime.append(u"--pwd=%s" % (docker_windows_path_adjust(self.builder.outdir)))
# runtime.append(u"--read-only=true") # true by default for Singularity images

if kwargs.get("custom_net", None) is not None:
runtime.append(u"--net={0}".format(kwargs.get("custom_net")))
elif kwargs.get("disable_net", None):
runtime.append(u"--net=none")
# runtime.append(u"--net={0}".format(kwargs.get("custom_net")))
raise UnsupportedRequirement(
"Singularity implementation does not support networking")
# elif kwargs.get("disable_net", None):
# runtime.append(u"--net=none")

if self.stdout:
runtime.append("--log-driver=none")
# No equivalent flag in Singularity
# if self.stdout:
# runtime.append("--log-driver=none")

if onWindows(): # windows os dont have getuid or geteuid functions
euid = docker_vm_uid()
Expand All @@ -398,18 +402,18 @@ def run(self, pull_image=True, rm_container=True,
if kwargs.get("no_match_user", None) is False and euid is not None:
runtime.append(u"--user=%s" % (euid))

if rm_container:
runtime.append(u"--rm")

runtime.append(u"--env=TMPDIR=/tmp")
# No equivalent
# if rm_container:
# runtime.append(u"--rm")
runtime.insert(0, u"SINGULARITYENV_TMPDIR=/tmp")

# spec currently says "HOME must be set to the designated output
# directory." but spec might change to designated temp directory.
# runtime.append("--env=HOME=/tmp")
runtime.append(u"--env=HOME=%s" % self.builder.outdir)
runtime.insert(0, u"SINGULARITYENV_HOME=%s" % self.builder.outdir)

for t, v in self.environment.items():
runtime.append(u"--env=%s=%s" % (t, v))
runtime.insert(0, u"SINGULARITYENV_%s=%s" % (t, v))

runtime.append(img_id)

Expand Down