本页面介绍如何在 Yum 代码库中添加、查看和删除 RPM 软件包。Artifact Registry Yum 代码库支持 Yum 和 DNF。
准备工作
- 如果目标 Yum 代码库不存在, 请创建一个新代码库。
- 配置虚拟机以访问该代码库。
- (可选)为 gcloud 命令配置默认值。
- 确保元数据中的软件包名称符合 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
- 将软件包直接上传到 Cloud Storage 存储桶。
- 运行以下命令:
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 查看软件包和软件包版本,请执行以下操作:
控制台
在 Cloud de Confiance 控制台中打开代码库 页面。
在代码库列表中,点击相应代码库。
软件包页面列出代码库中的软件包。
点击一个软件包以查看它的版本。
gcloud
如需列出代码库中的软件包,请运行以下命令:
gcloud artifacts packages list [--repository=REPOSITORY] [--location=LOCATION]
替换以下内容:
如需查看软件包的版本,请运行以下命令:
gcloud artifacts versions list --package=PACKAGE \
[--repository=REPOSITORY] [--location=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
Open the Repositories page in the Cloud de Confiance console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Select the package that you want to delete.
Click DELETE.
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:
PACKAGEis the name of the package in the repository.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis 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
Open the Repositories page in the Cloud de Confiance console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Click a package to view versions of that package.
Select versions that you want to delete.
Click DELETE.
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:
VERSIONis the name of the version to delete.PACKAGEis the name of the package in the repository.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis 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 软件包索引以反映删除操作。