Add env_file for docker hook

Add docker hook for environment files.
Some containerized services need to accept environment
files and cannot be configured otherwise, for example
Etcd key-value storage.

Partial-bug: #1668938

Change-Id: I228b5f9ee67215ae742760d449b9cd8a4b9543d0
Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
This commit is contained in:
Bogdan Dobrelya 2017-03-20 18:27:55 +01:00
parent 3961e3b32b
commit 5a694739a4
3 changed files with 31 additions and 1 deletions

View File

@ -40,6 +40,13 @@ def docker_run_args(cmd, container, config):
cconfig = config[container]
if cconfig.get('detach', True):
cmd.append('--detach=true')
if 'env_file' in cconfig:
if isinstance(cconfig['env_file'], list):
for f in cconfig.get('env_file', []):
if f:
cmd.append('--env-file=%s' % f)
else:
cmd.append('--env-file=%s' % cconfig['env_file'])
for v in cconfig.get('environment', []):
if v:
cmd.append('--env=%s' % v)

View File

@ -0,0 +1,6 @@
---
features:
- |
Add docker hook for environment files. Some containerized services need to
accept environment files and cannot be configured otherwise, for example
Etcd key-value storage.

View File

@ -38,6 +38,8 @@ class HookDockerCmdTest(common.RunScriptTest):
"name": "x",
"image": "xxx",
"privileged": False,
"environment": ["foo=bar"],
"env_file": "env.file",
"start_order": 0
},
"web-ls": {
@ -60,8 +62,11 @@ class HookDockerCmdTest(common.RunScriptTest):
"environment": [
"KOLLA_CONFIG_STRATEGY=COPY_ALWAYS",
"FOO=BAR"
],
"env_file": [
"foo.env",
"bar.conf"
]
}
}
}
@ -166,6 +171,8 @@ class HookDockerCmdTest(common.RunScriptTest):
'--label',
'managed_by=docker-cmd',
'--detach=true',
'--env-file=env.file',
'--env=foo=bar',
'--privileged=false',
'xxx'
], state[1]['args'])
@ -192,6 +199,8 @@ class HookDockerCmdTest(common.RunScriptTest):
'--label',
'managed_by=docker-cmd',
'--detach=true',
'--env-file=foo.env',
'--env-file=bar.conf',
'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
'--env=FOO=BAR',
'--net=host',
@ -319,6 +328,8 @@ class HookDockerCmdTest(common.RunScriptTest):
'--label',
'managed_by=docker-cmd',
'--detach=true',
'--env-file=env.file',
'--env=foo=bar',
'--privileged=false',
'xxx'
], state[1]['args'])
@ -345,6 +356,8 @@ class HookDockerCmdTest(common.RunScriptTest):
'--label',
'managed_by=docker-cmd',
'--detach=true',
'--env-file=foo.env',
'--env-file=bar.conf',
'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
'--env=FOO=BAR',
'--net=host',
@ -450,6 +463,8 @@ class HookDockerCmdTest(common.RunScriptTest):
'--label',
'managed_by=docker-cmd',
'--detach=true',
'--env-file=env.file',
'--env=foo=bar',
'--privileged=false',
'xxx'
], state[2]['args'])
@ -483,6 +498,8 @@ class HookDockerCmdTest(common.RunScriptTest):
'--label',
'managed_by=docker-cmd',
'--detach=true',
'--env-file=foo.env',
'--env-file=bar.conf',
'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
'--env=FOO=BAR',
'--net=host',