Today's code build & continuous deployment models are highly diverse thus leading to handwritten and complicated perl/awk/sed scripts. DevOps should come out of age old hand-crafted find and replace scripts with much modern template engines.
Of course template engines are available in wide variety. All enterprise configuration management (chef, puppet, ansible ) software are equipped with their own flavour of template engines and playbooks. This article however concentrate on "Mustache" template which is logicless template system and work on any text based data (Web pages, scripts, dataset, config files etc..)
The example below focusses on replacing dynamic text using a JSON dataset. Let's define terminologies
Of course template engines are available in wide variety. All enterprise configuration management (chef, puppet, ansible ) software are equipped with their own flavour of template engines and playbooks. This article however concentrate on "Mustache" template which is logicless template system and work on any text based data (Web pages, scripts, dataset, config files etc..)
The example below focusses on replacing dynamic text using a JSON dataset. Let's define terminologies
- Source : Template Parent Directory with all files/directories + dynamic variables in it
- Dataset: JSON based self defining dataset to replace the above source(s)
- Params: Extra parameters that are supplied (eg: Environment PROD, DEV etc..)
- All template files in "Source" to have an extension of ".mustache"
- Recursively scan whole of "Source" directory and children and identify .mustache files
- Feed these files into mustache renderer
- Rending information supplied using "Dataset"
- Filter out required elements of "Dataset" using input "Params"
- Copy directory structure and files into a temporary location with filled values