이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 4. Configuring templates
Configure templates to create software components, and publish these components to different locations, such as the Red Hat Developer Hub software catalog, or Git repositories.
A template is a form composed of different UI fields that is defined in a YAML file. Templates include actions, which are steps that are executed in sequential order and can be executed conditionally.
4.1. Creating a Software Template by using the Template Editor
Use the Red Hat Developer Hub Template Editor to create a Software Template.
Alternately, you can use the Template Editor to do any of the following actions:
- File > Open template directory
- File > Create template directory
- File > Close template editor
-
Use the Custom Fields Explorer button to test custom fields in your
templates.yaml
file - View Installed Actions Documentation
Procedure
To create a Software Template by using the Template Editor templates, complete the following steps:
- In your Red Hat Developer Hub navigation menu, click Create….
Click the overview menu and select Manage Templates.
NoteThe following options on the Managed Templates page do not create a software component in your Red Hat Developer Hub instance:
-
Template Form Playground: Use to create and test the
templates.yaml
file - Custom Field Explorer: Use to test custom fields
-
Template Form Playground: Use to create and test the
On the Managed Templates page, select any of the following options:
Load Template Directory: Use to load an existing
templates.yaml
file-
In your local file manager, navigate to the folder where your
templates.yaml
file is stored and click Select.
-
In your local file manager, navigate to the folder where your
Create New Template: Use to create a
templates.yaml
file-
In your local file manager, navigate to the folder where you want the Template Editor to create a
templates.yaml
file and click Select. -
On the Template Editor page, select the
templates.yaml
file. (Optional) You can preview and test your template specifications.
- On the Fill in some steps tab, enter text into the required fields and click Next.
- On the Repository Location tab, enter text into the required fields and click Review.
- Modify the YAML definition for the parameters of your template. For more information about these parameters, see Section 4.2, “Creating a Software Template as a YAML file”.
- Review the information for accuracy, then click Create.
-
In your local file manager, navigate to the folder where you want the Template Editor to create a
Verification
- Click the Catalog tab in the navigation panel.
- In the Kind drop-down menu, select Template.
- Confirm that your Software Template is shown in the list of existing templates.
4.2. Creating a Software Template as a YAML file
You can create a Software Template by defining a Template
object as a YAML file.
The Template
object describes the template and its metadata. It also contains required input variables and a list of actions that are executed by the scaffolding service.
Template
object example
apiVersion: scaffolder.backstage.io/v1beta3 kind: Template metadata: name: template-name title: Example template description: An example template for v1beta3 scaffolder. spec: owner: backstage/techdocs-core type: service parameters: - title: Fill in some steps required: - name properties: name: title: Name type: string description: Unique name of the component owner: title: Owner type: string description: Owner of the component - title: Choose a location required: - repoUrl properties: repoUrl: title: Repository Location type: string steps: - id: fetch-base name: Fetch Base action: fetch:template # ... output: links: - title: Repository url: ${{ steps['publish'].output.remoteUrl }} - title: Open in catalog icon: catalog entityRef: ${{ steps['register'].output.entityRef }} # ...
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: template-name
title: Example template
description: An example template for v1beta3 scaffolder.
spec:
owner: backstage/techdocs-core
type: service
parameters:
- title: Fill in some steps
required:
- name
properties:
name:
title: Name
type: string
description: Unique name of the component
owner:
title: Owner
type: string
description: Owner of the component
- title: Choose a location
required:
- repoUrl
properties:
repoUrl:
title: Repository Location
type: string
steps:
- id: fetch-base
name: Fetch Base
action: fetch:template
# ...
output:
links:
- title: Repository
url: ${{ steps['publish'].output.remoteUrl }}
- title: Open in catalog
icon: catalog
entityRef: ${{ steps['register'].output.entityRef }}
# ...
- 1
- Specify a name for the Software Template.
- 2
- Specify a title for the Software Template. This is the title that is visible on the Software Template tile in the Create… view.
- 3
- Specify a description for the Software Template. This is the description that is visible on the Software Template tile in the Create… view.
- 4
- Specify the ownership of the Software Template. The
owner
field provides information about who is responsible for maintaining or overseeing the Software Template within the system or organization. In the provided example, theowner
field is set tobackstage/techdocs-core
. This means that this Software Template belongs to thetechdocs-core
project in thebackstage
namespace. - 5
- Specify the component type. Any string value is accepted for this required field, but your organization should establish a proper taxonomy for these. Red Hat Developer Hub instances may read this field and behave differently depending on its value. For example, a
website
type component may present tooling in the Red Hat Developer Hub interface that is specific to just websites.The following values are common for this field:
service
- A backend service, typically exposing an API.
website
- A website.
library
- A software library, such as an npm module or a Java library.
- 6
- Use the
parameters
section to specify parameters for user input that are shown in a form view when a user creates a component by using the Software Template in the Red Hat Developer Hub console. Eachparameters
subsection, defined by a title and properties, creates a new form page with that definition. - 7
- Use the
steps
section to specify steps that are executed in the backend. These steps must be defined by using a unique step ID, a name, and an action. You can view actions that are available on your Red Hat Developer Hub instance by visiting the URLhttps://<rhdh_url>/create/actions
. - 8
- Use the
output
section to specify the structure of output data that is created when the Software Template is used. Theoutput
section, particularly thelinks
subsection, provides valuable references and URLs that users can utilize to access and interact with components that are created from the Software Template. - 9
- Provides a reference or URL to the repository associated with the generated component.
- 10
- Provides a reference or URL that allows users to open the generated component in a catalog or directory where various components are listed.
4.3. Importing an existing Software Template to Red Hat Developer Hub
You can add an existing Software Template to your Red Hat Developer Hub instance by using the Catalog Processor.
Prerequisites
- You have created a directory or repository that contains at least one Software Template YAML file.
- If you want to use a Software Template that is stored in a repository such as GitHub or GitLab, you must configure a Red Hat Developer Hub integration for your provider.
Procedure
In the
app-config.yaml
configuration file, modify thecatalog.rules
section to include a rule for templates, and configure thecatalog.locations
section to point to the Software Template that you want to add, as shown in the following example:# ... catalog: rules: - allow: [Template] locations: - type: url target: https://<repository_url>/example-template.yaml # ...
# ... catalog: rules: - allow: [Template]
1 locations: - type: url
2 target: https://<repository_url>/example-template.yaml
3 # ...
Copy to Clipboard Copied!
Verification
- Click the Catalog tab in the navigation panel.
- In the Kind drop-down menu, select Template.
- Confirm that your Software Template is shown in the list of existing Software Templates.