mirror of https://github.com/docker/compose.git
Add support for init and init_path
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
5a4293848c
commit
cc966a7e19
|
@ -108,6 +108,7 @@ ALLOWED_KEYS = DOCKER_CONFIG_KEYS + [
|
|||
'log_opt',
|
||||
'logging',
|
||||
'network_mode',
|
||||
'init',
|
||||
]
|
||||
|
||||
DOCKER_VALID_URL_PREFIXES = (
|
||||
|
|
|
@ -48,7 +48,7 @@ from .utils import parse_seconds_float
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
DOCKER_START_KEYS = [
|
||||
HOST_CONFIG_KEYS = [
|
||||
'cap_add',
|
||||
'cap_drop',
|
||||
'cgroup_parent',
|
||||
|
@ -60,6 +60,7 @@ DOCKER_START_KEYS = [
|
|||
'env_file',
|
||||
'extra_hosts',
|
||||
'group_add',
|
||||
'init',
|
||||
'ipc',
|
||||
'read_only',
|
||||
'log_driver',
|
||||
|
@ -729,8 +730,8 @@ class Service(object):
|
|||
number,
|
||||
self.config_hash if add_config_hash else None)
|
||||
|
||||
# Delete options which are only used when starting
|
||||
for key in DOCKER_START_KEYS:
|
||||
# Delete options which are only used in HostConfig
|
||||
for key in HOST_CONFIG_KEYS:
|
||||
container_options.pop(key, None)
|
||||
|
||||
container_options['host_config'] = self._get_container_host_config(
|
||||
|
@ -750,8 +751,12 @@ class Service(object):
|
|||
|
||||
logging_dict = options.get('logging', None)
|
||||
log_config = get_log_config(logging_dict)
|
||||
init_path = None
|
||||
if isinstance(options.get('init'), six.string_types):
|
||||
init_path = options.get('init')
|
||||
options['init'] = True
|
||||
|
||||
host_config = self.client.create_host_config(
|
||||
return self.client.create_host_config(
|
||||
links=self._get_links(link_to_self=one_off),
|
||||
port_bindings=build_port_bindings(
|
||||
formatted_ports(options.get('ports', []))
|
||||
|
@ -786,15 +791,12 @@ class Service(object):
|
|||
oom_score_adj=options.get('oom_score_adj'),
|
||||
mem_swappiness=options.get('mem_swappiness'),
|
||||
group_add=options.get('group_add'),
|
||||
userns_mode=options.get('userns_mode')
|
||||
userns_mode=options.get('userns_mode'),
|
||||
init=options.get('init', None),
|
||||
init_path=init_path,
|
||||
isolation=options.get('isolation'),
|
||||
)
|
||||
|
||||
# TODO: Add as an argument to create_host_config once it's supported
|
||||
# in docker-py
|
||||
host_config['Isolation'] = options.get('isolation')
|
||||
|
||||
return host_config
|
||||
|
||||
def get_secret_volumes(self):
|
||||
def build_spec(secret):
|
||||
target = '{}/{}'.format(
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from distutils.spawn import find_executable
|
||||
from os import path
|
||||
|
||||
import pytest
|
||||
|
@ -115,6 +116,21 @@ class ServiceTest(DockerClientTestCase):
|
|||
service.start_container(container)
|
||||
self.assertEqual(container.get('HostConfig.ShmSize'), 67108864)
|
||||
|
||||
def test_create_container_with_init_bool(self):
|
||||
self.require_api_version('1.25')
|
||||
service = self.create_service('db', init=True)
|
||||
container = service.create_container()
|
||||
service.start_container(container)
|
||||
assert container.get('HostConfig.Init') is True
|
||||
|
||||
def test_create_container_with_init_path(self):
|
||||
self.require_api_version('1.25')
|
||||
docker_init_path = find_executable('docker-init')
|
||||
service = self.create_service('db', init=docker_init_path)
|
||||
container = service.create_container()
|
||||
service.start_container(container)
|
||||
assert container.get('HostConfig.InitPath') == docker_init_path
|
||||
|
||||
@pytest.mark.xfail(True, reason='Some kernels/configs do not support pids_limit')
|
||||
def test_create_container_with_pids_limit(self):
|
||||
self.require_api_version('1.23')
|
||||
|
|
|
@ -15,7 +15,7 @@ from compose.const import API_VERSIONS
|
|||
from compose.const import COMPOSEFILE_V1 as V1
|
||||
from compose.const import COMPOSEFILE_V2_0 as V2_0
|
||||
from compose.const import COMPOSEFILE_V2_0 as V2_1
|
||||
from compose.const import COMPOSEFILE_V3_0 as V3_0
|
||||
from compose.const import COMPOSEFILE_V3_2 as V3_2
|
||||
from compose.const import LABEL_PROJECT
|
||||
from compose.progress_stream import stream_output
|
||||
from compose.service import Service
|
||||
|
@ -37,7 +37,7 @@ def get_links(container):
|
|||
|
||||
def engine_max_version():
|
||||
if 'DOCKER_VERSION' not in os.environ:
|
||||
return V3_0
|
||||
return V3_2
|
||||
version = os.environ['DOCKER_VERSION'].partition('-')[0]
|
||||
if version_lt(version, '1.10'):
|
||||
return V1
|
||||
|
@ -45,7 +45,7 @@ def engine_max_version():
|
|||
return V2_0
|
||||
if version_lt(version, '1.13'):
|
||||
return V2_1
|
||||
return V3_0
|
||||
return V3_2
|
||||
|
||||
|
||||
def build_version_required_decorator(ignored_versions):
|
||||
|
|
Loading…
Reference in New Issue