From 51074b0a42490d69f653c49aa78a03cb55888ff1 Mon Sep 17 00:00:00 2001 From: "Michal (inc0) Jastrzebski" Date: Thu, 2 Jun 2016 16:43:38 +0000 Subject: [PATCH] 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 --- kolla/common/config.py | 2 ++ kolla/image/build.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/kolla/common/config.py b/kolla/common/config.py index 903fd693d5..b1224d09eb 100644 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -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 = [ diff --git a/kolla/image/build.py b/kolla/image/build.py index 40601f0e84..6805ab14c1 100755 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -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()