Skip to main content

添加自己的模板

模板存储在软件目录在一种Template定义模板至少需要一个template.yaml文件,但最好也能在其中包含一些可以模板化的文件。

一个简单的template.yaml定义可能是这样的

apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
# some metadata about the template itself
metadata:
name: v1beta3-demo
title: Test Action template
description: scaffolder v1beta3 template demo
spec:
owner: backstage/techdocs-core
type: service

# these are the steps which are rendered in the frontend with the form input
parameters:
- title: Fill in some steps
required:
- name
properties:
name:
title: Name
type: string
description: Unique name of the component
ui:autofocus: true
ui:options:
rows: 5
- title: Choose a location
required:
- repoUrl
properties:
repoUrl:
title: Repository Location
type: string
ui:field: RepoUrlPicker
ui:options:
allowedHosts:
- github.com

# here's the steps that are executed in series in the scaffolder backend
steps:
- id: fetch-base
name: Fetch Base
action: fetch:template
input:
url: ./template
values:
name: ${{ parameters.name }}

- id: fetch-docs
name: Fetch Docs
action: fetch:plain
input:
targetPath: ./community
url: https://github.com/backstage/community/tree/main/backstage-community-sessions

- id: publish
name: Publish
action: publish:github
input:
allowedHosts: ['github.com']
description: This is ${{ parameters.name }}
repoUrl: ${{ parameters.repoUrl }}

- id: register
name: Register
action: catalog:register
input:
repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }}
catalogInfoPath: '/catalog-info.yaml'

模板实体包含有关必填字段的更多信息。

一旦我们有了template.yaml准备就绪后,我们就可以将其添加到软件目录中,供脚手架搭设者使用。

注意:添加或修改模板时,需要刷新位置实体。 > 否则,backstage 将不会在可用模板中显示该模板, > 或者会一直显示旧模板。 可以通过 > 进入 "目录 "网页,选择 "位置 "而不是 "组件",然后选择正确的位置实体来刷新位置实例。 > 从那里,可以点击代表 "预定实体刷新 "操作的刷新图标。 > 之后,应该可以看到模板已更新。

您可以通过以下方式将模板文件添加到目录中静态位置配置例如

catalog:
locations:
- type: url
target: https://github.com/backstage/software-templates/blob/main/scaffolder-templates/react-ssr-template/template.yaml
rules:
- allow: [Template]
- type: file
target: template.yaml # Backstage will expect the file to be in packages/backend/template.yaml

或者使用catalog-import插件,除非有不同的配置,否则该插件应运行在/catalog-import.

有关编写自己的模板的信息,请查看文档这里

如果您正在寻找一种无需手动摄取就能发现模板的方法,有几种可供选择的方法。 一种方法是利用发现提供程序,如发现 GitHub.

或者,您也可以选择设置外部集成。 这包括将您的系统连接到外部资源或平台,这些资源或平台可能会托管与您的需求相关的模板,如以下内容所述外部整合.