diff options
| author | Michal (inc0) Jastrzebski <inc007@gmail.com> | 2017-01-05 22:05:30 +0000 |
|---|---|---|
| committer | Michal (inc0) Jastrzebski <inc007@gmail.com> | 2017-01-06 17:33:40 +0000 |
| commit | febfd4e71ab0d1aed65ce92a8004b00e36cc7d60 (patch) | |
| tree | 720838fe070ca6e1bdb523f8cf4326a89c4df99d | |
| parent | f7a1831aad0681ec098a0decedb80ccc6b80a826 (diff) | |
| download | kolla-febfd4e71ab0d1aed65ce92a8004b00e36cc7d60.tar.gz kolla-febfd4e71ab0d1aed65ce92a8004b00e36cc7d60.zip | |
Support for multiple override files
To use multiple override files run --template-override f1
--template-override f2.
One caveat is it won't work well if both modify same variable/block. One
will override another, so if both overrides tries to add pkg to horizon
tpl, only second package gets installed
Change-Id: I8d2937c2dad83d3ec94efa6d9c9849a922c0cef6
| -rwxr-xr-x | kolla/common/config.py | 4 | ||||
| -rwxr-xr-x | kolla/image/build.py | 18 |
2 files changed, 17 insertions, 5 deletions
diff --git a/kolla/common/config.py b/kolla/common/config.py index 8be553b10..c2d8a5e0a 100755 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -203,8 +203,8 @@ _CLI_OPTS = [ help=("Don't build images. Generate Dockerfile only")), cfg.IntOpt('timeout', default=120, help='Time in seconds after which any operation times out'), - cfg.StrOpt('template-override', - help='Path to template override file'), + cfg.MultiOpt('template-override', types.String(), + help='Path to template override file'), cfg.StrOpt('logs-dir', help='Path to logs directory'), cfg.BoolOpt('pull', default=True, help='Attempt to pull a newer version of the base image.'), diff --git a/kolla/image/build.py b/kolla/image/build.py index 35029f198..c2f6fe614 100755 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -661,11 +661,11 @@ class KollaWorker(object): template = env.get_template(tpl_path) if self.conf.template_override: - template_path = os.path.dirname(self.conf.template_override) - template_name = os.path.basename(self.conf.template_override) + tpl_dict = self._merge_overrides(self.conf.template_override) + template_name = os.path.basename(tpl_dict.keys()[0]) values['parent_template'] = template env = jinja2.Environment( # nosec: not used to render HTML - loader=jinja2.FileSystemLoader(template_path)) + loader=jinja2.DictLoader(tpl_dict)) env.filters.update(self._get_filters()) env.globals.update(self._get_methods()) template = env.get_template(template_name) @@ -677,6 +677,18 @@ class KollaWorker(object): f.write(content) LOG.debug("Wrote it to %s", content_path) + def _merge_overrides(self, overrides): + tpl_name = os.path.basename(overrides[0]) + with open(overrides[0], 'r') as f: + tpl_content = f.read() + for override in overrides[1:]: + with open(override, 'r') as f: + cont = f.read() + # Remove extends header + cont = re.sub(r'.*\{\%.*extends.*\n', '', cont) + tpl_content += cont + return {tpl_name: tpl_content} + def find_dockerfiles(self): """Recursive search for Dockerfiles in the working directory""" self.docker_build_paths = list() |
