自定义 Tekton Hub 实例


Red Hat OpenShift Pipelines 1.10

安装 Tekton Hub 的自定义实例

Red Hat OpenShift Documentation Team

摘要

本文档提供有关安装和部署 Tekton Hub 自定义实例的信息。

第 1 章 在 OpenShift Pipelines 中使用 Tekton Hub

重要

Tekton Hub 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

Tekton Hub 可帮助您发现、搜索和共享 CI/CD 工作流可重复使用的任务和管道。Tekton Hub 的一个公共实例位于 hub.tekton.dev 中。集群管理员也可以安装和部署 Tekton Hub 的自定义实例供企业用户使用。

Tekton Hub 是一个可选组件 ; 集群管理员无法使用 TektonConfig 自定义资源(CR)安装它。要安装和管理 Tekton Hub,请使用 TektonHub CR。

注意

如果您使用 Github Enterprise 或 Gitlab Enterprise,请在与企业服务器相同的网络中安装并部署 Tekton Hub。例如,如果企业服务器在 VPN 后面运行,请在 VPN 之后也部署 Tekton Hub。

先决条件

  • 确保在集群中的默认 openshift-pipelines 命名空间中安装了 Red Hat OpenShift Pipelines Operator。

流程

  1. 创建 Tekton Hub 仓库的分叉。
  2. 克隆已分叉的存储库。
  3. 更新 config.yaml 文件,使其至少包含一个具有以下范围的用户:

    • 具有 agent:create 范围,如果目录中有任何更改,可以设置一个 cron 作业,该作业会在间隔后刷新 Tekton Hub 数据库。
    • 具有 catalog:refresh 范围的用户,它可以刷新目录以及 Tekton Hub 数据库中的所有资源。
    • 具有 config:refresh 范围的用户,可获取其他范围。

      ...
      scopes:
      - name: agent:create
        users: <username_registered_with_the_Git_repository_hosting_service_provider>
      - name: catalog:refresh
        users: <username_registered_with_the_Git_repository_hosting_service_provider>
      - name: config:refresh
        users: <username_registered_with_the_Git_repository_hosting_service_provider>
      ...
      Copy to Clipboard Toggle word wrap

      支持的服务供应商有 GitHub、GitLab 和 BitBucket。

  4. 使用托管供应商的 Git 存储库创建 OAuth 应用程序,并记下客户端 ID 和客户端 Secret。

    • 对于 GitHub OAuth 应用程序,将 Homepage URLAuthorization 回调 URL 设置为 <auth-route>
    • 对于 GitLab OAuth 应用程序,请将 REDIRECT_URI 设为 <auth-route>/auth/gitlab/callback
    • 对于 BitBucket OAuth 应用程序,将 Callback URL 设置为 <auth-route>
  5. 编辑 Tekton Hub API secret 的 <tekton_hub_repository>/config/02-api/20-api-secret.yaml 文件中的以下字段:

    • GH_CLIENT_ID :通过 Git 存储库托管服务提供商创建的 OAuth 应用程序的客户端 ID。
    • GH_CLIENT_SECRET :通过 Git 存储库托管服务提供商创建的 OAuth 应用中的客户端 Secret。
    • GHE_URL :GitHub Enterprise URL,如果您要使用 GitHub Enterprise 进行身份验证。不要提供目录的 URL 作为此字段的值。
    • GL_CLIENT_ID :来自 GitLab OAuth 应用程序的客户端 ID。
    • GL_CLIENT_SECRET :来自 GitLab OAuth 应用的客户端 Secret。
    • GLE_URL: GitLab Enterprise URL(如果使用 GitLab Enterprise 进行身份验证)。不要提供目录的 URL 作为此字段的值。
    • BB_CLIENT_ID :来自 BitBucket OAuth 应用程序的客户端 ID。
    • BB_CLIENT_SECRET :BitBucket OAuth 应用中的客户端 Secret。
    • JWT_SIGNING_KEY :用于签署为用户创建的 JSON Web 令牌(JWT)的随机字符串。
    • ACCESS_JWT_EXPIRES_IN :添加访问令牌过期的时间限制。例如,1m,其中 m 表示分钟。支持的时间单位为秒(s)、分钟(m)、小时(h)、天(d)和周(w)。
    • REFRESH_JWT_EXPIRES_IN :添加刷新令牌过期的时间限制。例如,1m,其中 m 表示分钟。支持的时间单位为秒(s)、分钟(m)、小时(h)、天(d)和周(w)。确保为令牌刷新设置的到期时间大于为令牌访问设置的到期时间。
    • AUTH_BASE_URL : OAuth 应用程序的 Route URL。

      注意
      • 将与客户端 ID 和客户端 Secret 相关的字段用于任何托管服务供应商的 Git 存储库。
      • 通过 Git 存储库托管服务提供商注册的帐户凭据,让具有 catalog: refresh 的范围可以验证和加载所有目录资源到数据库。
  6. 提交更改并将其推送到您的已分叉的存储库。
  7. 确保 TektonHub CR 类似以下示例:

    apiVersion: operator.tekton.dev/v1alpha1
    kind: TektonHub
    metadata:
      name: hub
    spec:
      targetNamespace: openshift-pipelines 
    1
    
      api:
        hubConfigUrl: https://raw.githubusercontent.com/tektoncd/hub/main/config.yaml 
    2
    Copy to Clipboard Toggle word wrap
    1
    需要安装 Tekton Hub 的命名空间;默认为 openshift-pipelines
    2
    使用您 fork 仓库的 config.yaml 文件的 URL 替换。
  8. 安装 Tekton Hub。

    $ oc apply -f TektonHub.yaml 
    1
    Copy to Clipboard Toggle word wrap
    1
    TektonConfig CR 的文件名或路径。
  9. 检查安装的状态。

    $ oc get tektonhub.operator.tekton.dev
    NAME   VERSION   READY   REASON   APIURL                    UIURL
    hub    v1.7.2    True             https://api.route.url/    https://ui.route.url/
    Copy to Clipboard Toggle word wrap

