summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2019-04-14 15:07:47 -0700
committerGitHub <noreply@github.com>2019-04-14 15:07:47 -0700
commit1aaa76dc5be1731cd2f5bc2166ad3afea819ea26 (patch)
tree0becd796c808aeb3bff674a72115066761221771
parent5e8b1c0e2ac9fd1a368abed69ced43d8a5c25dff (diff)
parent0d5aacc464df9765bbc54e9aaaaedb14e51b78f7 (diff)
downloaddocker-py-1aaa76dc5be1731cd2f5bc2166ad3afea819ea26.tar.gz
Merge pull request #2297 from hannseman/service-init
Add support for setting init on services
-rw-r--r--docker/api/service.py4
-rw-r--r--docker/models/services.py3
-rw-r--r--docker/types/services.py7
-rw-r--r--tests/integration/api_service_test.py14
4 files changed, 27 insertions, 1 deletions
diff --git a/docker/api/service.py b/docker/api/service.py
index 02f3380..372dd10 100644
--- a/docker/api/service.py
+++ b/docker/api/service.py
@@ -88,6 +88,10 @@ def _check_api_features(version, task_template, update_config, endpoint_spec,
if container_spec.get('Isolation') is not None:
raise_version_error('ContainerSpec.isolation', '1.35')
+ if utils.version_lt(version, '1.38'):
+ if container_spec.get('Init') is not None:
+ raise_version_error('ContainerSpec.init', '1.38')
+
if task_template.get('Resources'):
if utils.version_lt(version, '1.32'):
if task_template['Resources'].get('GenericResources'):
diff --git a/docker/models/services.py b/docker/models/services.py
index 5d2bd9b..2b6479f 100644
--- a/docker/models/services.py
+++ b/docker/models/services.py
@@ -165,6 +165,8 @@ class ServiceCollection(Collection):
env (list of str): Environment variables, in the form
``KEY=val``.
hostname (string): Hostname to set on the container.
+ init (boolean): Run an init inside the container that forwards
+ signals and reaps processes
isolation (string): Isolation technology used by the service's
containers. Only used for Windows containers.
labels (dict): Labels to apply to the service.
@@ -280,6 +282,7 @@ CONTAINER_SPEC_KWARGS = [
'hostname',
'hosts',
'image',
+ 'init',
'isolation',
'labels',
'mounts',
diff --git a/docker/types/services.py b/docker/types/services.py
index a0721f6..5722b0e 100644
--- a/docker/types/services.py
+++ b/docker/types/services.py
@@ -110,13 +110,15 @@ class ContainerSpec(dict):
privileges (Privileges): Security options for the service's containers.
isolation (string): Isolation technology used by the service's
containers. Only used for Windows containers.
+ init (boolean): Run an init inside the container that forwards signals
+ and reaps processes.
"""
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, tty=None, groups=None,
open_stdin=None, read_only=None, stop_signal=None,
healthcheck=None, hosts=None, dns_config=None, configs=None,
- privileges=None, isolation=None):
+ privileges=None, isolation=None, init=None):
self['Image'] = image
if isinstance(command, six.string_types):
@@ -183,6 +185,9 @@ class ContainerSpec(dict):
if isolation is not None:
self['Isolation'] = isolation
+ if init is not None:
+ self['Init'] = init
+
class Mount(dict):
"""
diff --git a/tests/integration/api_service_test.py b/tests/integration/api_service_test.py
index 57a8d33..71e0869 100644
--- a/tests/integration/api_service_test.py
+++ b/tests/integration/api_service_test.py
@@ -850,6 +850,20 @@ class ServiceTest(BaseAPIIntegrationTest):
)
assert privileges['SELinuxContext']['Disable'] is True
+ @requires_api_version('1.38')
+ def test_create_service_with_init(self):
+ container_spec = docker.types.ContainerSpec(
+ 'busybox', ['sleep', '999'], init=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 'Init' in svc_info['Spec']['TaskTemplate']['ContainerSpec']
+ assert (
+ svc_info['Spec']['TaskTemplate']['ContainerSpec']['Init'] is True
+ )
+
@requires_api_version('1.25')
def test_update_service_with_defaults_name(self):
container_spec = docker.types.ContainerSpec(