Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 5. Standardizing project development with software templates
As a platform engineer, you can use Software Templates in Red Hat Developer Hub (RHDH) to provide standardized project starter kits for your development teams. This self-service model improves developer productivity and ensures that new projects follow organizational standards and best practices.
5.1. Software Templates in Red Hat Developer Hub Link kopierenLink in die Zwischenablage kopiert!
You can use Software Templates in RHDH to automate the project setup process to reduce manual configuration and errors for developers. These Software Templates are part of the Backstage Scaffolder system.
A Software Template consists of a YAML file with the following elements:
- Metadata: Names and describes the template so developers can find the correct starter kit in the catalog.
- Parameters: Define the specific information developers must provide, such as the project name or owner.
- Steps: Sequence of steps that the system performs to build the project, such as fetching a repository skeleton, injecting parameters, and publishing the code to a Git provider.
5.2. Creating a basic Software Template Link kopierenLink in die Zwischenablage kopiert!
To automate the setup of standardized environments for your developers, you must create a template definition. This definition allows RHDH to automate the repetitive tasks of repository creation and initial configuration.
Prerequisites
- You have administrator access to a RHDH instance.
- You have a Git repository to store Software Template files.
Procedure
- Create a directory in your Git repository for the Software Template.
-
Create a file named
template.yamlin that directory. -
In the
template.yamlfile, define theapiVersion,kind, andmetadatato identify the starter kit in the software catalog. -
Add a
specsection to define theparametersthat a developer must provide when they use the Software Template. Define the
stepsrequired to generate the project, such asfetch:templateto retrieve the skeleton andpublish:githubto create the new repository.ImportantYou must include TechDocs in your Software Templates to ensure that documentation is automatically generated for every new project created from the Software Template.
Verification
-
Inspect the
template.yamlfile to ensure the YAML syntax is valid. -
Confirm that the
nameandactionfields are defined so the template is correctly recognized as a Scaffolder task. -
Check that the defined
parametersmatch the variables used in your Software Template skeleton files. -
Navigate to the form playground at
<instance-url>/create/template-formand test the Software Template configuration to confirm the fields and logic render as intended.
5.3. Sample Software Template Link kopierenLink in die Zwischenablage kopiert!
The following example shows a Software Template that defines project parameters and publishes the generated code to a GitHub repository.
5.4. Enabling Self-service with Software Templates Link kopierenLink in die Zwischenablage kopiert!
To allow developers to create new projects independently using your standards, you must publish the Software Template definition to the RHDH catalog. This registration makes the template a selectable option in the software creator interface.
Prerequisites
- You have administrator access to a RHDH instance.
- You have a Git repository to store Software Template files.
Procedure
- Navigate to the Create page in the RHDH interface.
- Select Register Component.
-
Enter the full URL to your
template.yamlfile in the Repository URL field. - Click Analyze and then Import.
Verification
- Navigate to the Create page.
- Confirm that your new template appears in the list of available options.
5.5. Extending Software Templates for complex project requirements Link kopierenLink in die Zwischenablage kopiert!
Use advanced logic to create Software Templates that adapt to specific project requirements and user inputs. The following table outlines the goals for advanced templating:
| Feature | Description |
|---|---|
| Parameterization | Use variables to inject user-provided data into project files. |
| Conditional Logic | Perform specific automation steps only when certain conditions are met. |
| Fetch and Execute | Retrieve remote files and run commands during the setup process. |