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 e6e5f7a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
18 changes: 17 additions & 1 deletion 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 @@ -371,6 +371,9 @@ def _get_container_create_options(self, override_options, one_off=False):
container_options['environment'] = dict(split_env(e) for e in container_options['environment'])
container_options['environment'] = dict(resolve_env(k, v) for k, v in container_options['environment'].iteritems())

if 'restart' in container_options:
container_options['restart'] = parse_restart_spec(container_options['restart'])

if self.can_be_built():
if len(self.client.images(name=self._build_tag_name())) == 0:
self.build()
Expand Down Expand Up @@ -467,6 +470,19 @@ def get_container_name(container):
return name[1:]


def parse_restart_spec(restart_config):
parts = restart_config.split(':')
if len(parts) > 2:
raise ConfigError("Restart %s has incorrect format, should be "
"mode[:max_retry]" % restart_config)
if len(parts) == 2:
name, max_retry_count = parts
else:
name, = parts
max_retry_count = 0

return { 'name': name, 'maximum_retry_count': max_retry_count }

def parse_volume_spec(volume_config):
parts = volume_config.split(':')
if len(parts) > 3:
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
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('web', 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('web', 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 e6e5f7a

Please sign in to comment.