第 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 应用程序已安装并部署。
流程
在
backstage/packages/app项目中,将 ArgoCD 插件添加为package.json依赖项,如下所示:cd packages/app yarn add @redhat/backstage-plugin-argo-cd在根目录中的
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。
使用以下代码将 ArgoCD 插件添加到插件列表中:
// packages/app/src/plugins.ts export { argocdPlugin } from '@redhat/backstage-plugin-argo-cd';将 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> );要在 Backstage 中为组件使用 ArgoCD 插件,请在组件的 YAML 配置文件中添加注解:
argocd/app-name: <app-name>要为组件选择多个 ArgoCD 应用程序,请使用标签,如下所示:
argocd/app-selector: <app-selector>注意您可以对组件使用注解或标签。
-
使用用户名和密码向 ArgoCD 的
/session端点发送 GET HTTP 请求,以获取您的身份验证密钥。 将获取的身份验证密钥添加到 Backstage 后端服务器的环境变量中,如下所示:
ARGOCD_AUTH_TOKEN="argocd.token=<auth-token>"