Adding transformations to Base Template Repos

Overview

Base Template Repositories (BTRs) are an excellent way to systematise and enforce configuration standards for your application. You can add Skycap Transformation definitions to any BTR to ensure that configuration files (Stencils) generated from that BTR are automatically transformed by your scripts.

Learn about BTRs and Validation Policies

This guide assumes you have a working knowledge of both BTRs and Skycap Validation Policies. Please read our separate guides for both these topics if you're unsure about them.

How to add transformations to a BTR

Transformations are defined in a BTR via a central templates.json file that sits in the root of the repo. This is an excerpt from a templates.json file that illustrates the structure of the transformations section:

    "transformations": [
             {
                "name": "Insert Sidecar",
                "filename": "sidecar.js",
                "description": "Insert sidecar in all of your services",
                "selector": "kind: Service",
                "tags": [],
                "preferred_sequence": 0
             },
          ]

The same templates.json file is also used to define the Kubernetes templates (Stencils) and any policies applied to those templates. For more info, please read our guides to these features.

Components of the JSON definition

The Transformation section of the templates.json has the following fields:

  • name is the name of the Transformation as it will appear in the Skycap UI
  • filename is the name of the Transformation's Javascript file in the BTR
  • description is a short description of the Transformation to help you identify it
  • selector is the Kubernetes selector for the templates to which the Transformation will apply (e.g. kind: Service)
  • tags is an array of default tags that will be added to Transformation files generated by this template
  • preferred_sequence determines the default sequence in which this Transformation will be run, relative to any other Transformations in the Formation.

Directory structure for transformations in BTRs

BTRs must be organized as follows:

  • The templates.json must be placed in the root directory
  • The Transformation (js) files must be placed in a directory named transformations