内部开发者平台IDP:Backstage搭建企业级开发者门户 2026
DevOps运维
内部开发者平台IDP:Backstage搭建企业级开发者门户
你刚入职一家有200个微服务的公司。第一天,领导说"去部署一下order-service"。然后你花了3小时找Git仓库、2小时找CI/CD配置、1小时找API文档——还没开始写代码,一天就过去了。
这就是没有内部开发者平台(IDP)的日常。Backstage,Spotify开源的开发者门户框架,正在成为平台工程的事实标准。本文从5个核心模式出发,带你从零搭建企业级IDP。
核心概念速览
| 概念 | 说明 | 类比 |
|---|---|---|
| IDP(Internal Developer Platform) | 内部开发者平台,统一开发者自助服务入口 | 企业内部的"App Store" |
| Backstage | Spotify开源的IDP框架 | IDP界的Kubernetes |
| Software Catalog | 软件目录,所有服务的元数据注册中心 | 服务的"黄页" |
| TechDocs | 基于Markdown的技术文档系统 | 工程版Wiki |
| Software Template | 软件模板,一键创建标准化项目 | 脚手架CLI的Web版 |
| Plugin | Backstage插件,扩展功能模块 | 浏览器扩展 |
内部开发者平台的5大痛点
- 服务发现困难:几百个微服务,找不到谁负责、怎么部署、在哪监控
- 文档散落各处:Confluence、GitLab Wiki、飞书文档……找不到也看不懂
- 新项目启动慢:每次从零搭脚手架,CI/CD、监控、日志配置重复劳动
- 工具链割裂:Jenkins、ArgoCD、Grafana、Jira……来回切换效率低下
- 合规审计难:谁改了什么、谁有权限、服务依赖关系一锅粥
模式一:Backstage架构与安装
Backstage采用插件化单体架构(Plugin Monolith),核心是Catalog + TechDocs + Scaffold + Search四大模块,通过插件扩展生态。
# Backstage安装与初始化
# 运行环境: Node.js 20.x+ / yarn 1.22+ / Git 2.40+
# 依赖版本: @backstage/cli 1.32+ / @backstage/core 1.30+
# 1. 创建Backstage应用
npx @backstage/create-app@latest --name my-idp
cd my-idp
# 2. 项目结构
# my-idp/
# ├── app/ # 前端React应用
# │ ├── src/
# │ │ ├── components/ # 自定义组件
# │ │ ├── plugins/ # 前端插件
# │ │ └── App.tsx # 应用入口
# ├── packages/
# │ ├── backend/ # 后端Node.js服务
# │ └── app/ # 前端构建包
# ├── plugins/ # 自定义插件目录
# ├── catalog-info.yaml # Catalog实体定义
# └── app-config.yaml # 应用配置
# 3. 启动开发服务器
yarn dev
# 4. 构建生产版本
yarn build:backend
# app-config.yaml: Backstage核心配置
# 运行环境: Backstage 1.32+
app:
title: 企业开发者门户
baseUrl: http://localhost:3000
organization:
name: MyCompany
backend:
baseUrl: http://localhost:7007
listen:
port: 7007
csp:
connect-src: ["'self'", 'http:', 'https:']
cors:
origin: http://localhost:3000
methods: [GET, HEAD, PATCH, POST, PUT, DELETE]
credentials: true
database:
client: pg
connection:
host: ${POSTGRES_HOST}
port: ${POSTGRES_PORT:-5432}
user: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
database: backstage_plugin
integrations:
github:
- host: github.com
token: ${GITHUB_TOKEN}
gitlab:
- host: gitlab.mycompany.com
token: ${GITLAB_TOKEN}
auth:
environment: development
providers:
github:
development:
clientId: ${GITHUB_CLIENT_ID}
clientSecret: ${GITHUB_CLIENT_SECRET}
oidc:
production:
metadataUrl: ${OIDC_METADATA_URL}
clientId: ${OIDC_CLIENT_ID}
clientSecret: ${OIDC_CLIENT_SECRET}
catalog:
rules:
- allow: [Component, System, API, Resource, Location, Template]
locations:
- type: url
target: https://github.com/mycompany/catalog/blob/main/catalog-info.yaml
- type: url
target: https://gitlab.mycompany.com/platform/catalog/-/blob/main/all.yaml
techdocs:
builder: 'local'
generator:
runIn: 'docker'
publisher:
type: 'local'
模式二:软件目录Catalog
Catalog是Backstage的核心——所有服务的元数据注册中心。通过YAML描述文件定义实体,自动发现和索引服务。
# catalog-info.yaml: 服务组件注册
# 运行环境: Backstage 1.32+ / Catalog API v1
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: order-service
description: 订单核心服务,处理订单创建、支付、履约全流程
annotations:
backstage.io/source-location: url:https://github.com/mycompany/order-service
backstage.io/techdocs-ref: dir:.
github.com/project-slug: mycompany/order-service
gitlab.com/project-id: "12345"
jira.com/project-key: ORD
grafana/dashboard-tag: order-service
prometheus.io/alert: order-service-alerts
tags:
- java
- spring-boot
- microservice
- tier-1
links:
- url: https://grafana.mycompany.com/d/order-service
title: Grafana监控
icon: dashboard
- url: https://argocd.mycompany.com/applications/order-service
title: ArgoCD部署
icon: cloud
- url: https://order-service.mycompany.com/swagger
title: API文档
icon: api
spec:
type: service
lifecycle: production
owner: team-order
system: order-system
dependsOn:
- component:payment-service
- component:inventory-service
- resource:order-db
providesApis:
- order-api
consumesApis:
- payment-api
- inventory-api
---
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
name: order-api
description: 订单服务REST API
spec:
type: openapi
lifecycle: production
owner: team-order
system: order-system
definition:
$text: https://raw.githubusercontent.com/mycompany/order-service/main/openapi.yaml
---
apiVersion: backstage.io/v1alpha1
kind: System
metadata:
name: order-system
description: 订单系统,包含订单、支付、库存等核心服务
spec:
owner: team-order
domain: commerce
---
apiVersion: backstage.io/v1alpha1
kind: Group
metadata:
name: team-order
description: 订单团队
spec:
type: team
parent: dept-commerce
children: []
members:
- zhang.san
- li.si
- wang.wu
// TypeScript: 自定义Catalog实体处理器
// 运行环境: Node.js 20.x+ / @backstage/plugin-catalog-node 1.12+
import {
CatalogProcessor,
CatalogProcessorEmit,
processingResult,
} from '@backstage/plugin-catalog-node';
import { LocationSpec, Location } from '@backstage/plugin-catalog-common';
import { Entity } from '@backstage/catalog-model';
export class CustomServiceProcessor implements CatalogProcessor {
getProcessorName(): string {
return 'CustomServiceProcessor';
}
async validateLocationKind(location: Location): Promise<boolean> {
return location.type === 'url';
}
async preProcessEntity(
entity: Entity,
location: LocationSpec,
emit: CatalogProcessorEmit,
): Promise<Entity> {
// 自动为所有生产环境服务添加合规标签
if (
entity.kind === 'Component' &&
entity.spec?.lifecycle === 'production'
) {
const annotations = entity.metadata.annotations ?? {};
annotations['compliance.mycompany.com/scan-required'] = 'true';
annotations['compliance.mycompany.com/last-scan'] = new Date().toISOString();
entity.metadata.annotations = annotations;
}
// 自动生成服务依赖关系
if (entity.kind === 'Component' && entity.spec?.dependsOn) {
const deps = entity.spec.dependsOn as string[];
for (const dep of deps) {
emit(
processingResult.relation({
source: {
name: entity.metadata.name,
namespace: entity.metadata.namespace ?? 'default',
kind: entity.kind,
},
target: {
name: dep.replace('component:', ''),
namespace: 'default',
kind: 'Component',
},
type: 'dependsOn',
}),
);
}
}
return entity;
}
}
模式三:技术文档TechDocs
TechDocs基于MkDocs + Markdown,文档即代码(Docs-as-Code),和代码仓库同生命周期。
# mkdocs.yaml: TechDocs文档配置
# 运行环境: MkDocs 1.6+ / mkdocs-material 9.5+
site_name: Order Service 技术文档
site_description: 订单服务完整技术文档
nav:
- 首页: index.md
- 快速开始: getting-started.md
- 架构设计:
- 系统架构: architecture/overview.md
- 数据模型: architecture/data-model.md
- API设计: architecture/api-design.md
- 运维手册:
- 部署指南: ops/deployment.md
- 监控告警: ops/monitoring.md
- 故障排查: ops/troubleshooting.md
- 开发规范:
- 代码规范: dev/coding-standards.md
- Git工作流: dev/git-workflow.md
- 测试策略: dev/testing.md
plugins:
- techdocs-core:
add_mermaid: true
add_plantuml: true
markdown_extensions:
- admonition
- codehilite
- footnotes
- meta
- toc:
permalink: true
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_code_format
<!-- docs/index.md: TechDocs首页 -->
# Order Service
## 概述
Order Service 是订单系统的核心微服务,负责处理订单创建、支付、履约全流程。
## 快速链接
| 资源 | 链接 |
|------|------|
| 代码仓库 | [GitHub](https://github.com/mycompany/order-service) |
| CI/CD | [Jenkins](https://jenkins.mycompany.com/job/order-service) |
| 监控面板 | [Grafana](https://grafana.mycompany.com/d/order-service) |
| API文档 | [Swagger](https://order-service.mycompany.com/swagger) |
## 架构图
```mermaid
graph TB
A[API Gateway] --> B[Order Service]
B --> C[Payment Service]
B --> D[Inventory Service]
B --> E[(Order DB)]
B --> F[Redis Cache]
B --> G[Kafka]
关键指标
| 指标 | 目标 | 当前 |
|---|---|---|
| P99延迟 | <200ms | 150ms |
| 可用性 | 99.95% | 99.97% |
| 错误率 | <0.1% | 0.05% |
## 模式四:插件开发
Backstage的插件系统是其核心竞争力。自定义插件可以让IDP真正适配你的企业工具链。
```typescript
// TypeScript: Backstage自定义插件 - 服务健康检查面板
// 运行环境: Node.js 20.x+ / @backstage/core-plugin-api 1.9+ / React 18.x
// --- 前端插件 ---
// plugins/service-health/src/plugin.ts
import {
createPlugin,
createRoutableExtension,
} from '@backstage/core-plugin-api';
export const serviceHealthPlugin = createPlugin({
id: 'service-health',
routes: {
root: rootRouteRef,
},
});
export const ServiceHealthPage = serviceHealthPlugin.provide(
createRoutableExtension({
name: 'ServiceHealthPage',
component: () =>
import('./components/ServiceHealthPanel').then(
(m) => m.ServiceHealthPanel,
),
mountPoint: rootRouteRef,
}),
);
// plugins/service-health/src/components/ServiceHealthPanel.tsx
import React from 'react';
import { useEntity } from '@backstage/plugin-catalog-react';
import {
Header,
Page,
Content,
InfoCard,
Progress,
StatusOK,
StatusError,
StatusWarning,
} from '@backstage/core-components';
import { useApi } from '@backstage/core-plugin-api';
import { serviceHealthApiRef } from '../api';
interface HealthCheckResult {
name: string;
status: 'healthy' | 'degraded' | 'down';
latency_ms: number;
last_check: string;
message: string;
}
export const ServiceHealthPanel: React.FC = () => {
const { entity } = useEntity();
const healthApi = useApi(serviceHealthApiRef);
const [healthData, setHealthData] = React.useState<HealthCheckResult[]>([]);
const [loading, setLoading] = React.useState(true);
React.useEffect(() => {
const serviceName = entity.metadata.name;
healthApi
.getServiceHealth(serviceName)
.then((data) => {
setHealthData(data.checks);
setLoading(false);
})
.catch(() => setLoading(false));
}, [entity, healthApi]);
if (loading) return <Progress />;
const StatusIcon = ({ status }: { status: string }) => {
switch (status) {
case 'healthy':
return <StatusOK />;
case 'degraded':
return <StatusWarning />;
case 'down':
return <StatusError />;
default:
return null;
}
};
return (
<Page themeId="tool">
<Header title={`${entity.metadata.name} 健康检查`} />
<Content>
{healthData.map((check) => (
<InfoCard key={check.name} title={check.name}>
<StatusIcon status={check.status} />
<p>状态: {check.status}</p>
<p>延迟: {check.latency_ms}ms</p>
<p>上次检查: {check.last_check}</p>
<p>消息: {check.message}</p>
</InfoCard>
))}
</Content>
</Page>
);
};
// TypeScript: Backstage后端插件
// 运行环境: Node.js 20.x+ / @backstage/backend-common 0.25+
// plugins/service-health-backend/src/plugin.ts
import {
createBackendPlugin,
coreServices,
} from '@backstage/backend-plugin-api';
import { createRouter } from './router';
export const serviceHealthBackendPlugin = createBackendPlugin({
pluginId: 'service-health',
register(env) {
env.registerInit({
deps: {
logger: coreServices.logger,
config: coreServices.rootConfig,
httpRouter: coreServices.httpRouter,
discovery: coreServices.discovery,
},
async init({ logger, config, httpRouter, discovery }) {
const router = await createRouter({
logger,
config,
discovery,
});
httpRouter.use(router);
httpRouter.addAuthPolicy({
path: '/health',
allow: 'unauthenticated',
});
logger.info('Service Health plugin initialized');
},
});
},
});
// plugins/service-health-backend/src/router.ts
import express, { Router } from 'express';
import { LoggerService, RootConfigService, DiscoveryService } from '@backstage/backend-plugin-api';
interface RouterOptions {
logger: LoggerService;
config: RootConfigService;
discovery: DiscoveryService;
}
export async function createRouter(
options: RouterOptions,
): Promise<Router> {
const { logger, config } = options;
const router = Router();
// 健康检查端点
router.get('/health', (_req, res) => {
res.json({ status: 'ok' });
});
// 服务健康查询
router.get('/services/:serviceName/health', async (req, res) => {
const { serviceName } = req.params;
try {
// 对接企业监控系统(如Prometheus、Datadog)
const healthChecks = await fetchServiceHealth(config, serviceName);
res.json({
service: serviceName,
checks: healthChecks,
timestamp: new Date().toISOString(),
});
} catch (error) {
logger.error(`Failed to fetch health for ${serviceName}: ${error}`);
res.status(500).json({ error: 'Health check failed' });
}
});
return router;
}
async function fetchServiceHealth(
config: RootConfigService,
serviceName: string,
): Promise<Array<{
name: string;
status: 'healthy' | 'degraded' | 'down';
latency_ms: number;
last_check: string;
message: string;
}>> {
// 实际对接Prometheus/Grafana/Datadog API
const prometheusUrl = config.getString('monitoring.prometheus.url');
// 模拟健康检查结果
return [
{
name: 'HTTP端点',
status: 'healthy',
latency_ms: 45,
last_check: new Date().toISOString(),
message: '所有端点正常响应',
},
{
name: '数据库连接',
status: 'healthy',
latency_ms: 12,
last_check: new Date().toISOString(),
message: '连接池正常',
},
{
name: 'Kafka消费者',
status: 'degraded',
latency_ms: 250,
last_check: new Date().toISOString(),
message: '消费延迟超过阈值',
},
];
}
模式五:生产级IDP部署
# docker-compose.yml: Backstage生产级部署
# 运行环境: Docker Compose v2.30+ / PostgreSQL 16
version: "3.8"
services:
backstage:
image: mycompany/backstage:1.32.0
ports:
- "7007:7007"
environment:
APP_CONFIG_app_baseUrl: https://idp.mycompany.com
APP_CONFIG_backend_baseUrl: https://idp.mycompany.com
APP_CONFIG_backend_database_client: pg
APP_CONFIG_backend_database_connection_host: postgres
APP_CONFIG_backend_database_connection_port: "5432"
APP_CONFIG_backend_database_connection_user: ${POSTGRES_USER}
APP_CONFIG_backend_database_connection_password: ${POSTGRES_PASSWORD}
POSTGRES_HOST: postgres
POSTGRES_PORT: "5432"
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
GITHUB_TOKEN: ${GITHUB_TOKEN}
GITLAB_TOKEN: ${GITLAB_TOKEN}
depends_on:
postgres:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:7007/healthcheck"]
interval: 30s
timeout: 10s
retries: 3
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: backstage_plugin
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
volumes:
postgres_data:
# kubernetes/backstage-deployment.yaml: K8s生产部署
# 运行环境: Kubernetes 1.30+ / Helm 3.15+
apiVersion: apps/v1
kind: Deployment
metadata:
name: backstage
namespace: idp
labels:
app: backstage
spec:
replicas: 3
selector:
matchLabels:
app: backstage
template:
metadata:
labels:
app: backstage
spec:
containers:
- name: backstage
image: mycompany/backstage:1.32.0
ports:
- containerPort: 7007
env:
- name: APP_CONFIG_app_baseUrl
value: "https://idp.mycompany.com"
- name: APP_CONFIG_backend_baseUrl
value: "https://idp.mycompany.com"
- name: APP_CONFIG_backend_database_client
value: "pg"
- name: APP_CONFIG_backend_database_connection_host
valueFrom:
secretKeyRef:
name: backstage-db-secret
key: host
- name: APP_CONFIG_backend_database_connection_password
valueFrom:
secretKeyRef:
name: backstage-db-secret
key: password
resources:
requests:
cpu: "500m"
memory: "512Mi"
limits:
cpu: "2000m"
memory: "2Gi"
livenessProbe:
httpGet:
path: /healthcheck
port: 7007
initialDelaySeconds: 30
periodSeconds: 30
readinessProbe:
httpGet:
path: /healthcheck
port: 7007
initialDelaySeconds: 10
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: backstage
namespace: idp
spec:
selector:
app: backstage
ports:
- port: 80
targetPort: 7007
type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: backstage
namespace: idp
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
tls:
- hosts:
- idp.mycompany.com
secretName: backstage-tls
rules:
- host: idp.mycompany.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: backstage
port:
number: 80
# Helm部署Backstage(推荐方式)
# 运行环境: Helm 3.15+ / Kubernetes 1.30+
# 1. 添加Backstage Helm仓库
helm repo add backstage https://backstage.github.io/charts
helm repo update
# 2. 创建values.yaml覆盖配置
cat > backstage-values.yaml << 'EOF'
backstage:
image:
repository: mycompany/backstage
tag: 1.32.0
extraAppConfig:
- configMapRef: backstage-config
extraEnvVarsSecrets:
- backstage-secrets
ingress:
enabled: true
host: idp.mycompany.com
tls:
enabled: true
secretName: backstage-tls
postgresql:
enabled: true
primary:
persistence:
size: 20Gi
auth:
existingSecret: backstage-db-secret
EOF
# 3. 部署
helm install backstage backstage/backstage \
-n idp \
--create-namespace \
-f backstage-values.yaml
# 4. 验证
kubectl get pods -n idp
kubectl port-forward svc/backstage 7007:80 -n idp
避坑指南:5个常见陷阱
坑1:Catalog实体注册后不显示
❌ 错误做法:只在本地创建catalog-info.yaml,未注册Location
✅ 正确做法:在app-config.yaml中添加locations,或在UI中注册Location
坑2:TechDocs构建失败
❌ 错误做法:直接在宿主机运行MkDocs,依赖缺失导致构建失败
✅ 正确做法:配置techdocs.generator.runIn: 'docker',使用容器化构建
坑3:GitHub/GitLab集成Token权限不足
# ❌ 错误:Token只有repo:read权限
# ✅ 正确:Token需要以下权限
# GitHub: repo, read:org, read:user
# GitLab: api, read_repository, read_api
坑4:插件开发时热更新不生效
# ❌ 错误:修改插件代码后未重启开发服务器
# ✅ 正确:确保yarn dev在运行,Backstage支持HMR热更新
# 如果HMR不生效,清除缓存重启:
yarn cache clean
yarn dev
坑5:生产环境数据库连接池耗尽
# app-config.yaml: 配置连接池
backend:
database:
client: pg
connection:
host: postgres
port: 5432
user: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
# ✅ 关键:配置连接池
pool:
min: 5
max: 20
idleTimeoutMillis: 30000
connectionTimeoutMillis: 5000
报错排查表
| 报错信息 | 原因 | 解决方案 |
|---|---|---|
Failed to fetch catalog entities |
GitHub/GitLab Token无效或权限不足 | 检查Token权限,确保有repo和read:org |
ECONNREFUSED 127.0.0.1:5432 |
PostgreSQL未启动或连接配置错误 | 检查数据库服务和连接参数 |
TechDocs generation failed |
MkDocs构建失败,缺少依赖 | 配置runIn: 'docker',或安装缺失Python包 |
Plugin not found: xxx |
插件未注册到backend | 在packages/backend/src/index.ts中import并注册插件 |
Unauthorized: Invalid token |
OIDC/OAuth配置错误 | 检查clientId/clientSecret和回调URL |
CORS error |
前后端域名不一致 | 配置backend.cors.origin匹配前端URL |
Location not found |
catalog-info.yaml URL不可访问 | 验证URL可达性和Token权限 |
Out of memory |
Node.js堆内存不足 | 设置NODE_OPTIONS=--max-old-space-size=4096 |
Schema validation failed |
catalog-info.yaml格式错误 | 使用backstage-cli catalog-validate验证 |
Template execution timeout |
Software Template执行超时 | 检查模板中的HTTP请求,增加超时配置 |
进阶优化:5个生产级技巧
技巧1:Catalog自动发现
// TypeScript: GitLab自动发现处理器
// 运行环境: @backstage/plugin-catalog-backend-module-gitlab 0.8+
import { GitLabDiscoveryProcessor } from '@backstage/plugin-catalog-backend-module-gitlab';
// app-config.yaml配置
const config = {
catalog: {
processors: [
GitLabDiscoveryProcessor.fromConfig(env.config, {
logger: env.logger,
// 自动发现gitlab.mycompany.com/group/project下的所有catalog-info.yaml
schedule: {
frequency: { minutes: 30 },
timeout: { minutes: 3 },
initialDelay: { seconds: 15 },
},
}),
],
},
};
技巧2:RBAC权限控制
# app-config.yaml: RBAC配置
# 运行环境: @backstage/plugin-permission-backend 0.6+
permission:
enabled: true
rbac:
policies:
- name: 'role:default/developer'
permissions:
- 'catalog.entity.read'
- 'techdocs.read'
- 'scaffolder.template.execute'
- name: 'role:default/admin'
permissions:
- 'catalog.entity.create'
- 'catalog.entity.delete'
- 'catalog.entity.update'
- 'techdocs.write'
- 'scaffolder.template.create'
policyFile: ./rbac-policy.csv
技巧3:搜索增强
# app-config.yaml: 搜索引擎配置
# 运行环境: @backstage/plugin-search-backend-module-elasticsearch 1.6+
search:
collators:
techdocs:
schedule:
frequency: { minutes: 10 }
timeout: { minutes: 5 }
initialDelay: { seconds: 30 }
elasticsearch:
url: ${ELASTICSEARCH_URL}
auth:
username: ${ELASTICSEARCH_USER}
password: ${ELASTICSEARCH_PASSWORD}
indexPrefix: backstage_search_
技巧4:多集群ArgoCD集成
# app-config.yaml: ArgoCD多集群集成
# 运行环境: @backstage/plugin-argocd 2.5+
argocd:
appLocatorMethods:
- type: 'config'
instances:
- name: production
url: https://argocd.mycompany.com
token: ${ARGOCD_TOKEN_PROD}
- name: staging
url: https://argocd-staging.mycompany.com
token: ${ARGOCD_TOKEN_STAGING}
技巧5:Golden Path模板
# templates/java-spring-boot/template.yaml: Golden Path脚手架模板
# 运行环境: @backstage/plugin-scaffolder 1.25+
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: java-spring-boot-service
title: Java Spring Boot微服务模板
description: 创建标准化的Spring Boot微服务,包含CI/CD、监控、文档
spec:
owner: platform-team
type: service
parameters:
- title: 服务基本信息
required:
- name
- owner
properties:
name:
title: 服务名称
type: string
pattern: '^[a-z][a-z0-9-]*$'
description: 小写字母开头,只含小写字母、数字和连字符
owner:
title: 负责团队
type: string
ui:field: OwnerPicker
ui:options:
allowedKinds:
- Group
description:
title: 服务描述
type: string
description: 一句话描述服务功能
database:
title: 数据库类型
type: string
default: postgresql
enum:
- postgresql
- mysql
- mongodb
- none
- title: CI/CD配置
properties:
ciProvider:
title: CI工具
type: string
default: github-actions
enum:
- github-actions
- gitlab-ci
- jenkins
deployTarget:
title: 部署目标
type: string
default: kubernetes
enum:
- kubernetes
- ecs
- cloud-run
steps:
- id: fetch-template
name: 拉取模板代码
action: fetch:template
input:
url: ./skeleton
values:
name: ${{ parameters.name }}
owner: ${{ parameters.owner }}
description: ${{ parameters.description }}
database: ${{ parameters.database }}
ciProvider: ${{ parameters.ciProvider }}
deployTarget: ${{ parameters.deployTarget }}
- id: publish
name: 发布到Git仓库
action: publish:github
input:
allowedHosts: ['github.com']
description: ${{ parameters.description }}
repoUrl: github.com?owner=mycompany&repo=${{ parameters.name }}
defaultBranch: main
protectDefaultBranch: true
- id: register
name: 注册到Catalog
action: catalog:register
input:
repoContentsUrl: ${{ steps.publish.output.repoContentsUrl }}
catalogInfoPath: '/catalog-info.yaml'
output:
links:
- title: 仓库地址
url: ${{ steps.publish.output.remoteUrl }}
- title: 打开Catalog
url: https://idp.mycompany.com/catalog/default/component/${{ parameters.name }}
IDP平台对比分析
| 维度 | Backstage | Port | Humanitec |
|---|---|---|---|
| 开源 | ✅ Apache 2.0 | ❌ 商业SaaS | ❌ 商业SaaS |
| 自托管 | ✅ 完全可控 | ❌ 云托管 | ❌ 云托管 |
| 插件生态 | 200+社区插件 | 内置集成 | 内置集成 |
| 学习曲线 | 中高(需TypeScript) | 低(可视化配置) | 中(平台工程概念) |
| 定制化 | 极高(代码级) | 中(API扩展) | 中(Score定义) |
| 软件目录 | ✅ 核心功能 | ✅ 核心功能 | ✅ 核心功能 |
| TechDocs | ✅ 原生支持 | ❌ 需集成 | ❌ 需集成 |
| 成本 | 人力成本(开发维护) | $50-200/用户/月 | $100-500/用户/月 |
| 适用规模 | 50-5000+开发者 | 10-500开发者 | 100-5000+开发者 |
| 典型客户 | Spotify、American Airlines | Lyft、Palo Alto | BMW、Qonto |
总结
Backstage是2026年构建内部开发者平台的最优选择——开源、可自托管、插件生态丰富。但要注意:
- 小团队(<50人):优先考虑Port等SaaS方案,Backstage的维护成本可能不划算
- 中型团队(50-500人):Backstage是最佳选择,投入2-3人维护即可
- 大型团队(500+人):Backstage + Golden Path模板 + 自动发现,构建完整的平台工程体系
关键成功要素:先上Catalog和TechDocs,再逐步加插件,最后做Golden Path模板。不要试图一步到位。
在线工具推荐
- /zh-CN/json/format - JSON格式化,处理Catalog实体YAML转JSON
- /zh-CN/dev/curl-to-code - cURL转代码,快速生成Backstage API调用
- /zh-CN/encode/hash - 哈希计算,生成服务唯一标识
- /zh-CN/text/diff - 文本对比,对比catalog-info.yaml变更
本站提供浏览器本地工具,免注册即可试用 →
#内部开发者平台#Backstage#IDP#开发者门户#平台工程#2026#DevOps运维