Commit f626332a authored by Philip ABBET's avatar Philip ABBET
Browse files

Add a priority mechanism for docker images providing the same environments

parent a02e52d5
......@@ -68,7 +68,7 @@ class Host(object):
self.client = docker.Client(**self.kwargs)
self.environments = self._discover_environments(raise_on_errors=True)
self.environments = self._discover_environments(raise_on_errors=False)
# makes sure we can talk to the docker host
assert self.ip
......@@ -165,11 +165,62 @@ class Host(object):
"uniquely named. Fix this and re-start." % \
(tag or id, retval[key]['image'], key))
else:
logger.warn("Overriding **existing** environment `%s' image " \
"with `%s' (it was `%s). To avoid this warning make " \
"sure your docker images do not contain environments " \
"with the same names", key, retval[key]['image'],
image['Id'])
new_version = None
previous_version = None
parts = tag.split('/')
if len(parts) > 1:
parts = parts[-1].split(':')
if len(parts) > 1:
new_version = parts[-1]
parts = retval[key]['tag'].split('/')
if len(parts) > 1:
parts = parts[-1].split(':')
if len(parts) > 1:
previous_version = parts[-1]
replacement = False
keep = False
if (new_version is not None) and (previous_version is not None):
if new_version == 'latest':
replacement = True
elif previous_version == 'latest':
keep = True
else:
try:
new_version = tuple([ int(x) for x in new_version.split('.') ])
try:
previous_version = tuple([ int(x) for x in previous_version.split('.') ])
if new_version > previous_version:
replacement = True
else:
keep = True
except:
replacement = True
except:
keep = True
elif new_version is not None:
replacement = True
elif previous_version is not None:
keep = True
if replacement:
logger.debug("Overriding **existing** environment `%s' in image `%s'", key, retval[key]['tag'])
elif keep:
logger.debug("Environment `%s' already existing in image `%s', we'll keep it", key, retval[key]['tag'])
continue
else:
logger.warn("Overriding **existing** environment `%s' image " \
"with `%s' (it was `%s). To avoid this warning make " \
"sure your docker images do not contain environments " \
"with the same names", key, retval[key]['image'],
image['Id'])
retval[key] = description
retval[key]['image'] = image['Id']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment