Menyimpan paket Conda di Artifact Registry
Panduan memulai ini menunjukkan cara menyiapkan repositori Conda Artifact Registry pribadi, lalu mengupload paket ke repositori tersebut.
Sebelum memulai
- Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
-
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.
-
- Untuk menggunakan Conda CLI dalam lingkungan Google Cloud Anda, instal salah satu pengelola paket Conda berikut:
Meluncurkan Cloud Shell
Dalam panduan memulai ini, Anda akan menggunakan Cloud Shell, yang merupakan lingkungan shell untuk mengelola resource yang dihosting diGoogle Cloud.
Cloud Shell telah diinstal lebih dulu dengan Google Cloud CLI dan Conda. gcloud CLI menyediakan antarmuka command line utama untuk Google Cloud.
Meluncurkan Cloud Shell:
Buka konsol Google Cloud .
Di toolbar konsol Google Cloud , klik Activate Cloud Shell.
Sesi Cloud Shell akan terbuka di dalam frame yang lebih rendah di konsol.
Anda menggunakan shell ini untuk menjalankan perintah gcloud.
Mengonfigurasi autentikasi
Channel Conda adalah alamat ke lokasi tempat satu atau beberapa paket Conda disimpan. Sebelum dapat menginstal paket di lingkungan Conda, Anda harus menambahkan saluran untuk paket tersebut ke file konfigurasi Conda.
Untuk mengizinkan Conda CLI memanggil Artifact Registry secara langsung, Anda harus mengautentikasi channel Conda di Google Cloud dengan melakukan hal berikut:
Di gcloud CLI, jalankan perintah berikut untuk menyimpan identitas token
oauthdalam variabel TOKEN:export TOKEN="oauth2accesstoken:$(gcloud auth print-access-token)"Tambahkan repositori Conda Anda sebagai saluran di file konfigurasi Conda Anda:
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/REPOSITORYDengan:
- TOKEN menyimpan nilai token
oauthyang dihasilkan dengan menjalankanoauth2accesstoken:$(gcloud auth print-access-token). - LOCATION adalah lokasi regional atau multi-regional untuk repositori.
- PROJECT adalah ID project yang berisi repositori.
- REPOSITORY adalah ID repositori.
- TOKEN menyimpan nilai token
Memperbarui token oauth yang masa berlakunya telah berakhir
Masa berlaku token oauth akan berakhir setelah satu jam. Untuk mengautentikasi ulang channel Anda dengan token baru, lakukan hal berikut:
Hapus channel Anda dari file konfigurasi:
Conda
conda config --remove channels CHANNEL_NAMEMiniforge
conda config --remove channels CHANNEL_NAMEMamba
mamba config --remove channels CHANNEL_NAMEMicromamba
micromamba config --remove channels CHANNEL_NAMEIkuti langkah sebelumnya yang menjelaskan cara membuat token
oauthbaru.Tambahkan kembali repositori Conda ke file konfigurasi Conda Anda, menggunakan nilai token baru Anda.
Membuat repositori
Buat repositori untuk paket Anda.
Jalankan perintah berikut untuk membuat repositori Conda baru dalam project saat ini bernama
quickstart-conda-repodi lokasius-west1.gcloud artifacts repositories create quickstart-conda-repo \ --repository-format=conda \ --location=us-west1 \ --description="Conda repository"Jalankan perintah berikut untuk memverifikasi bahwa repositori Anda telah dibuat:
gcloud artifacts repositories listUntuk menyederhanakan perintah
gcloud, tetapkan repositori default kequickstart-conda-repodan lokasi default keus-west1. Setelah nilai ditetapkan, Anda tidak perlu menentukannya dalam perintahgcloudyang memerlukan repositori atau lokasi.Untuk menyetel repositori, jalankan perintah berikut:
gcloud config set artifacts/repository quickstart-conda-repoUntuk menyetel lokasi, jalankan perintah berikut:
gcloud config set artifacts/location us-west1Untuk mengetahui informasi selengkapnya tentang perintah ini, lihat dokumentasi gcloud config set.
Mengupload paket ke repositori
Untuk mengupload paket ke repositori, jalankan perintah berikut:
gcloud artifacts files upload \
--source=PACKAGE_NAME \
--repository=REPO_NAME\
--project=PROJECT \
--location=LOCATION
Dengan:
- REPO_NAME adalah ID repositori.
- PROJECT adalah ID project yang berisi repositori.
- LOCATION adalah lokasi regional atau multi-regional untuk repositori.
Untuk mengupload beberapa paket sekaligus:
gcloud artifacts files upload \
--source-directory="DIRECTORY" \
--repository="REPO_NAME"\
--project="PROJECT" \
--location="LOCATION"
Dengan:
- DIRECTORY adalah alamat folder lokal yang berisi paket Conda Anda.
Melihat paket di repositori
Untuk memverifikasi bahwa paket Anda telah ditambahkan, cantumkan paket di repositori
quickstart-conda-repo.
Jalankan perintah berikut:
gcloud artifacts packages list --repository=quickstart-conda-repo
Untuk melihat versi paket, jalankan perintah berikut:
gcloud artifacts versions list --package=PACKAGE_NAME
Untuk melihat file untuk versi paket, jalankan perintah berikut:
gcloud artifacts files list --package=PACKAGE_NAME --version=VERSION
Menginstal paket
Untuk menginstal paket yang baru saja Anda tambahkan ke repositori Artifact Registry, jalankan perintah berikut:
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
Dengan:
- ENVIRONMENT_NAME adalah nama lingkungan Conda Anda.
- PACKAGE_NAME adalah nama paket yang akan diinstal di repositori Anda.
Pemecahan masalah
Lihat Pemecahan masalah untuk paket Conda untuk mengetahui informasi selengkapnya.
Pembersihan
Agar akun Google Cloud Anda tidak dikenai biaya untuk resource yang digunakan pada halaman ini, ikuti langkah-langkah berikut.
Sebelum menghapus repositori, pastikan semua paket yang ingin Anda simpan tersedia di lokasi lain.
Untuk menghapus repositori
quickstart-conda-repo, jalankan perintah berikut:gcloud artifacts repositories delete quickstart-conda-repoJika Anda ingin menghapus setelan repositori dan lokasi default yang Anda konfigurasi untuk konfigurasi
gcloudaktif, jalankan perintah berikut:gcloud config unset artifacts/repository gcloud config unset artifacts/location
Langkah berikutnya
- Pelajari lebih lanjut cara mengonfigurasi autentikasi.
- Pelajari cara mengelola repositori.
- Pelajari cara mengelola paket.
- Baca sumber daya kami tentang DevOps dan jelajahi program penelitian kami.