在 Artifact Registry 中存储 Conda 软件包
本快速入门介绍如何设置私有 Artifact Registry Conda 代码库,然后向该代码库上传软件包。
准备工作
-
In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Cloud de Confiance project.
Enable the Artifact Registry API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Make sure that you have the following role or roles on the project: Artifact Registry Administrator
Check for the roles
-
In the Cloud de Confiance console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Cloud de Confiance console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies, or contact your administrator.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
- 如需在 Cloud de Confiance 环境中使用 Conda CLI,请安装以下 Conda 软件包管理器之一:
启动 Cloud Shell
在本快速入门中,您将使用 Cloud Shell,这是一个用于管理Cloud de Confiance by S3NS上托管资源的 Shell 环境。
Cloud Shell 预安装有 Google Cloud CLI 和 Conda。gcloud CLI 为 Cloud de Confiance提供了主要命令行界面。
启动 Cloud Shell:
前往 Cloud de Confiance 控制台。
在 Cloud de Confiance 控制台工具栏上,点击激活 Cloud Shell。
控制台下方的框架内会打开一个 Cloud Shell 会话。您可以使用此 shell 运行 gcloud 命令。
配置身份验证
Conda 渠道是指存储了一个或多个 Conda 软件包的位置的地址。在 Conda 环境中安装软件包之前,您必须将相应软件包的渠道添加到 Conda 配置文件中。
如需允许 Conda CLI 直接调用 Artifact Registry,您必须在 Cloud de Confiance by S3NS 中对 Conda 渠道进行身份验证,方法如下:
在 gcloud CLI 中,运行以下命令,将
oauth令牌的身份存储在 TOKEN 变量中:export TOKEN="oauth2accesstoken:$(gcloud auth print-access-token)"将您的 Conda 代码库添加为 Conda 配置文件中的渠道:
Conda
conda config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMiniforge
conda config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMamba
mamba config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMicromamba
micromamba config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORY其中:
- TOKEN 存储通过运行
oauth2accesstoken:$(gcloud auth print-access-token)生成的oauth令牌的值。 - LOCATION 是代码库的单区域或多区域位置。
- PROJECT 是包含相应代码库的项目的 ID。
- REPOSITORY 是代码库的 ID。
- TOKEN 存储通过运行
刷新已过期的 oauth 令牌
oauth 令牌会在 1 小时后过期。如需使用新令牌重新验证频道,请执行以下操作:
从配置文件中移除您的频道:
Conda
conda config --remove channels CHANNEL_NAMEMiniforge
conda config --remove channels CHANNEL_NAMEMamba
mamba config --remove channels CHANNEL_NAMEMicromamba
micromamba config --remove channels CHANNEL_NAME按照上一步中所述的步骤创建新的
oauth令牌。使用新令牌值将您的 Conda 代码库重新添加到 Conda 配置文件中。
创建代码库
为您的软件包创建代码库。
运行以下命令,在位置
us-west1的当前项目quickstart-conda-repo中创建一个新的 Conda 代码库。gcloud artifacts repositories create quickstart-conda-repo \ --repository-format=conda \ --location=us-west1 \ --description="Conda repository"运行以下命令确认已创建代码库:
gcloud artifacts repositories list为了简化
gcloud命令,请将默认代码库设置为quickstart-conda-repo,并将默认位置设置为us-west1。设置以上值之后,您无需在需要代码库或位置的gcloud命令中指定这些值。如需设置代码库,请运行以下命令:
gcloud config set artifacts/repository quickstart-conda-repo如需设置位置,请运行以下命令:
gcloud config set artifacts/location us-west1如需详细了解这些命令,请参阅 gcloud config set 文档。
将软件包上传到代码库
如需将软件包上传到代码库,请运行以下命令:
gcloud artifacts files upload \
--source=PACKAGE_NAME \
--repository=REPO_NAME\
--project=PROJECT \
--location=LOCATION
其中:
- REPO_NAME 是代码库的 ID。
- PROJECT 是包含相应代码库的项目的 ID。
- LOCATION 是代码库的单区域或多区域位置。
如需一次上传多个软件包,请执行以下操作:
gcloud artifacts files upload \
--source-directory="DIRECTORY" \
--repository="REPO_NAME"\
--project="PROJECT" \
--location="LOCATION"
其中:
- DIRECTORY 是包含您的 Conda 软件包的本地文件夹的地址。
查看代码库中的软件包
如需验证您的软件包是否已添加,请列出 quickstart-conda-repo 代码库中的软件包。
运行以下命令:
gcloud artifacts packages list --repository=quickstart-conda-repo
如需查看软件包的版本,请运行以下命令:
gcloud artifacts versions list --package=PACKAGE_NAME
如需查看软件包版本的相关文件,请运行以下命令:
gcloud artifacts files list --package=PACKAGE_NAME --version=VERSION
安装软件包
如需安装您刚刚添加到 Artifact Registry 制品库中的软件包,请运行以下命令:
Conda
conda install -n ENVIRONMENT_NAME PACKAGE_NAME
Miniforge
conda install -n ENVIRONMENT_NAME PACKAGE_NAME
Mamba
mamba install -n ENVIRONMENT_NAME PACKAGE_NAME
Micromamba
micromamba install -n ENVIRONMENT_NAME PACKAGE_NAME
其中:
- ENVIRONMENT_NAME 是您的 Conda 环境的名称。
- PACKAGE_NAME 是要在代码库中安装的软件包的名称。
问题排查
如需了解详情,请参阅 Conda 软件包问题排查。
清理
为避免因本页中使用的资源导致您的 Cloud de Confiance 账号产生费用,请按照以下步骤操作。
在移除代码库之前,请确保已在其他位置保存了您要保留的任何软件包。
如需删除
quickstart-conda-repo代码库,请运行以下命令:gcloud artifacts repositories delete quickstart-conda-repo如果要移除您为活跃
gcloud配置配置的默认代码库和位置设置,请运行以下命令:gcloud config unset artifacts/repository gcloud config unset artifacts/location
后续步骤
- 详细了解如何配置身份验证。
- 了解如何管理代码库。
- 了解如何管理软件包。
- 阅读我们关于 DevOps 的资源,并了解我们的研究项目。