Conda パッケージを Artifact Registry に保存する
このクイックスタートでは、非公開の Artifact Registry Conda リポジトリを設定して、パッケージをそのリポジトリにアップロードする方法について説明します。
始める前に
- Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud 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 Google Cloud 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 Google Cloud 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 Google Cloud 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 email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud 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 Google Cloud 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 Google Cloud 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 Google Cloud 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 email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
- Google Cloud 環境内で Conda CLI を使用するには、次のいずれかの Conda パッケージ マネージャーをインストールします。
Cloud Shell を起動する
このクイックスタートでは、Google Cloudでホストされているリソースを管理するためのシェル環境である Cloud Shell を使用します。
Cloud Shell には、Google Cloud CLI と Conda がプリインストールされています。gcloud CLI は、 Google Cloudの主要なコマンドライン インターフェースを提供します。
Cloud Shell を起動します。
Google Cloud コンソールに移動します。
Google Cloud コンソールのツールバーで、[Cloud Shell をアクティブにする] をクリックします。
コンソールの下部にあるフレーム内で Cloud Shell セッションが開きます。このシェルで gcloud コマンドを実行します。
認証を構成する
Conda チャネルは、1 つ以上の Conda パッケージが保存されている場所のアドレスです。Conda 環境にパッケージをインストールする前に、そのパッケージのチャンネルを Conda 構成ファイルに追加する必要があります。
Conda CLI が Artifact Registry を直接呼び出せるようにするには、次の操作を行って Google Cloud で Conda チャネルを認証する必要があります。
gcloud CLI で次のコマンドを実行して、
oauthトークンの ID を 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 listgcloudコマンドを簡素化するには、デフォルトのリポジトリを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 パッケージのトラブルシューティングをご覧ください。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。
リポジトリを削除する前に、保持する必要があるパッケージが別の場所で使用可能であることを確認してください。
quickstart-conda-repoリポジトリを削除するには、次のコマンドを実行します。gcloud artifacts repositories delete quickstart-conda-repoアクティブな
gcloud構成のデフォルトのリポジトリとロケーション設定を削除するには、次のコマンドを実行します。gcloud config unset artifacts/repository gcloud config unset artifacts/location
次のステップ
- 認証の構成の詳細を確認する。
- リポジトリの管理について確認する。
- パッケージの管理について学習する。
- DevOps に関するリソースを読む。また、研究プログラムについて確認する。