Skip to content

Docker socket #13

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
wants to merge 6 commits into from
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
17 changes: 16 additions & 1 deletion cwltool/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ def run(self, dry_run=False, pull_image=True, rm_container=True, rm_tmpdir=True,
env = os.environ
img_id = docker.get_from_requirements(docker_req, docker_is_req, pull_image)

(docker_socket_req, _) = get_feature(self, "DockerSocketRequirement")

gid = os.getgid()

if docker_socket_req:
if kwargs.get("enable_docker_socket") is not True:
raise WorkflowException("DockerSocketRequirement is present but enable_docker_socket is not True")
if docker_socket_req.get("additionalDockerImages"):
for d in docker_socket_req["additionalDockerImages"]:
docker.get_from_requirements(docker_req, True, pull_image)
gid = os.stat("/var/run/docker.sock").st_gid

if docker_is_req and img_id is None:
raise WorkflowException("Docker is required for running this tool.")

Expand All @@ -67,7 +79,7 @@ def run(self, dry_run=False, pull_image=True, rm_container=True, rm_tmpdir=True,
runtime.append("--volume=%s:%s:rw" % (os.path.abspath(self.tmpdir), "/tmp/job_tmp"))
runtime.append("--workdir=%s" % ("/tmp/job_output"))
euid = docker_vm_uid() or os.geteuid()
runtime.append("--user=%s" % (euid))
runtime.append("--user=%s:%s" % (euid, gid))

if rm_container:
runtime.append("--rm")
Expand All @@ -77,6 +89,9 @@ def run(self, dry_run=False, pull_image=True, rm_container=True, rm_tmpdir=True,
for t,v in self.environment.items():
runtime.append("--env=%s=%s" % (t, v))

if docker_socket_req:
runtime.append("--volume=/var/run/docker.sock:/var/run/docker.sock:rw")

runtime.append(img_id)
else:
env = self.environment
Expand Down
12 changes: 10 additions & 2 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ def arg_parser():
dest="move_outputs")

exgroup = parser.add_mutually_exclusive_group()
exgroup.add_argument("--enable-pull", default=True, action="store_true",
exgroup.add_argument("--enable-docker-socket", default=False, action="store_true",
help="Permit DockerSocketRequirement", dest="enable_docker_socket")

exgroup.add_argument("--disable-docker-socket", default=False, action="store_false",
help="Disallow DockerSocketRequirement", dest="enable_docker_socket")

exgroup = parser.add_mutually_exclusive_group()
exgroup.add_argument("--enable-", default=True, action="store_true",
help="Try to pull Docker images", dest="enable_pull")

exgroup.add_argument("--disable-pull", default=True, action="store_false",
Expand Down Expand Up @@ -431,7 +438,8 @@ def main(args=None,
tmpdir_prefix=args.tmpdir_prefix,
rm_tmpdir=args.rm_tmpdir,
makeTool=makeTool,
move_outputs=args.move_outputs
move_outputs=args.move_outputs,
enable_docker_socket=args.enable_docker_socket
)
# This is the workflow output, it needs to be written
stdout.write(json.dumps(out, indent=4))
Expand Down
5 changes: 4 additions & 1 deletion cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"CreateFileRequirement",
"ScatterFeatureRequirement",
"SubworkflowFeatureRequirement",
"MultipleInputFeatureRequirement"]
"MultipleInputFeatureRequirement",
"DockerSocketRequirement"]

def get_schema():
f = resource_stream(__name__, 'schemas/draft-3/cwl-avro.yml')
Expand Down Expand Up @@ -167,6 +168,8 @@ def _init_job(self, joborder, input_basedir, **kwargs):
for r in self.requirements:
if r["class"] not in supportedProcessRequirements:
raise WorkflowException("Unsupported process requirement %s" % (r["class"]))
if r["class"] == "DockerSocketRequirement" and kwargs.get("enable_docker_socket") is not True:
raise WorkflowException("DockerSocketRequirement is present but enable_docker_socket is not True")

builder.files = []
builder.bindings = []
Expand Down
29 changes: 29 additions & 0 deletions cwltool/schemas/draft-2/draft-2/dndtool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class: CommandLineTool
description: "Reverse each line using the `rev` command"
reqirements:
- class: DockerRequirement
dockerId: docker_in_docker
dockerFile: |
FROM ubuntu:14.04
MAINTAINER peter.amstutz@curoverse.com

RUN apt-get update -qq && apt-get install -qqy \
apt-transport-https \
ca-certificates \
curl \
lxc \
iptables \
python-setuptools

# Install Docker from Docker Inc. repositories.
RUN curl -sSL https://get.docker.com/ubuntu/ | sh

- class: DockerSocketRequirement
inputs: []
outputs:
- id: "#output"
type: File
outputBinding:
glob: output.txt
baseCommand: [docker, version]
stdout: output.txt
26 changes: 26 additions & 0 deletions cwltool/schemas/draft-3/cwl-avro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2044,3 +2044,29 @@
the expression engine. The semantics of this field are defined by the
underlying expression engine. Intended for uses such as providing
function definitions that will be called from CWL expressions.


- name: DockerSocketRequirement
type: record
extends: "#ProcessRequirement"
fields:
- name: additionalDockerImages
type:
- "null"
- type: array
items: "#DockerRequirement"
doc: |
Require that the command should have access to the Docker socket at
`/var/run/docker.sock`. If the command is itself run in Docker, this means
the Docker socket must be made available inside the Docker container
through a bind mount.

If this requirement is present, the platform is strongly encouraged to
arrange that file paths are consistent inside and outside the container, as
paths that exist only inside the container cannot be passed to other
containers.

Note there are inherent security problems with providing access to the
Docker socket, so use of this feature should be limited to trusted
environments running trusted workflows. This feature is provided to support
existing container schemes that rely on Docker-in-Docker functionality.
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/add-lines-wf.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/binding-test.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/bwa-mem-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/cat-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/cat-n-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/cat1-tool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/cat2-tool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/cat3-tool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/cat4-tool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/cat5-tool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/count-lines3-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/count-lines4-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/count-lines6-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/echo-tool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/empty.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/env-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/env-tool1.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/env-tool2.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/hello.txt
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/index.py
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/node-engine.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/number.txt
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/parseInt-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/rename-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/rename.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/revsort-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/revtool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/scatter-job1.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/scatter-job2.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/scatter-wf1.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/scatter-wf2.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/search-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/search.py
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/sorttool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/tmap-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/underscore.js
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/wc-job.json
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/wc-tool.cwl
2 changes: 1 addition & 1 deletion cwltool/schemas/draft-3/draft-3/whale.txt