Browse Source

Use sets to diff env vars.

I was trying to preserve the ordering, but we sort all the args
anyway. Using sets and subtracting them performs much better than
list comprehensions.
tags/v0.1.1
Chris Smith 7 years ago
parent
commit
fc389cf3ef
2 changed files with 4 additions and 4 deletions
  1. 3
    3
      docker-rerun
  2. 1
    1
      test.py

+ 3
- 3
docker-rerun View File

@@ -112,9 +112,9 @@ def handle_command(container):
112 112
 
113 113
 def handle_environment(container):
114 114
     """Copies the environment (-e/--env) arguments."""
115
-    container_env = container.info['Config']['Env'] or []
116
-    image_env = container.image_info['Config']['Env'] or []
117
-    delta = [e for e in container_env if e not in image_env]
115
+    container_env = set(container.info['Config']['Env'] or [])
116
+    image_env = set(container.image_info['Config']['Env'] or [])
117
+    delta = container_env - image_env
118 118
     container.args.extend(['--env=%s' % env for env in delta])
119 119
 
120 120
 

+ 1
- 1
test.py View File

@@ -15,7 +15,7 @@ def _run(cmd):
15 15
     ['docker', 'run', '--name=test123', '-d', 'hello-world:latest'],
16 16
     ['docker', 'run', '--name=test123', '-d', 'hello-world', '/hello', 'world...'],
17 17
     ['docker', 'run', '--env=PATH=/root', '--env=Z=X', '--name=test123', '-d', 'hello-world'],
18
-    ['docker', 'run', '--env=FOO=bar baz', '--name=test1234', '-d', 'hello-world'],
18
+    ['docker', 'run', '--env=FOO=bar baz', '--name=test123', '-d', 'hello-world'],
19 19
     ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world'],
20 20
     ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world'],
21 21
     ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world'],

Loading…
Cancel
Save