管理 RPM 软件包

本页面介绍如何在 Yum 代码库中添加、查看和删除 RPM 软件包。Artifact Registry Yum 代码库支持 Yum 和 DNF。

准备工作

  1. 如果目标 Yum 代码库不存在, 请创建一个新代码库。
  2. 配置虚拟机以访问该代码库。
  3. (可选)为 gcloud 命令配置默认值。
  4. 确保元数据中的软件包名称符合 Fedora 软件包命名准则和 Fedora 软件包版本控制准则。

添加软件包

代码库模式: 标准

您必须同时拥有对代码库的读取和写入 权限,才能添加软件包。

您可以使用 Google Cloud CLI 将软件包上传到代码库,也可以导入存储在 Cloud Storage 中的软件包。

非常长的导入或上传操作可能会超出 gcloud CLI 用于调用 API 的令牌的有效期。如果要添加的软件包数量非常多,请考虑分批添加,以便每个上传或导入操作都可以在较短的时间内完成。 如需了解详情,请参阅操作系统软件包问题排查文档。

直接上传

使用 gcloud artifacts yum upload命令 将软件包上传到 Yum 代码库:

gcloud artifacts yum upload REPOSITORY \
    --location=LOCATION \
    --source=PACKAGES

替换以下值:

  • REPOSITORY 是 Artifact Registry 代码库名称。
  • LOCATION 是代码库的区域 位置。
  • PACKAGES 是软件包的路径。

例如,如需将软件包 my-package.rpm 上传到位置为 u-france-east1 的 Yum 代码库 my-repo,请运行以下命令:

gcloud artifacts yum upload my-repo \
    --location=u-france-east1 \
    --source=my-package.rpm

Cloud Storage

  1. 将软件包直接上传到 Cloud Storage 存储桶。
  2. 运行以下命令:
    gcloud artifacts yum import REPOSITORY \
      --location=LOCATION \
      --gcs-source=PACKAGES
    

    替换以下值:

    • REPOSITORY 是 Artifact Registry 代码库名称。
    • LOCATION 是代码库的区域 位置。
    • PACKAGES 是 Cloud Storage 中以英文逗号分隔的软件包列表 。如需上传目录中的所有软件包,请使用 目录通配符 (*);如需上传所有子目录中的所有软件包,请使用递归目录通配符 (**)。

    例如,以下命令会将存储桶 my-bucket中的软件包package.rpm和 directory目录中的所有 软件包上传到位置为 u-france-east1的 Yum 代码库my-repo:

    gcloud artifacts yum import my-repo \
      --location=u-france-east1 \
      --gcs-source=gs://my-bucket/path/to/package.rpm,gs://my-bucket/directory*
    

上传或导入操作完成后,您可以使用 Cloud de Confiance 控制台或 gcloud CLI 查看代码库中的 软件包,并确认软件包已成功上传。

如果您有一个包含大量软件包的大型代码库,则可能需要几分钟时间才能重新生成软件包索引,以便 Yum 客户端能够看到新软件包。

查看软件包

代码库模式: 标准

如需查看软件包,您必须拥有 Artifact Registry Reader 角色的权限。 Artifact Registry 不会列出软件包中的文件。

如需使用 Cloud de Confiance 控制台 或 gcloud 查看软件包和软件包版本,请执行以下操作:

控制台

  1. 在 Cloud de Confiance 控制台中打开代码库 页面。

    打开“代码库”页面

  2. 在代码库列表中,点击相应代码库。

    软件包页面列出代码库中的软件包。

  3. 点击一个软件包以查看它的版本。

gcloud

如需列出代码库中的软件包,请运行以下命令:

gcloud artifacts packages list [--repository=REPOSITORY] [--location=LOCATION]

替换以下内容:

  • REPOSITORY 是代码库的名称。如果您 配置了默认代码库,则可以省略此标志以使用默认值。
  • LOCATION 是代码库的区域 位置。 如果您配置了 默认位置,则您 可以省略此标志以使用默认值。

如需查看软件包的版本,请运行以下命令:

gcloud artifacts versions list --package=PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION]

替换以下内容:

  • PACKAGE 是软件包的 ID 或软件包的完全限定 标识符。
  • REPOSITORY 是代码库的名称。如果您 配置了默认 代码库,则可以省略此标志以使用默认值。
  • LOCATION 是代码库的区域 位置。 使用此标志可查看特定位置的代码库。 如果您配置了默认 位置,则可以省略此标志以使用默认值。

安装软件包

代码库模式: 标准

在安装软件包之前,请验证您是否已将虚拟机 配置为从 Artifact Registry 代码库安装 软件包。

如需安装软件包,请运行以下命令:

sudo yum --enablerepo=REPOSITORY install PACKAGE

替换以下值:

  • PACKAGE 是软件包名称
  • REPOSITORY 是在 .repo 文件中配置的代码库的名称。

例如,如需从代码库 my-repo 安装软件包 my-package,请运行以下命令:

sudo yum --enablerepo=my-repo install my-package

删除软件包

代码库模式: 标准

Before you delete a package or package version, verify that any you have communicated or addressed any important dependencies on it.

To delete a package:

Console

  1. Open the Repositories page in the Cloud de Confiance console.

    打开“代码库”页面

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Select the package that you want to delete.

  4. Click DELETE.

  5. In the confirmation dialog box, click DELETE.

gcloud

Run the following command:

gcloud artifacts packages delete PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION] [--async]

Replace the following:

  • PACKAGE is the name of the package in the repository.
  • REPOSITORY is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.
  • LOCATION is the regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.

The --async flag causes the command to return immediately, without waiting for the operation in progress to complete.

To delete versions of a package:

Console

  1. Open the Repositories page in the Cloud de Confiance console.

    打开“代码库”页面

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Click a package to view versions of that package.

  4. Select versions that you want to delete.

  5. Click DELETE.

  6. In the confirmation dialog box, click DELETE.

gcloud

Run the following command:

gcloud artifacts versions delete VERSION \
    --package=PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION] \
    [--async]

Replace the following:

  • VERSION is the name of the version to delete.
  • PACKAGE is the name of the package in the repository.
  • REPOSITORY is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.
  • LOCATION is the regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.

The --async flag causes the command to return immediately, without waiting for the operation in progress to complete.

对于大型代码库,可能需要几分钟时间才能重新生成 Yum 软件包索引以反映删除操作。

后续步骤