第 1 章 Backstage 的 ArgoCD 插件


ArgoCD 插件代表 Backstage Catalog 中应用程序的当前状态。

1.1. 对于管理员

1.1.1. 安装

用于 Backstage (RHPIB)软件包的红帽插件托管在单独的 NPM registry 中,由红帽维护。要使用这些软件包,您必须调整 NPM 配置来拉取 @redhat 有范围的软件包:

# update your .npmrc or .yarnrc file
yarn config set "@redhat:registry" https://npm.registry.redhat.com
# then pull a package
yarn add @redhat/backstage-plugin-quay

如需更多信息,请参阅 npm 文档

创建 .npmrc 文件可确保所有软件包都限定在 @redhat 下,并从 红帽的 NPM registry 获取,而其余依赖项仍来自其他 registry

先决条件

  • 您的 Backstage 应用程序已安装并部署。

流程

  1. backstage/packages/app 项目中,将 ArgoCD 插件添加为 package.json 依赖项,如下所示:

    cd packages/app
    yarn add @redhat/backstage-plugin-argo-cd
  2. 在根目录中的 app-config.yaml 文件中,将 argo-cd 添加到 proxy 对象中,如下所示:

    proxy:
      ...
    
      '/argocd/api':
        # url to the api of your hosted argoCD instance
        target: https://159.65.209.132/api/v1/
        changeOrigin: true
        # this line is required if your hosted argoCD instance has self-signed certificate
        secure: false
        headers:
          Cookie:
            $env: ARGOCD_AUTH_TOKEN
    
    
    # optional: this will link to your argoCD web UI for each argoCD application
    argocd:
      baseUrl: https://my-argocd-web-ui.com

    另外,您还可以在前面的代码中为 ArgoCD Web UI 添加基本 URL。

  3. 使用以下代码将 ArgoCD 插件添加到插件列表中:

    // packages/app/src/plugins.ts
    export { argocdPlugin } from '@redhat/backstage-plugin-argo-cd';
  4. 将 ArgoCD 插件添加到 ENT itityPage.tsx 文件中,如下所示:

    // packages/app/src/components/catalog/EntityPage.tsx
    import {
      EntityArgoCDHistoryCard,
      isArgocdAvailable,
    } from '@redhat/backstage-plugin-argo-cd';
    
    
    const overviewContent = (
      <Grid container spacing={3} alignItems="stretch">
        ...
        <EntitySwitch>
          <EntitySwitch.Case if={e => Boolean(isArgocdAvailable(e))}>
            <Grid item sm={6}>
              <EntityArgoCDHistoryCard />
            </Grid>
          </EntitySwitch.Case>
        </EntitySwitch>
        ...
      </Grid>
    );
  5. 要在 Backstage 中为组件使用 ArgoCD 插件,请在组件的 YAML 配置文件中添加注解:

    argocd/app-name: <app-name>

    要为组件选择多个 ArgoCD 应用程序,请使用标签,如下所示:

    argocd/app-selector: <app-selector>

    注意

    您可以对组件使用注解或标签。

  6. 使用用户名和密码向 ArgoCD 的 /session 端点发送 GET HTTP 请求,以获取您的身份验证密钥。
  7. 将获取的身份验证密钥添加到 Backstage 后端服务器的环境变量中,如下所示:

    ARGOCD_AUTH_TOKEN="argocd.token=<auth-token>"

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部