Browse Source

Support for env vars

tags/v0.1.1
Chris Smith 7 years ago
parent
commit
8e96d1e448
3 changed files with 25 additions and 14 deletions
  1. 2
    1
      README.md
  2. 8
    0
      docker-rerun
  3. 15
    13
      test.py

+ 2
- 1
README.md View File

@@ -27,17 +27,18 @@ option:
27 27
 At present docker-rerun supports a small number of commonly used arguments:
28 28
 
29 29
     * Commands (trailing arguments)
30
+    * Environment variables (-e/--env)
30 31
     * Names (--name)
31 32
     * Networks (--net)
32 33
     * Port publications (-p)
33 34
     * Restart policies (--restart)
35
+    * User switching (-u/--user)
34 36
     * Volumes (-v/--volume, and --volumes-from)
35 37
 
36 38
 ## What's not done yet
37 39
 
38 40
 Many other command line arguments:
39 41
 
40
-    * Environment variables
41 42
     * Labels
42 43
     * Linking and aliases
43 44
     * Permissions and policies

+ 8
- 0
docker-rerun View File

@@ -110,6 +110,14 @@ def handle_command(container):
110 110
     container.cmd = container.if_image_diff(lambda c: c['Config']['Cmd'], [])
111 111
 
112 112
 
113
+def handle_environment(container):
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]
118
+    container.args.extend(['--env=%s' % env for env in delta])
119
+
120
+
113 121
 def handle_image(container):
114 122
     """Copies the image argument."""
115 123
     container.image = container.info['Config']['Image']

+ 15
- 13
test.py View File

@@ -11,22 +11,24 @@ def _run(cmd):
11 11
 
12 12
 
13 13
 @parameterized([
14
-    'docker run --name=test123 -d hello-world',
15
-    'docker run --name=test123 -d hello-world:latest',
16
-    'docker run --name=test123 -d hello-world /hello world...',
17
-    'docker run --name=test123 --restart=always -d hello-world',
18
-    'docker run --name=test123 --restart=on-failure:10 -d hello-world',
19
-    'docker run --name=test123 --net=host -d hello-world',
20
-    'docker run --name=test123 -d -p=127.0.0.1:443:443/tcp -p=127.0.0.1::1336/tcp hello-world',
21
-    'docker run --name=test123 -d -p=443/tcp hello-world',
22
-    'docker run --name=test123 --user=root -d hello-world /hello foobar',
23
-    'docker run --name=test123 --volume=/dev/null:/null --volume=/dev/urandom:/mnt/random -d hello-world',
14
+    ['docker', 'run', '--name=test123', '-d', 'hello-world'],
15
+    ['docker', 'run', '--name=test123', '-d', 'hello-world:latest'],
16
+    ['docker', 'run', '--name=test123', '-d', 'hello-world', '/hello', 'world...'],
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'],
19
+    ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world'],
20
+    ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world'],
21
+    ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world'],
22
+    ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443/tcp', '-p=127.0.0.1::1336/tcp', 'hello-world'],
23
+    ['docker', 'run', '--name=test123', '-d', '-p=443/tcp', 'hello-world'],
24
+    ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar'],
25
+    ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world'],
24 26
 ])
25
-def test_command_matches(command):
27
+def test_command_matches(*command):
26 28
     _run(['docker', 'rm', '-f', 'test123'])
27
-    _run(command.split(' '))
29
+    _run(command)
28 30
     output = subprocess.check_output(['./docker-rerun', '--dry-run', 'test123'])
29 31
     output = output.decode('utf-8').strip().splitlines()
30
-    assert output[3] == command
32
+    assert output[3] == ' '.join(command)
31 33
     _run(['docker', 'rm', '-f', 'test123'])
32 34
 

Loading…
Cancel
Save