Browse Source

docker/compose: quote health-cmd

Healthcheck commands need to be quoted to avoid Docker interpreting the
cmd as arguments of CLI.
This patch prevents that, and also test it in unit tests.

Change-Id: I8273684716df0dbe6f58608d1915e0c9c17493b3
Closes-Bug: #1824808
(cherry picked from commit affc28f515)
tags/2.5.2
Emilien Macchi 3 months ago
parent
commit
9fbbad559d
2 changed files with 3 additions and 3 deletions
  1. 1
    1
      paunch/builder/compose1.py
  2. 2
    2
      paunch/tests/test_builder_compose1.py

+ 1
- 1
paunch/builder/compose1.py View File

@@ -165,7 +165,7 @@ class ComposeV1Builder(object):
165 165
         if 'healthcheck' in cconfig:
166 166
             hconfig = cconfig['healthcheck']
167 167
             if 'test' in hconfig:
168
-                cmd.append('--health-cmd=%s' % hconfig['test'])
168
+                cmd.append('--health-cmd="%s"' % hconfig['test'])
169 169
             if 'interval' in hconfig:
170 170
                 cmd.append('--health-interval=%s' % hconfig['interval'])
171 171
             if 'timeout' in hconfig:

+ 2
- 2
paunch/tests/test_builder_compose1.py View File

@@ -424,7 +424,7 @@ three-12345678 three''', '', 0),
424 424
                 'uts': 'host',
425 425
                 'restart': 'always',
426 426
                 'healthcheck': {
427
-                    'test': '/bin/true',
427
+                    'test': 'ls /mydir',
428 428
                     'interval': '30s',
429 429
                     'timeout': '10s',
430 430
                     'retries': 3
@@ -441,7 +441,7 @@ three-12345678 three''', '', 0),
441 441
             ['docker', 'run', '--name', 'one',
442 442
              '--detach=true', '--env-file=/tmp/foo.env',
443 443
              '--net=host', '--ipc=host', '--pid=container:bar',
444
-             '--uts=host', '--health-cmd=/bin/true', '--health-interval=30s',
444
+             '--uts=host', '--health-cmd="ls /mydir"', '--health-interval=30s',
445 445
              '--health-timeout=10s', '--health-retries=3',
446 446
              '--privileged=true', '--restart=always', '--user=bar',
447 447
              '--log-opt=tag={{.ImageName}}/{{.Name}}/{{.ID}}', 'centos:7'],

Loading…
Cancel
Save