Merge pull request #2508 from jstewmon/stop_signal

add support for stop_signal to compose file
This commit is contained in:
Aanand Prasad 2016-01-14 12:46:04 +00:00
commit 7733600262
8 changed files with 40 additions and 1 deletions

View File

@ -62,6 +62,7 @@ DOCKER_CONFIG_KEYS = [
'restart',
'security_opt',
'stdin_open',
'stop_signal',
'tty',
'user',
'volume_driver',

View File

@ -94,6 +94,7 @@
"restart": {"type": "string"},
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"stdin_open": {"type": "boolean"},
"stop_signal": {"type": "string"},
"tty": {"type": "boolean"},
"ulimits": {
"type": "object",

View File

@ -101,6 +101,7 @@
"restart": {"type": "string"},
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"stdin_open": {"type": "boolean"},
"stop_signal": {"type": "string"},
"tty": {"type": "boolean"},
"ulimits": {
"type": "object",

View File

@ -107,6 +107,10 @@ class Container(object):
def labels(self):
return self.get('Config.Labels') or {}
@property
def stop_signal(self):
return self.get('Config.StopSignal')
@property
def log_config(self):
return self.get('HostConfig.LogConfig') or None
@ -132,6 +136,10 @@ class Container(object):
def environment(self):
return dict(var.split("=", 1) for var in self.get('Config.Env') or [])
@property
def exit_code(self):
return self.get('State.ExitCode')
@property
def is_running(self):
return self.get('State.Running')

View File

@ -1,8 +1,8 @@
PyYAML==3.11
docker-py==1.6.0
dockerpty==0.3.4
docopt==0.6.1
enum34==1.0.4
git+https://github.com/docker/docker-py.git@master#egg=docker-py
jsonschema==2.5.1
requests==2.7.0
six==1.7.3

View File

@ -739,6 +739,18 @@ class CLITestCase(DockerClientTestCase):
self.assertEqual(len(service.containers(stopped=True)), 1)
self.assertFalse(service.containers(stopped=True)[0].is_running)
def test_stop_signal(self):
self.base_dir = 'tests/fixtures/stop-signal-composefile'
self.dispatch(['up', '-d'], None)
service = self.project.get_service('simple')
self.assertEqual(len(service.containers()), 1)
self.assertTrue(service.containers()[0].is_running)
self.dispatch(['stop', '-t', '1'], None)
self.assertEqual(len(service.containers(stopped=True)), 1)
self.assertFalse(service.containers(stopped=True)[0].is_running)
self.assertEqual(service.containers(stopped=True)[0].exit_code, 0)
def test_start_no_containers(self):
result = self.dispatch(['start'], returncode=1)
assert 'No containers to start' in result.stderr

View File

@ -0,0 +1,10 @@
simple:
image: busybox:latest
command:
- sh
- '-c'
- |
trap 'exit 0' SIGINT
trap 'exit 1' SIGTERM
while true; do :; done
stop_signal: SIGINT

View File

@ -887,6 +887,12 @@ class ServiceTest(DockerClientTestCase):
for name in labels_dict:
self.assertIn((name, ''), labels)
def test_stop_signal(self):
stop_signal = 'SIGINT'
service = self.create_service('web', stop_signal=stop_signal)
container = create_and_start_container(service)
self.assertEqual(container.stop_signal, stop_signal)
def test_custom_container_name(self):
service = self.create_service('web', container_name='my-web-container')
self.assertEqual(service.custom_container_name(), 'my-web-container')