Templates not only allow you to achieve standardization across your services and projects, but save developers a lot of time. Templates can streamline everything from your framework code to configuring your organization’s build pipeline. With a template, you eliminate potential for human error and the tedious task of copying and pasting elements of code that remain the same.
Cookiecutter has emerged as a leading templating library, allowing engineers to automate the creation of code to follow exact standards. Cookiecutter allows you to create a template and tweak it to your needs, so you can easily enforce consistency every time a new project is spun up.
With a tool like Cookiecutter, you can standardize how your services are structured across teams and you can reduce duplications in the process, freeing engineers to focus on what really matters. Cortex has taken Cookiecutter’s capabilities even further with the scaffolder, which allows you to not only create a new service, but add functionality to existing services, too.
You can access the scaffolder with the Tools tab in the navigation bar.
From there, you'll decide whether to Create a new service or Add to an existing service.
Create a new service
Create a new service is best when you're working on an entirely new project that should ultimately be added into the catalog. Everything from front-end libraries to data pipelines can be created through the Scaffolder.
Once you select Create a new service, click on one of the available templates to move on to the next stage.
First, you’ll be asked to provide some essential information for your service — these fields will be the same no matter what template you select.
Once you’ve entered in the template fields, you can decide whether to Create a new repo or Open a pull request. If you choose to Create a new repo, you'll be prompted to select a Repo Org from a dropdown, name the new repo, and identify the default branch to be used for the service.
If you want to add custom GitHub secrets to the repository, you can do so under Advanced Configuration.
If you choose to Open a pull request, you'll select the Repo Name from a dropdown list, define the Branch to create where the generated code will be pushed, and identify the Subdirectory where the generated code will live.
The final step is to Configure service. At this stage, you'll be prompted to enter details about your service, just like during the standard service import flow. Keep in mind that your new service will be added into the catalog at the end of this process — to maximize the functionality of your service, it makes sense to add as much of this information upfront as possible. In addition to service details, you can also designate owners, add Slack channels, and define dependencies during this step.
Once you've added all of this information, select Create Service to confirm all of the details you entered. When you click Create Service, Cortex will create or connect with the repository in Git, run Cookiecutter, generate the code, and push the code to the appropriate Git repo. The new service will also appear in the catalog, complete with its own YAML file, so you’ll continue to have full control over your projects.
Add to an existing service
Cortex has extended Cookiecutter’s powerful features to include the ability to Add to an existing service with a template by opening a pull request against an existing repository. If your organization uses a monorepo, or if you have an existing service you need to update, this is the option for you.
Select one of the available templates to use to Add to an existing service to move on to the next stage. Just like with Create a new service, the next stage is defining the template inputs.
Next, select the appropriate repo from the dropdown list and name the Branch to create.
Once you’ve entered in the repository information, Cortex will create this branch in Git and open a pull request against the repo.
When working with the scaffolder, Cortex will surface any errors to the UI (even if the errors are within the Cookiecutter file), so you’ll have a clear sense of how to correct the code.
Going further
There are a suite of features within the scaffolder that extend the powerful functionality of Cookiecutter. To learn how to hide fields, add descriptions to input fields, and much more, make sure to check out our developer docs.
Comments
0 comments
Article is closed for comments.