1.1.1. 在 Tekton Hub 中手动刷新目录

当您在 Red Hat OpenShift Pipelines 集群上安装并部署 Tekton Hub 时,也会安装 Postgres 数据库。最初,数据库为空。要将目录中可用的任务和管道添加到数据库,集群管理员必须刷新目录。

先决条件

  • 确保您位于 <tekton_hub_repository>/config/ 目录中。

流程

  1. 在 Tekton Hub UI 中,点击 Login -→ Sign In with GitHub

    注意

    GitHub 在公共的 Tekton Hub UI 中用作示例。对于在集群中的自定义安装,列出了您提供的客户端 ID 和客户端 Secret 的所有 Git 存储库托管服务供应商。

  2. 在主页上,点击 user profile 并复制令牌。
  3. 调用 Catalog Refresh API。

    • 要使用特定名称刷新目录,请运行以下命令:

      $ curl -X POST -H "Authorization: <jwt-token>" \ 
      1
      
        <api-url>/catalog/<catalog_name>/refresh 
      2
      Copy to Clipboard Toggle word wrap
      1
      从 UI 复制的 Tekton Hub 令牌。
      2
      目录的 API pod URL 和名称。

      输出示例:

      [{"id":1,"catalogName":"tekton","status":"queued"}]
      Copy to Clipboard Toggle word wrap
    • 要刷新所有目录,请运行以下命令:

      $ curl -X POST -H "Authorization: <jwt-token>" \ 
      1
      
        <api-url>/catalog/refresh 
      2
      Copy to Clipboard Toggle word wrap
      1
      从 UI 复制的 Tekton Hub 令牌
      2
      API pod URL。
  4. 在浏览器中刷新页面。

集群管理员可选择性地设置一个 cron 作业,以便在固定间隔后刷新数据库,因此目录中的更改会出现在 Tekton Hub web 控制台中。

注意

如果资源添加到目录或更新,则刷新目录会在 Tekton Hub UI 中显示这些更改。但是,如果从目录中删除资源,则刷新目录不会从数据库中删除资源。Tekton Hub UI 继续显示已删除的资源。

