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

  1. 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.
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Artifact Registry API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the API

  5. Make sure that you have the following role or roles on the project: Artifact Registry Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. 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.

    4. 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

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  6. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. Verify that billing is enabled for your Google Cloud project.

  8. Enable the Artifact Registry API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the API

  9. Make sure that you have the following role or roles on the project: Artifact Registry Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. 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.

    4. 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

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  10. 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:

  1. Buka konsol Google Cloud .

    Google Cloud console

  2. 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:

  1. Di gcloud CLI, jalankan perintah berikut untuk menyimpan identitas token oauth dalam variabel TOKEN:

    export TOKEN="oauth2accesstoken:$(gcloud auth print-access-token)"
    
  2. Tambahkan repositori Conda Anda sebagai saluran di file konfigurasi Conda Anda:

    Conda

    conda config --add channels \
    https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORY
    

    Miniforge

    conda config --add channels \
    https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORY
    

    Mamba

    mamba config --add channels \
    https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORY
    

    Micromamba

    micromamba config --add channels \
    https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORY
    

    Dengan:

    • TOKEN menyimpan nilai token oauth yang dihasilkan dengan menjalankan oauth2accesstoken:$(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.

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:

  1. Hapus channel Anda dari file konfigurasi:

    Conda

    conda config --remove channels CHANNEL_NAME
    

    Miniforge

    conda config --remove channels CHANNEL_NAME
    

    Mamba

    mamba config --remove channels CHANNEL_NAME
    

    Micromamba

    micromamba config --remove channels CHANNEL_NAME
    
  2. Ikuti langkah sebelumnya yang menjelaskan cara membuat token oauth baru.

  3. Tambahkan kembali repositori Conda ke file konfigurasi Conda Anda, menggunakan nilai token baru Anda.

Membuat repositori

Buat repositori untuk paket Anda.

  1. Jalankan perintah berikut untuk membuat repositori Conda baru dalam project saat ini bernama quickstart-conda-repo di lokasi us-west1.

    gcloud artifacts repositories create quickstart-conda-repo \
        --repository-format=conda \
        --location=us-west1 \
        --description="Conda repository"
    
  2. Jalankan perintah berikut untuk memverifikasi bahwa repositori Anda telah dibuat:

    gcloud artifacts repositories list
    
  3. Untuk menyederhanakan perintah gcloud, tetapkan repositori default ke quickstart-conda-repo dan lokasi default ke us-west1. Setelah nilai ditetapkan, Anda tidak perlu menentukannya dalam perintah gcloud yang memerlukan repositori atau lokasi.

    Untuk menyetel repositori, jalankan perintah berikut:

    gcloud config set artifacts/repository quickstart-conda-repo
    

    Untuk menyetel lokasi, jalankan perintah berikut:

    gcloud config set artifacts/location us-west1
    

    Untuk 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.

  1. Untuk menghapus repositori quickstart-conda-repo, jalankan perintah berikut:

    gcloud artifacts repositories delete quickstart-conda-repo
    
  2. Jika Anda ingin menghapus setelan repositori dan lokasi default yang Anda konfigurasi untuk konfigurasi gcloud aktif, jalankan perintah berikut:

    gcloud config unset artifacts/repository
    gcloud config unset artifacts/location
    

Langkah berikutnya