Mechanism for Dockerfile customization

This patchset enables potentially full customization of Dockerfiles
provided by Kolla without having to change main Kolla code. Mechanism is
based on jinja2 block mechanism. In our dockerfiles we'll add blocks
(mostly empty) with highly standarized naming, then in override file
users will be able to fill/override contents of these blocks. Example is
shown in this patch.
To enable cutomized override file call build.py

--template-override=path-to-file Only caveat is that header {% extends
.. %} has to stay

Change-Id: I5957024e5652f9677c439fb2fcd524e467b951af
Partially-implements: blueprint third-party-plugin-support
This commit is contained in:
Michal (inc0) Jastrzebski 2016-06-02 16:43:38 +00:00
parent c31688be36
commit 51074b0a42
2 changed files with 12 additions and 3 deletions

View File

@ -142,6 +142,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'),
]
_BASE_OPTS = [

View File

@ -609,9 +609,6 @@ class KollaWorker(object):
self.base)
for path in self.docker_build_paths:
template_name = "Dockerfile.j2"
env = jinja2.Environment( # nosec: not used to render HTML
loader=jinja2.FileSystemLoader(path))
template = env.get_template(template_name)
values = {'base_distro': self.base,
'base_image': self.conf.base_image,
'base_distro_tag': self.base_tag,
@ -624,6 +621,16 @@ class KollaWorker(object):
'maintainer': self.maintainer,
'kolla_version': kolla_version,
'rpm_setup': self.rpm_setup}
env = jinja2.Environment( # nosec: not used to render HTML
loader=jinja2.FileSystemLoader(path))
template = env.get_template(template_name)
if self.conf.template_override:
template_path = os.path.dirname(self.conf.template_override)
template_name = os.path.basename(self.conf.template_override)
values['parent_template'] = template
env = jinja2.Environment( # nosec: not used to render HTML
loader=jinja2.FileSystemLoader(template_path))
template = env.get_template(template_name)
if self.include_header:
with open(self.include_header, 'r') as f:
values['include_header'] = f.read()