Skip to content

Commit

Permalink
Add restart option to Fig. Related to docker#478
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Bonaud <paul@bonaud.fr>
  • Loading branch information
paulRbr committed Oct 28, 2014
1 parent 11280e4 commit 3dcda4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions fig/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
log = logging.getLogger(__name__)


DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'domainname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'entrypoint', 'privileged', 'volumes_from', 'net', 'working_dir']
DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'domainname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'entrypoint', 'privileged', 'volumes_from', 'net', 'working_dir', 'restart']
DOCKER_CONFIG_HINTS = {
'link' : 'links',
'port' : 'ports',
Expand Down Expand Up @@ -262,6 +262,7 @@ def start_container(self, container=None, intermediate_container=None, **overrid
privileged = options.get('privileged', False)
net = options.get('net', 'bridge')
dns = options.get('dns', None)
restart = options.get('restart', None)

container.start(
links=self._get_links(link_to_self=options.get('one_off', False)),
Expand All @@ -271,6 +272,7 @@ def start_container(self, container=None, intermediate_container=None, **overrid
privileged=privileged,
network_mode=net,
dns=dns,
restart_policy=restart
)
return container

Expand Down Expand Up @@ -377,7 +379,7 @@ def _get_container_create_options(self, override_options, one_off=False):
container_options['image'] = self._build_tag_name()

# Delete options which are only used when starting
for key in ['privileged', 'net', 'dns']:
for key in ['privileged', 'net', 'dns', 'restart']:
if key in container_options:
del container_options[key]

Expand Down
13 changes: 12 additions & 1 deletion tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_start_container_creates_fixed_external_ports(self):
def test_start_container_creates_fixed_external_ports_when_it_is_different_to_internal_port(self):
service = self.create_service('web', ports=['8001:8000'])
container = service.start_container().inspect()
self.assertIn('8000/tcp', container['NetworkSettings']['Ports'])
self.assertIn('8000/tcp', containe['NetworkSettings']['Ports'])
self.assertEqual(container['NetworkSettings']['Ports']['8000/tcp'][0]['HostPort'], '8001')

def test_port_with_explicit_interface(self):
Expand Down Expand Up @@ -365,6 +365,17 @@ def test_dns_list(self):
container = service.start_container().inspect()
self.assertEqual(container['HostConfig']['Dns'], ['8.8.8.8', '9.9.9.9'])

def test_restart_always_value(self):
service = self.create_service('restart', restart='always')
container = service.start_container().inspect()
self.assertEqual(container['HostConfig']['RestartPolicy']['Name'], 'always')

def test_restart_on_failure_value(self):
service = self.create_service('restart', restart='on-failure:5')
container = service.start_container().inspect()
self.assertEqual(container['HostConfig']['RestartPolicy']['Name'], 'on-failure')
self.assertEqual(container['HostConfig']['RestartPolicy']['MaximumRetryCount'], '5')

def test_working_dir_param(self):
service = self.create_service('container', working_dir='/working/dir/sample')
container = service.create_container().inspect()
Expand Down

0 comments on commit 3dcda4c

Please sign in to comment.