Merge pull request #4163 from aanand/add-healthcheck
Implement 'healthcheck' option
This commit is contained in:
commit
635a281777
9 changed files with 172 additions and 9 deletions
|
|
@ -17,6 +17,7 @@ from ..const import COMPOSEFILE_V2_0 as V2_0
|
|||
from ..const import COMPOSEFILE_V2_1 as V2_1
|
||||
from ..const import COMPOSEFILE_V3_0 as V3_0
|
||||
from ..utils import build_string_dict
|
||||
from ..utils import parse_nanoseconds_int
|
||||
from ..utils import splitdrive
|
||||
from .environment import env_vars_from_file
|
||||
from .environment import Environment
|
||||
|
|
@ -65,6 +66,7 @@ DOCKER_CONFIG_KEYS = [
|
|||
'extra_hosts',
|
||||
'group_add',
|
||||
'hostname',
|
||||
'healthcheck',
|
||||
'image',
|
||||
'ipc',
|
||||
'labels',
|
||||
|
|
@ -642,6 +644,10 @@ def process_service(service_config):
|
|||
if 'extra_hosts' in service_dict:
|
||||
service_dict['extra_hosts'] = parse_extra_hosts(service_dict['extra_hosts'])
|
||||
|
||||
if 'healthcheck' in service_dict:
|
||||
service_dict['healthcheck'] = process_healthcheck(
|
||||
service_dict['healthcheck'], service_config.name)
|
||||
|
||||
for field in ['dns', 'dns_search', 'tmpfs']:
|
||||
if field in service_dict:
|
||||
service_dict[field] = to_list(service_dict[field])
|
||||
|
|
@ -649,6 +655,29 @@ def process_service(service_config):
|
|||
return service_dict
|
||||
|
||||
|
||||
def process_healthcheck(raw, service_name):
|
||||
hc = {}
|
||||
|
||||
if raw.get('disable'):
|
||||
if len(raw) > 1:
|
||||
raise ConfigurationError(
|
||||
'Service "{}" defines an invalid healthcheck: '
|
||||
'"disable: true" cannot be combined with other options'
|
||||
.format(service_name))
|
||||
hc['test'] = ['NONE']
|
||||
elif 'test' in raw:
|
||||
hc['test'] = raw['test']
|
||||
|
||||
if 'interval' in raw:
|
||||
hc['interval'] = parse_nanoseconds_int(raw['interval'])
|
||||
if 'timeout' in raw:
|
||||
hc['timeout'] = parse_nanoseconds_int(raw['timeout'])
|
||||
if 'retries' in raw:
|
||||
hc['retries'] = raw['retries']
|
||||
|
||||
return hc
|
||||
|
||||
|
||||
def finalize_service(service_config, service_names, version, environment):
|
||||
service_dict = dict(service_config.config)
|
||||
|
||||
|
|
|
|||
|
|
@ -205,12 +205,13 @@
|
|||
"interval": {"type":"string"},
|
||||
"timeout": {"type":"string"},
|
||||
"retries": {"type": "number"},
|
||||
"command": {
|
||||
"test": {
|
||||
"oneOf": [
|
||||
{"type": "string"},
|
||||
{"type": "array", "items": {"type": "string"}}
|
||||
]
|
||||
}
|
||||
},
|
||||
"disable": {"type": "boolean"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ from docker.utils.ports import split_port
|
|||
|
||||
from . import __version__
|
||||
from . import progress_stream
|
||||
from . import timeparse
|
||||
from .config import DOCKER_CONFIG_KEYS
|
||||
from .config import merge_environment
|
||||
from .config.types import VolumeSpec
|
||||
|
|
@ -35,6 +34,7 @@ from .parallel import parallel_start
|
|||
from .progress_stream import stream_output
|
||||
from .progress_stream import StreamOutputError
|
||||
from .utils import json_hash
|
||||
from .utils import parse_seconds_float
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
@ -450,7 +450,7 @@ class Service(object):
|
|||
def stop_timeout(self, timeout):
|
||||
if timeout is not None:
|
||||
return timeout
|
||||
timeout = timeparse.timeparse(self.options.get('stop_grace_period') or '')
|
||||
timeout = parse_seconds_float(self.options.get('stop_grace_period'))
|
||||
if timeout is not None:
|
||||
return timeout
|
||||
return DEFAULT_TIMEOUT
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import ntpath
|
|||
import six
|
||||
|
||||
from .errors import StreamParseError
|
||||
from .timeparse import timeparse
|
||||
|
||||
|
||||
json_decoder = json.JSONDecoder()
|
||||
|
|
@ -107,6 +108,21 @@ def microseconds_from_time_nano(time_nano):
|
|||
return int(time_nano % 1000000000 / 1000)
|
||||
|
||||
|
||||
def nanoseconds_from_time_seconds(time_seconds):
|
||||
return time_seconds * 1000000000
|
||||
|
||||
|
||||
def parse_seconds_float(value):
|
||||
return timeparse(value or '')
|
||||
|
||||
|
||||
def parse_nanoseconds_int(value):
|
||||
parsed = timeparse(value or '')
|
||||
if parsed is None:
|
||||
return None
|
||||
return int(parsed * 1000000000)
|
||||
|
||||
|
||||
def build_string_dict(source_dict):
|
||||
return dict((k, str(v if v is not None else '')) for k, v in source_dict.items())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue