Templates
Templates are predefined configurations that guide users through the process of creating new entities, such as microservices, libraries, or even documentation sites. These templates help enforce best practices and ensure consistency across projects.
Defining a Template
A template is defined using a combination of YAML and Go templates. The YAML file specifies metadata about the template, including its name, description, and parameters required from the user. The Go template provides the structure and content of the files that will be generated.
Example YAML snippet for a template:
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: my-service-template
title: My Service Template
description: Template for creating a new service
spec:
owner: team@example.com
parameters:
- title: Service Name
type: string
required: true
description: The name of the new service
steps:
- action: scaffolder:fetch
id: fetch-base
name: Fetch Base Template
input:
url: https://github.com/my-org/base-template-repo
- action: scaffolder:template
id: generate-files
name: Generate Files
input:
path: base-template
values:
name: ${{ parameters.name }}
Using a Template
To use a template, click Create via the dashboard sidebar, then select a desired template from the list.
Fill in the required parameters, such as the service name, and initiate the creation process. The developer platform then uses the template to scaffold a new project based on the provided parameters.
Automating Processes
Templates can include various steps to automate the setup of new projects, such as:
- Fetching base templates or boilerplate code from repositories.
- Generating files and directories with customized content.
- Initializing version control repositories.
- Setting up CI/CD pipelines.
- Registering the new component in the component catalog.
Consistency and Best Practices
By using templates, organizations ensure that new projects adhere to established standards and best practices. Templates encapsulate knowledge about the organization's preferred tools, configurations, and conventions, reducing the learning curve for new developers and increasing overall productivity.
Conclusion
Templates provide a robust way to standardize and simplify the creation of new components and services. By leveraging templates, organizations can ensure consistency, promote best practices, and automate repetitive tasks, leading to more efficient and reliable development processes.
References
Looking for more information? Check out the following resource: