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)
This commit is contained in:
Emilien Macchi 2019-04-15 09:00:53 -04:00 committed by Alex Schultz
parent e52fdc0854
commit d3c1cdc13a
2 changed files with 3 additions and 3 deletions

View File

@ -186,7 +186,7 @@ class ComposeV1Builder(object):
if 'healthcheck' in cconfig:
hconfig = cconfig['healthcheck']
if 'test' in hconfig:
cmd.append('--health-cmd=%s' % hconfig['test'])
cmd.append('--health-cmd="%s"' % hconfig['test'])
if 'interval' in hconfig:
cmd.append('--health-interval=%s' % hconfig['interval'])
if 'timeout' in hconfig:

View File

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