Unverified Kaydet (Commit) 1aaa76dc authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

Merge pull request #2297 from hannseman/service-init

Add support for setting init on services
......@@ -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'):
......
......@@ -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',
......
......@@ -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):
"""
......
......@@ -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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment