Registering a Scaffolder template
Last updated
Last updated
Cortex's Scaffolder allows you to build a fully-automated Workflow for spinning up a new project (including repositories and libraries) and adds functionality to existing services (CI scripts, infrastructure modules, etc). Using templates, you can automatically generate the boilerplate and plumbing for projects, ensuring they follow best practices from day 0.
Templating is powered by the open source Cookiecutter project, an industry-standard tool to auto-generate boilerplate for new projects.
This page describes how to get started using the Scaffolder as a block in a Workflow. For advanced usage information, see Scaffolder advanced usage.
Before getting started:
Make sure you have configured a Git integration with write
access. The following integrations are available:
Cortex's GitHub app is pre-configured with permissions for the Scaffolder.
Configure the GitLab access token with write
permissions
Configure the Bitbucket token with Repositories - admin and delete
scopes.
Note: It is not possible to require a new Pull Request when using the Scaffolder with Bitbucket.
Configure the Azure DevOps token with Code read, write & manage
access.
To get started with the Scaffolder, you'll need a Cookiecutter template. You can either use an existing template or create a new one.
To get started quickly, you can use an existing open source template.
Find an open source template and clone the repo.
Open your cookiecutter.json
file, located in the root of the template repository.
In the file, add a version
key and enter the version. This allows Cortex to track which version of the template was used to generate a given project in the Catalog. For example:
Security restrictions for templates For security reasons, for templates used on Cortex Cloud, we disable Cookiecutter hooks, network access, and any syscalls. If you get an exception when using your template, ensure it's not attempting any of these restricted actions.
These features are enabled for templates when using Cortex Server (self-hosted).
You must have the Configure Scaffolder templates
permission to follow these steps.
In Cortex, navigate to Workflows from the main nav.
In the upper right corner of the page, click Register Scaffolder template.
Configure the template details:
Provider: Select which Git provider you are using.
Name: Enter a name for the template. This will be seen by developers when they create a service using the template.
Description: Add a description to help others understand the template's purpose.
Tags: Optionally, add tags to describe the template. For example, these could help developers understand whether the template is meant to be used for a specific service type, what language it uses, and more.
Under "Configuration," fill in the fields:
Git provider configuration: Enter the configuration, e.g., default
If you want the Scaffolder action to perform all git operations using this configuration, enable Use this configuration for all git operations.
Git URL: Enter the git URL where your template lives, e.g. https://github.com/cortexapps/cookiecutter-employee
Subdirectory for Cookiecutter template: If your Cookiecutter template is not stored at the root of your repository, enter the subdirectory URL here.
Configuration requirements: Select one of the following:
New service. Cortex service descriptor will be generated for the service and it will be automatically added to relevant catalogs.
If you don't select this option, you will still have the option to create a service entity when running the Scaffolder.
New pull request. When enabled, the template can only be used to open pull requests against existing repositories.
Note: It is not possible to require a new Pull Request when using the Scaffolder with Bitbucket.
Both. Enable both "New service" and "New pull request" configurations.
Neither. Disable both "New service" and "New pull request" configurations.
Create cortex.yaml in git when creating a new service: When enabled, a cortex.yaml will be created in git when the Scaffolder creates a new service.
If you don't enable this setting, the entity descriptor will be added via the API.
Show README.md during Scaffolding: When enabled, the project's README.md will be displayed when inputting the variables to use while rendering the template. If there is no README.md, nothing will be shown.
Click Register Scaffolder template.
If you see a "Failed to save template" error, ensure that you have provided a valid Git URL.
After you have added a template to Cortex, you can start using the Scaffolder in a Workflow.
Follow the instructions in the Workflows documentation for creating a Workflow and adding a Scaffolder block.
View all templates available to your organization under Workflows > Scaffolders.