Skip to content

Commit

Permalink
Remove any existing labels with the same key.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Dec 31, 2016
1 parent af72c20 commit c9cfd97
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docker_rerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ def __init__(self, container_info, image_info):
self.image_info = image_info
"""The image information as returned by `docker inspect`"""


def command_line(self):
"""Gets the full command-line used to run this container."""
return ['docker', 'run'] + sorted(self.args) + [self.image] + self.cmd


def add_args_from_list(self, template, selector):
"""Adds an argument for each item in a list.
Expand All @@ -64,7 +62,6 @@ def add_args_from_list(self, template, selector):
if target:
self.args.extend([template % entry for entry in target])


def if_image_diff(self, selector, fallback):
"""Gets a property if it's different from the image's config.
Expand Down Expand Up @@ -225,7 +222,11 @@ def modify_labels(parser=None, args=None, container=None):
parser.add_argument('--label', '-l', action='append',
help='The new label to add to the container.')
elif args.label:
container.args.extend(['--label=%s' % label for label in args.label])
for label in args.label:
# Remove any existing label with the same key
prefix = label.split('=')[0]
container.args = [arg for arg in container.args if not arg.startswith('--label=%s=' % prefix)
and not arg == '--label=%s' % prefix] + ['--label=%s' % label]


def modify_network(parser=None, args=None, container=None):
Expand Down Expand Up @@ -342,5 +343,6 @@ def entrypoint():
"""Entrypoint for script use."""
main(sys.argv[1:], sys.stdout)


if __name__ == "__main__":
entrypoint()

0 comments on commit c9cfd97

Please sign in to comment.