summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-06-21 16:29:25 -0700
committerJoffrey F <joffrey@docker.com>2017-06-21 16:29:25 -0700
commit06d2553b9c3a4c91d1ef2110ea120da15605de2f (patch)
tree1a820abff4e5fe1ef8c8373c77508ab26353de3b
parenta3b1059839ee5314834131f1af9b391fca99bf13 (diff)
downloaddocker-py-06d2553b9c3a4c91d1ef2110ea120da15605de2f.tar.gz
Add support for ContainerSpec.TTY
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--docker/api/service.py5
-rw-r--r--docker/models/services.py2
-rw-r--r--docker/types/services.py6
-rw-r--r--tests/integration/api_service_test.py17
4 files changed, 29 insertions, 1 deletions
diff --git a/docker/api/service.py b/docker/api/service.py
index 0f14776..cc16cc3 100644
--- a/docker/api/service.py
+++ b/docker/api/service.py
@@ -38,6 +38,11 @@ def _check_api_features(version, task_template, update_config):
'Placement.preferences is not supported in'
' API version < 1.27'
)
+ if task_template.container_spec.get('TTY'):
+ if utils.version_lt(version, '1.25'):
+ raise errors.InvalidVersion(
+ 'ContainerSpec.TTY is not supported in API version < 1.25'
+ )
class ServiceApiMixin(object):
diff --git a/docker/models/services.py b/docker/models/services.py
index c10804d..e1e2ea6 100644
--- a/docker/models/services.py
+++ b/docker/models/services.py
@@ -146,6 +146,7 @@ class ServiceCollection(Collection):
of the service. Default: ``None``
user (str): User to run commands as.
workdir (str): Working directory for commands to run.
+ tty (boolean): Whether a pseudo-TTY should be allocated.
Returns:
(:py:class:`Service`) The created service.
@@ -212,6 +213,7 @@ CONTAINER_SPEC_KWARGS = [
'mounts',
'stop_grace_period',
'secrets',
+ 'tty'
]
# kwargs to copy straight over to TaskTemplate
diff --git a/docker/types/services.py b/docker/types/services.py
index 9cec34e..8411b70 100644
--- a/docker/types/services.py
+++ b/docker/types/services.py
@@ -84,10 +84,11 @@ class ContainerSpec(dict):
terminate before forcefully killing it.
secrets (list of py:class:`SecretReference`): List of secrets to be
made available inside the containers.
+ tty (boolean): Whether a pseudo-TTY should be allocated.
"""
def __init__(self, image, command=None, args=None, hostname=None, env=None,
workdir=None, user=None, labels=None, mounts=None,
- stop_grace_period=None, secrets=None):
+ stop_grace_period=None, secrets=None, tty=None):
self['Image'] = image
if isinstance(command, six.string_types):
@@ -125,6 +126,9 @@ class ContainerSpec(dict):
raise TypeError('secrets must be a list')
self['Secrets'] = secrets
+ if tty is not None:
+ self['TTY'] = tty
+
class Mount(dict):
"""
diff --git a/tests/integration/api_service_test.py b/tests/integration/api_service_test.py
index 8ac852d..54111a7 100644
--- a/tests/integration/api_service_test.py
+++ b/tests/integration/api_service_test.py
@@ -359,6 +359,23 @@ class ServiceTest(BaseAPIIntegrationTest):
assert 'Env' in con_spec
assert con_spec['Env'] == ['DOCKER_PY_TEST=1']
+ @requires_api_version('1.25')
+ def test_create_service_with_tty(self):
+ container_spec = docker.types.ContainerSpec(
+ BUSYBOX, ['true'], tty=True
+ )
+ task_tmpl = docker.types.TaskTemplate(
+ container_spec,
+ )
+ name = self.get_service_name()
+ svc_id = self.client.create_service(task_tmpl, name=name)
+ svc_info = self.client.inspect_service(svc_id)
+ assert 'TaskTemplate' in svc_info['Spec']
+ assert 'ContainerSpec' in svc_info['Spec']['TaskTemplate']
+ con_spec = svc_info['Spec']['TaskTemplate']['ContainerSpec']
+ assert 'TTY' in con_spec
+ assert con_spec['TTY'] is True
+
def test_create_service_global_mode(self):
container_spec = docker.types.ContainerSpec(
BUSYBOX, ['echo', 'hello']