Fix mutation of service.options when a label or environment variable is specified in the config.

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin 2015-08-27 17:42:26 -04:00
commit d264c2e33a
3 changed files with 45 additions and 12 deletions

View file

@ -576,7 +576,6 @@ class Service(object):
number,
one_off=False,
previous_container=None):
add_config_hash = (not one_off and not override_options)
container_options = dict(
@ -589,13 +588,6 @@ class Service(object):
elif not container_options.get('name'):
container_options['name'] = self.get_container_name(number, one_off)
if add_config_hash:
config_hash = self.config_hash
if 'labels' not in container_options:
container_options['labels'] = {}
container_options['labels'][LABEL_CONFIG_HASH] = config_hash
log.debug("Added config hash: %s" % config_hash)
if 'detach' not in container_options:
container_options['detach'] = True
@ -643,7 +635,8 @@ class Service(object):
container_options['labels'] = build_container_labels(
container_options.get('labels', {}),
self.labels(one_off=one_off),
number)
number,
self.config_hash if add_config_hash else None)
# Delete options which are only used when starting
for key in DOCKER_START_KEYS:
@ -899,11 +892,16 @@ def parse_volume_spec(volume_config):
# Labels
def build_container_labels(label_options, service_labels, number, one_off=False):
labels = label_options or {}
def build_container_labels(label_options, service_labels, number, config_hash):
labels = dict(label_options or {})
labels.update(label.split('=', 1) for label in service_labels)
labels[LABEL_CONTAINER_NUMBER] = str(number)
labels[LABEL_VERSION] = __version__
if config_hash:
log.debug("Added config hash: %s" % config_hash)
labels[LABEL_CONFIG_HASH] = config_hash
return labels