Browse Source

Remove any existing labels with the same key.

master
Chris Smith 7 years ago
parent
commit
c9cfd97e0a
1 changed files with 6 additions and 4 deletions
  1. 6
    4
      docker_rerun.py

+ 6
- 4
docker_rerun.py View File

47
         self.image_info = image_info
47
         self.image_info = image_info
48
         """The image information as returned by `docker inspect`"""
48
         """The image information as returned by `docker inspect`"""
49
 
49
 
50
-
51
     def command_line(self):
50
     def command_line(self):
52
         """Gets the full command-line used to run this container."""
51
         """Gets the full command-line used to run this container."""
53
         return ['docker', 'run'] + sorted(self.args) + [self.image] + self.cmd
52
         return ['docker', 'run'] + sorted(self.args) + [self.image] + self.cmd
54
 
53
 
55
-
56
     def add_args_from_list(self, template, selector):
54
     def add_args_from_list(self, template, selector):
57
         """Adds an argument for each item in a list.
55
         """Adds an argument for each item in a list.
58
 
56
 
64
         if target:
62
         if target:
65
             self.args.extend([template % entry for entry in target])
63
             self.args.extend([template % entry for entry in target])
66
 
64
 
67
-
68
     def if_image_diff(self, selector, fallback):
65
     def if_image_diff(self, selector, fallback):
69
         """Gets a property if it's different from the image's config.
66
         """Gets a property if it's different from the image's config.
70
 
67
 
225
         parser.add_argument('--label', '-l', action='append',
222
         parser.add_argument('--label', '-l', action='append',
226
                             help='The new label to add to the container.')
223
                             help='The new label to add to the container.')
227
     elif args.label:
224
     elif args.label:
228
-        container.args.extend(['--label=%s' % label for label in args.label])
225
+        for label in args.label:
226
+            # Remove any existing label with the same key
227
+            prefix = label.split('=')[0]
228
+            container.args = [arg for arg in container.args if not arg.startswith('--label=%s=' % prefix)
229
+                              and not arg == '--label=%s' % prefix] + ['--label=%s' % label]
229
 
230
 
230
 
231
 
231
 def modify_network(parser=None, args=None, container=None):
232
 def modify_network(parser=None, args=None, container=None):
342
     """Entrypoint for script use."""
343
     """Entrypoint for script use."""
343
     main(sys.argv[1:], sys.stdout)
344
     main(sys.argv[1:], sys.stdout)
344
 
345
 
346
+
345
 if __name__ == "__main__":
347
 if __name__ == "__main__":
346
     entrypoint()
348
     entrypoint()

Loading…
Cancel
Save