Package: cnd-scaffold
CndScaffold >=3.0.0Why use CndScaffoldCndScaffold is a python lib, designed to help management of GitOps process.
Now base on jinja2, it allow you to merge a dict of data into a list of file.Connected with the right provider, you can directly push your result to a git server (gitlab / github /Azure DevOps)How it's works ? (with example)define in jinja format a list of template file (the file can be text, yaml or anything else)create a file of definitionapply data on itWhat we want as resultData sourceFor example we got this dataname:Deniscustomers:-name:my_first_customeremail:my_first_customer@sample-mail.comid:c6a240ac-587a-11ee-8c99-0242ac120002token:ABC-name:my_secondemail:my_second_customer@sample-mail.comid:d174a3e4-587a-11ee-8c99-0242ac120002token:DEF-name:my_lastemail:my_last_customer@sample-mail.comid:ebe22792-587a-11ee-8c99-0242ac120002token:GHIFiles resultAnd we want to generate multiple file for a gitops process, who look like this result:config.ymlname:Denistype:my_type_samplecustomers.ymlcustomers:-name:my_first_customeremail:my_first_customer@sample-mail.comid:c6a240ac-587a-11ee-8c99-0242ac120002-name:my_secondemail:my_second_customer@sample-mail.comid:d174a3e4-587a-11ee-8c99-0242ac120002-name:my_lastemail:my_last_customer@sample-mail.comid:ebe22792-587a-11ee-8c99-0242ac120002customers/c6a240ac-587a-11ee-8c99-0242ac120002.ymltoken:ABCcustomers/d174a3e4-587a-11ee-8c99-0242ac120002.ymltoken:DEFcustomers/ebe22792-587a-11ee-8c99-0242ac120002.ymltoken:GHIHow we do itDefinition of a list of file in jinjaA single simple file :definition/customers/file1.ymlname:{{name}}type:my_type_sampleNow a file with a loop :definition/customers/loop.yml{%if customers |length > 1 %}customers:{%- for customer in customers %}name:{{customer.name -}}email:{{customer.email -}}id:{{customer.id -}}{%endfor %}{%endif %}And finally to create multiple file with a loop (like one per customer):definition/customers/multiple.ymltoken:{{token}}Definition filedefinition/customers.ymlsource_folder:customersfiles:-name:file1.ymlstep:['init']target:config.yml-name:loop.ymlstep:['init','build','runtime']-name:multiple.ymlstep:['init','build','runtime']repeat:customerstarget:customers/{{ id }}.ymlBuild the code (localfile)The first sample will generate the file into a results folderrun.py (generate data in a local folder)importcnd_scaffoldimportcndprintdata=my_data# .... load your data as you needcnd_scaffold=cnd_scaffold.Scaffold(_print)model=cnd_scaffold.load_model('definition',customers.yml')final_files=cnd_scaffold.apply('init',model,data)final_files=cnd_scaffold.push_files(final_files,'results')Build the code (provider gitlab)This second example will push the result intogit_lab_project_idrun.py (generate data in a local folder)importcnd_scaffoldimportcndprintimportcnd_providerdata=my_data# .... load your data as you needprovider=cnd_provider.CndProviderGitlab({"private_token":'replace-me',"host":"https://mygitlab"}cnd_scaffold=cnd_scaffold.Scaffold(_print)model=cnd_scaffold.load_model('definition',customers.yml')final_files=cnd_scaffold.apply('init',model,data)final_files=cnd_scaffold.push_files(final_files,"git_lab_project_id",provider=provider)That's all !With this definition, each time you use cnd_scaffold you will generate this file structure/content from your own data.TipsStepstep, will allow you using different case, you can use it as you prefer, but I suggest you this:init: First time only, it's mean this file will never been update by the scriptbuild: Each time the process start, it will be updateruntime: Perfect for Terraform secret for example, you can set this to never write result on git, but only on the current pipeline session