Commit 2e81276b authored by Kirill Smelkov's avatar Kirill Smelkov

gitlab: Introduce macro library

Introduce a library of Jinja2 macros that will be handy to use in
templates. For now we add only 2 macros:

    cfg(name)   - to get instance configuration parameter `name`,   and
    cfg_bool    - to get truth value of ----//----

The reason we introduce cfg() is that we will need to use a lot of
parameters in many places and it is much more handy to write, e.g.

    cfg('email_enabled')

compared to

    instance_parameter:configuration.email_enabled

/cc @kazuhiko, @jerome
parent de860ba5
...@@ -127,6 +127,8 @@ mode = 0700 ...@@ -127,6 +127,8 @@ mode = 0700
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do extensions = jinja2.ext.do
mode = 0640 mode = 0640
import-list =
rawfile macrolib.cfg.in {{ macrolib_cfg_in }}
context = context =
raw autogenerated # This file was autogenerated. (DO NOT EDIT - changes will be lost) raw autogenerated # This file was autogenerated. (DO NOT EDIT - changes will be lost)
section instance_parameter instance-parameter section instance_parameter instance-parameter
......
...@@ -41,6 +41,7 @@ context = ...@@ -41,6 +41,7 @@ context =
raw gitlab_parameters_cfg ${gitlab-parameters.cfg:target} raw gitlab_parameters_cfg ${gitlab-parameters.cfg:target}
raw gitlab_shell_config_yml_in ${gitlab-shell-config.yml.in:target} raw gitlab_shell_config_yml_in ${gitlab-shell-config.yml.in:target}
raw gitlab_yml_in ${gitlab.yml.in:target} raw gitlab_yml_in ${gitlab.yml.in:target}
raw macrolib_cfg_in ${macrolib.cfg.in:target}
raw rack_attack_rb_in ${rack_attack.rb.in:target} raw rack_attack_rb_in ${rack_attack.rb.in:target}
raw resque_yml_in ${resque.yml.in:target} raw resque_yml_in ${resque.yml.in:target}
raw smtp_settings_rb_in ${smtp_settings.rb.in:target} raw smtp_settings_rb_in ${smtp_settings.rb.in:target}
......
{# common macros for gitlab instance #}
{# cfg(name) -> instance_parameter:configuration.<name> #}
{% macro cfg(name) %}{{ instance_parameter[str("configuration." + name)] }}{% endmacro %}
{# cfg_bool(name) - like cfg(name), but returns 'true'/''
NOTE macros can return only strings - that's why '' is used for false #}
{% macro cfg_bool(name) %}{{ 'true' if (cfg(name).lower() in ('true', 'yes')) else '' }}{% endmacro %}
...@@ -208,6 +208,10 @@ url = ${:_profile_base_location_}/template/${:_buildout_section_name_} ...@@ -208,6 +208,10 @@ url = ${:_profile_base_location_}/template/${:_buildout_section_name_}
<= download-file <= download-file
# md5sum = TODO # md5sum = TODO
[macrolib.cfg.in]
<= download-file
# md5sum = TODO
[rack_attack.rb.in] [rack_attack.rb.in]
<= download-template <= download-template
# md5sum = TODO # md5sum = TODO
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment