在 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上託管資源的殼層環境。
Cloud Shell 已預先安裝 Google Cloud CLI 和 Conda。gcloud CLI 提供 Cloud de Confiance的主要指令列介面。
啟動 Cloud Shell:
前往 Cloud de Confiance 控制台。
在 Cloud de Confiance 控制台工具列中,點選「啟用 Cloud Shell」。
此時 Cloud Shell 工作階段會在主控台底部的頁框中開啟,您可以使用這個殼層來執行 gcloud 指令。
設定驗證機制
Conda channel 是儲存一或多個 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 會儲存執行
oauth產生的oauth2accesstoken:$(gcloud auth print-access-token)權杖值。 - 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
後續步驟
- 進一步瞭解如何設定驗證方法。
- 瞭解如何管理存放區。
- 瞭解如何管理套件。
- 參閱開發運作相關資源,並探索我們的研究計畫。