先决条件

  • 确保您位于 <project_root>/config/ 目录中,其中 <project_root> 是克隆的 Tekton Hub 存储库的顶级目录。
  • 确保您有一个 JSON Web 令牌(JWT)令牌,其范围有刷新目录。

流程

  1. 创建基于代理的 JWT 令牌以供使用。

    $ curl -X PUT --header "Content-Type: application/json" \
        -H "Authorization: <access-token>" \ 
    1
    
        --data '{"name":"catalog-refresh-agent","scopes": ["catalog:refresh"]}' \
        <api-route>/system/user/agent
    Copy to Clipboard Toggle word wrap
    1
    JWT 令牌.

    带有必要范围的代理令牌以 {"token":"<agent_jwt_token>"} 格式返回。请注意返回的令牌,并保留目录刷新 cron 作业。

  2. 编辑 05-catalog-refresh-cj/50-catalog-refresh-secret.yaml 文件,将 HUB_TOKEN 参数设置为上一步中返回的 <agent_jwt_token>

    apiVersion: v1
    kind: Secret
    metadata:
      name: catalog-refresh
    type: Opaque
    stringData:
      HUB_TOKEN: <hub_token> 
    1
    Copy to Clipboard Toggle word wrap
    1
    上一步中返回的 <agent_jwt_token>
  3. 应用修改后的 YAML 文件。

    $ oc apply -f 05-catalog-refresh-cj/ -n openshift-pipelines.
    Copy to Clipboard Toggle word wrap
  4. 可选:默认情况下,cron 任务配置为每 30 分钟运行一次。要更改间隔,修改 05-catalog-refresh-cj/51-catalog-refresh-cronjob.yaml 文件中的 schedule 参数的值。

    apiVersion: batch/v1
    kind: CronJob
    metadata:
      name: catalog-refresh
      labels:
        app: tekton-hub-api
    spec:
      schedule: "*/30 * * * *"
      ...
    Copy to Clipboard Toggle word wrap

1.1.3. 可选:在 Tekton Hub 配置中添加新用户

流程

  1. 根据预期的范围,集群管理员可以在 config.yaml 文件中添加新用户。

    ...
    scopes:
      - name: agent:create
        users: [<username_1>, <username_2>] 
    1
    
      - name: catalog:refresh
        users: [<username_3>, <username_4>]
      - name: config:refresh
        users: [<username_5>, <username_6>]
    
    default:
      scopes:
        - rating:read
        - rating:write
    ...
    Copy to Clipboard Toggle word wrap
    1
    在 Git 存储库托管服务提供商中注册的用户名。
    注意

    当任何用户首次登录时,它们只会有默认范围,即使它们被添加到 config.yaml 中。要激活其他范围,请确保用户至少登录一次。

  2. 确保 config.yaml 文件中具有 config-refresh 范围。
  3. 刷新配置。

    $ curl -X POST -H "Authorization: <access-token>" \ 
    1
    
        --header "Content-Type: application/json" \
        --data '{"force": true} \
        <api-route>/system/config/refresh
    Copy to Clipboard Toggle word wrap
    1
    JWT 令牌.

1.2. 在 Developer 视角中选择 Tekton Hub

集群管理员可以选择在 Red Hat OpenShift Pipelines 集群的 Developer 视角的 Pipeline Builder 页面中显示 Tekton Hub 资源,如任务和管道。

前提条件

  • 确保在集群中安装了 Red Hat OpenShift Pipelines Operator,并且 oc 命令行工具可用。

流程

  • 要在 Developer 视角中选择显示 Tekton Hub 资源,将 TektonConfig 自定义资源(CR)中的 enable-devconsole-integration 字段设置为 false

    apiVersion: operator.tekton.dev/v1alpha1
      kind: TektonConfig
      metadata:
        name: config
      spec:
        targetNamespace: openshift-pipelines
        ...
        hub:
          params:
            - name: enable-devconsole-integration
              value: "false"
        ...
    Copy to Clipboard Toggle word wrap

    默认情况下,TektonConfig CR 不包括 enable-devconsole-integration 字段,Red Hat OpenShift Pipelines Operator 假定值为 true

法律通告

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat