Skip to main content

Tools initiate a new project in git lab, based on a existing definition

Project description

CndScaffold >=3.0.0

Why use CndScaffold

CndScaffold 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 definition
  • apply data on it

What we want as result

Data source

For example we got this data

name: Denis
customers:
  - name: my_first_customer
    email: my_first_customer@sample-mail.com
    id: c6a240ac-587a-11ee-8c99-0242ac120002
    token: ABC
  - name: my_second
    email: my_second_customer@sample-mail.com
    id: d174a3e4-587a-11ee-8c99-0242ac120002
    token: DEF
  - name: my_last
    email: my_last_customer@sample-mail.com
    id: ebe22792-587a-11ee-8c99-0242ac120002
    token: GHI

Files result

And we want to generate multiple file for a gitops process, who look like this result:

config.yml

name: Denis
type: my_type_sample

customers.yml

customers:
- name: my_first_customer
  email: my_first_customer@sample-mail.com
  id: c6a240ac-587a-11ee-8c99-0242ac120002
- name: my_second
  email: my_second_customer@sample-mail.com
  id: d174a3e4-587a-11ee-8c99-0242ac120002
- name: my_last
  email: my_last_customer@sample-mail.com
  id: ebe22792-587a-11ee-8c99-0242ac120002

customers/c6a240ac-587a-11ee-8c99-0242ac120002.yml

token: ABC

customers/d174a3e4-587a-11ee-8c99-0242ac120002.yml

token: DEF

customers/ebe22792-587a-11ee-8c99-0242ac120002.yml

token: GHI

How we do it

Definition of a list of file in jinja

A single simple file :

definition/customers/file1.yml

name: {{ name }}
type: my_type_sample

Now 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.yml

token: {{ token }}

Definition file

definition/customers.yml

source_folder: customers
files:
- name: file1.yml
  step: ['init']
  target: config.yml
- name: loop.yml
  step: ['init', 'build', 'runtime']
- name: multiple.yml
  step: ['init', 'build', 'runtime']
  repeat: customers 
  target: customers/{{ id }}.yml 

Build the code (localfile)

The first sample will generate the file into a results folder

run.py (generate data in a local folder)

import cnd_scaffold
import cndprint


data = my_data # .... load your data as you need
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, 'results')

Build the code (provider gitlab)

This second example will push the result into git_lab_project_id

run.py (generate data in a local folder)

import cnd_scaffold
import cndprint
import cnd_provider


data = my_data # .... load your data as you need
provider = 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.

Tips

Step

step, 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 script
  • build: Each time the process start, it will be update
  • runtime: Perfect for Terraform secret for example, you can set this to never write result on git, but only on the current pipeline session

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cnd_scaffold-3.2.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

cnd_scaffold-3.2.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file cnd_scaffold-3.2.1.tar.gz.

File metadata

  • Download URL: cnd_scaffold-3.2.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for cnd_scaffold-3.2.1.tar.gz
Algorithm Hash digest
SHA256 8f1ea6d3c18c405611dc37f03c798322a63c305e064de6d9827c89fb2d984b20
MD5 96f38cf6c780c10afd7fb9fdd5404c68
BLAKE2b-256 dceb74584bac23e2413431961c49d38fc74e06c185ce7e9db9f1153264684edf

See more details on using hashes here.

File details

Details for the file cnd_scaffold-3.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cnd_scaffold-3.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87d460df531b54c069f614baf85bee0b2b52d435b24784aae744e049c0df53b1
MD5 ce54347f4ea02c21362b5a9cabb54a99
BLAKE2b-256 010034b97cda3918b780ebb8660b20b321fa9c861286b463c7704569ae40ee4e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page