diff --git a/pyccc/engines/dockerengine.py b/pyccc/engines/dockerengine.py index 175b247..d7120c3 100644 --- a/pyccc/engines/dockerengine.py +++ b/pyccc/engines/dockerengine.py @@ -89,31 +89,30 @@ def _generate_container_args(self, job): if job.env: container_args['environment'].update(job.env) - if job.engine_options: - volumes = [] - binds = [] - - # mount the docker socket into the container - if job.engine_options.get('mount_docker_socket', False): - volumes.append('/var/run/docker.sock') - binds.append('/var/run/docker.sock:/var/run/docker.sock:rw') - - # handle other mounted volumes - for volume, mount in job.engine_options.get('volumes', {}).items(): - if isinstance(mount, (list, tuple)): - mountpoint, mode = mount - bind = '%s:%s:%s' % (volume, mountpoint, mode) - else: - mountpoint = mount - mode = None - bind = '%s:%s' % (volume, mountpoint) - - volumes.append(mountpoint) - binds.append(bind) - - if volumes or binds: - container_args['volumes'] = volumes - container_args['host_config'] = self.client.create_host_config(binds=binds) + volumes = [] + binds = [] + + # mount the docker socket into the container (two ways to do this for backwards compat.) + if job.withdocker or job.engine_options.get('mount_docker_socket', False): + volumes.append('/var/run/docker.sock') + binds.append('/var/run/docker.sock:/var/run/docker.sock:rw') + + # handle other mounted volumes + for volume, mount in job.engine_options.get('volumes', {}).items(): + if isinstance(mount, (list, tuple)): + mountpoint, mode = mount + bind = '%s:%s:%s' % (volume, mountpoint, mode) + else: + mountpoint = mount + mode = None + bind = '%s:%s' % (volume, mountpoint) + + volumes.append(mountpoint) + binds.append(bind) + + if volumes or binds: + container_args['volumes'] = volumes + container_args['host_config'] = self.client.create_host_config(binds=binds) return container_args diff --git a/pyccc/job.py b/pyccc/job.py index b86c566..1525bb6 100644 --- a/pyccc/job.py +++ b/pyccc/job.py @@ -64,6 +64,7 @@ class Job(object): contents (which can be either a FileContainer or just a string) on_status_update (callable): function that can be called as ``func(job)``; will be called locally whenever the job's status field is updated + withdocker (bool): whether this job needs access to a docker daemon when_finished (callable): function that can be called as ``func(job)``; will be called locally once, when this job completes numcpus (int): number of CPUs required (default:1) @@ -79,7 +80,7 @@ def __init__(self, engine=None, name='untitled', submit=True, inputs=None, - requirements=None, + withdocker=False, numcpus=1, runtime=3600, on_status_update=None, @@ -92,7 +93,7 @@ def __init__(self, engine=None, self.engine = engine self.image = image self.command = if_not_none(command, '') - self.engine_options = engine_options + self.engine_options = if_not_none(engine_options, {}) self.workingdir = workingdir self.env = env @@ -104,11 +105,11 @@ def __init__(self, engine=None, else: self.inputs[filename] = fileobj - self.requirements = if_not_none(requirements, {}) self.on_status_update = on_status_update self.when_finished = when_finished self.numcpus = numcpus self.runtime = runtime + self.withdocker = withdocker self._reset() diff --git a/pyccc/tests/test_job_types.py b/pyccc/tests/test_job_types.py index c3d3660..f136b7a 100644 --- a/pyccc/tests/test_job_types.py +++ b/pyccc/tests/test_job_types.py @@ -347,9 +347,10 @@ def _runcall(fixture, request, function, *args, **kwargs): job.wait() return job.result + @pytest.mark.skipif('CI_PROJECT_ID' in os.environ, reason="Can't mount docker socket in codeship") -def test_docker_socket_mount(local_docker_engine): +def test_docker_socket_mount_with_engine_option(local_docker_engine): engine = local_docker_engine job = engine.launch(image='docker', @@ -360,6 +361,19 @@ def test_docker_socket_mount(local_docker_engine): assert job.jobid in running +@pytest.mark.skipif('CI_PROJECT_ID' in os.environ, + reason="Can't mount docker socket in codeship") +def test_docker_socket_mount_withdocker_option(local_docker_engine): + engine = local_docker_engine + + job = engine.launch(image='docker', + command='docker ps -q --no-trunc', + withdocker=True) + job.wait() + running = job.stdout.strip().splitlines() + assert job.jobid in running + + def test_docker_volume_mount(local_docker_engine): """ Note: