Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compose/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'restart',
'security_opt',
'stdin_open',
'stop_signal',
'tty',
'user',
'volume_driver',
Expand Down
1 change: 1 addition & 0 deletions compose/config/service_schema_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions compose/config/service_schema_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions compose/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def format_port(private, public):
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
Expand All @@ -132,6 +136,10 @@ def human_readable_command(self):
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')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/acceptance/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,18 @@ def test_stop(self):
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
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/stop-signal-composefile/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,12 @@ def test_empty_labels(self):
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')
Expand Down