Conda-Pakete in Artifact Registry speichern

In dieser Kurzanleitung wird gezeigt, wie Sie ein privates Conda-Repository für Artifact Registry einrichten und ein Paket in dieses Repository hochladen.

Hinweis

  1. Melden Sie sich in Ihrem Google Cloud -Konto an. Wenn Sie mit Google Cloudnoch nicht vertraut sind, erstellen Sie ein Konto, um die Leistungsfähigkeit unserer Produkte in der Praxis sehen und bewerten zu können. Neukunden erhalten außerdem ein Guthaben von 300 $, um Arbeitslasten auszuführen, zu testen und bereitzustellen.
  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. Wenn Sie die Conda-Befehlszeile in Ihrer Google Cloud -Umgebung verwenden möchten, installieren Sie einen der folgenden Conda-Paketmanager:

Cloud Shell starten

In dieser Kurzanleitung verwenden Sie Cloud Shell, eine Shell-Umgebung für die Verwaltung von Ressourcen, die inGoogle Cloudgehostet werden.

Die Google Cloud CLI und Conda sind in Cloud Shell vorinstalliert. Die gcloud CLI bietet die primäre Befehlszeile für Google Cloud.

Cloud Shell aufrufen

  1. Zur Google Cloud Console.

    Google Cloud Console

  2. Klicken Sie in der Symbolleiste der Google Cloud Console auf Cloud Shell aktivieren.

In einem Frame im unteren Teil der Console wird eine Cloud Shell-Sitzung geöffnet. Mit dieser Shell führen Sie gcloud-Befehle aus.

Authentifizierung konfigurieren

Ein Conda-Channel ist die Adresse eines Ortes, an dem ein oder mehrere Conda-Pakete gespeichert sind. Bevor Sie Pakete in Ihrer Conda-Umgebung installieren können, müssen Sie den Channel für dieses Paket Ihrer Conda-Konfigurationsdatei hinzufügen.

Damit die Conda-Befehlszeile Artifact Registry direkt aufrufen kann, müssen Sie Ihren Conda-Channel in Google Cloud authentifizieren. Gehen Sie dazu so vor:

  1. Führen Sie in der gcloud CLI den folgenden Befehl aus, um die Identität eines oauth-Tokens in einer TOKEN-Variablen zu speichern:

    export TOKEN="oauth2accesstoken:$(gcloud auth print-access-token)"
    
  2. Fügen Sie Ihr Conda-Repository als Channel in Ihre Conda-Konfigurationsdatei ein:

    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
    

    Wobei:

    • In TOKEN wird der Wert des oauth-Tokens gespeichert, der durch Ausführen von oauth2accesstoken:$(gcloud auth print-access-token) generiert wird.
    • LOCATION ist der regionale oder multiregionale Standort für das Repository.
    • PROJECT ist die ID des Projekts, das das Repository enthält.
    • REPOSITORY ist die ID des Repositorys.

Abgelaufenes oauth-Token aktualisieren

Ein oauth-Token läuft nach einer Stunde ab. So authentifizierst du deinen Kanal mit einem neuen Token:

  1. Entferne deinen Kanal aus der Konfigurationsdatei:

    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. Folgen Sie dem vorherigen Schritt, in dem beschrieben wird, wie Sie ein neues oauth-Token erstellen.

  3. Fügen Sie Ihr Conda-Repository mit Ihrem neuen Tokenwert wieder in Ihre Conda-Konfigurationsdatei ein.

Repository erstellen

Erstellen Sie das Repository für Ihr Paket.

  1. Führen Sie den folgenden Befehl aus, um ein neues Conda-Repository im aktuellen Projekt mit dem Namen quickstart-conda-repo am Speicherort us-west1 zu erstellen.

    gcloud artifacts repositories create quickstart-conda-repo \
        --repository-format=conda \
        --location=us-west1 \
        --description="Conda repository"
    
  2. Führen Sie den folgenden Befehl aus, um zu prüfen, ob Ihr Repository erstellt wurde:

    gcloud artifacts repositories list
    
  3. Um die gcloud-Befehle zu vereinfachen, legen Sie für das Standard-Repository den Wert quickstart-conda-repo und für den Standard-Speicherort us-west1 fest. Nachdem Sie die Werte festgelegt haben, müssen Sie diese nicht mehr in gcloud-Befehlen angeben, für die ein Repository oder Speicherort erforderlich ist.

    Führen Sie den folgenden Befehl aus, um das Repository festzulegen:

    gcloud config set artifacts/repository quickstart-conda-repo
    

    Führen Sie den folgenden Befehl aus, um den Standort festzulegen:

    gcloud config set artifacts/location us-west1
    

    Weitere Informationen zu diesen Befehlen finden Sie in der Dokumentation zu gcloud config set.

Paket in das Repository hochladen

Führen Sie den folgenden Befehl aus, um ein Paket in Ihr Repository hochzuladen:

gcloud artifacts files upload \
    --source=PACKAGE_NAME \
    --repository=REPO_NAME\
    --project=PROJECT \
    --location=LOCATION

Wobei:

  • REPO_NAME ist die ID des Repositorys.
  • PROJECT ist die ID des Projekts, das das Repository enthält.
  • LOCATION ist der regionale oder multiregionale Standort für das Repository.

So laden Sie mehrere Pakete gleichzeitig hoch:

gcloud artifacts files upload \
    --source-directory="DIRECTORY" \
    --repository="REPO_NAME"\
    --project="PROJECT" \
    --location="LOCATION"

Wobei:

  • DIRECTORY ist die Adresse eines lokalen Ordners, der Ihre Conda-Pakete enthält.

Paket im Repository ansehen

So prüfen Sie, ob das Paket hinzugefügt wurde: Listen Sie die Pakete im quickstart-conda-repo-Repository auf.

Führen Sie dazu diesen Befehl aus:

gcloud artifacts packages list --repository=quickstart-conda-repo

Um die Versionen für ein Paket aufzurufen, führen Sie folgenden Befehl aus:

gcloud artifacts versions list --package=PACKAGE_NAME

Führen Sie den folgenden Befehl aus, um die Dateien für eine Paketversion aufzurufen:

gcloud artifacts files list --package=PACKAGE_NAME --version=VERSION

Paket installieren

Führen Sie den folgenden Befehl aus, um das Paket zu installieren, das Sie gerade Ihrem Artifact Registry-Repository hinzugefügt haben:

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

Wobei:

  • ENVIRONMENT_NAME ist der Name Ihrer Conda-Umgebung.
  • PACKAGE_NAME ist der Name des Pakets, das in Ihrem Repository installiert werden soll.

Fehlerbehebung

Weitere Informationen finden Sie unter Fehlerbehebung bei Conda-Paketen.

Bereinigen

Mit den folgenden Schritten vermeiden Sie, dass Ihrem Google Cloud -Konto die auf dieser Seite verwendeten Ressourcen in Rechnung gestellt werden:

Prüfen Sie vor dem Entfernen des Repositorys, ob alle Pakete, die Sie beibehalten möchten, an einem anderen Speicherort verfügbar sind.

  1. Um das Repository quickstart-conda-repo zu löschen, führen Sie folgenden Befehl aus:

    gcloud artifacts repositories delete quickstart-conda-repo
    
  2. Wenn Sie die Einstellungen für das Standard-Repository und den Standard-Speicherort entfernen möchten, die Sie für die aktive gcloud-Konfiguration festgelegt haben, führen Sie die folgenden Befehle aus:

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

Nächste Schritte