Conda-Pakete in Artifact Registry speichern
In dieser Kurzanleitung erfahren Sie, wie Sie ein privates Artifact Registry-Conda-Repository einrichten und dann ein Paket in dieses Repository hochladen.
Hinweis
- Melden Sie sich in Ihrem Google Cloud -Konto an. Wenn Sie mit Google Cloudnoch nicht vertraut sind, erstellen Sie einfach 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.
-
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.
-
- 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
Rufen Sie die Google Cloud Console auf.
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-Kanal ist die Adresse eines Speicherorts, an dem ein oder mehrere Conda-Pakete gespeichert sind. Bevor Sie Pakete in Ihrer Conda-Umgebung installieren können, müssen Sie den Kanal für dieses Paket Ihrer Conda-Konfigurationsdatei hinzufügen.
Damit die Conda-Befehlszeile Artifact Registry direkt aufrufen kann, müssen Sie Ihren Conda-Kanal in Google Cloud so authentifizieren:
Führen Sie in der gcloud CLI den folgenden Befehl aus, um die Identität eines
oauth-Tokens in einer TOKEN-Variable zu speichern:export TOKEN="oauth2accesstoken:$(gcloud auth print-access-token)"Fügen Sie Ihr Conda-Repository als Channel in Ihrer Conda-Konfigurationsdatei hinzu:
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/REPOSITORYWobei:
- TOKEN speichert den Wert des
oauth-Tokens, das durch Ausführen vonoauth2accesstoken:$(gcloud auth print-access-token)generiert wurde. - 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.
- TOKEN speichert den Wert des
Abgelaufenes oauth-Token aktualisieren
Ein oauth-Token läuft nach einer Stunde ab. So authentifizieren Sie Ihren Kanal mit einem neuen Token noch einmal:
Entfernen Sie Ihren Kanal aus der Konfigurationsdatei:
Conda
conda config --remove channels CHANNEL_NAMEMiniforge
conda config --remove channels CHANNEL_NAMEMamba
mamba config --remove channels CHANNEL_NAMEMicromamba
micromamba config --remove channels CHANNEL_NAMEFühren Sie den vorherigen Schritt aus, in dem das Erstellen eines neuen
oauth-Tokens beschrieben wurde.Fügen Sie das Conda-Repository mit dem neuen Tokenwert wieder der Conda-Konfigurationsdatei hinzu.
Repository erstellen
Erstellen Sie das Repository für Ihr Paket.
Führen Sie den folgenden Befehl aus, um ein neues Conda-Repository im aktuellen Projekt
quickstart-conda-repoam Standortus-west1zu erstellen.gcloud artifacts repositories create quickstart-conda-repo \ --repository-format=conda \ --location=us-west1 \ --description="Conda repository"Führen Sie den folgenden Befehl aus, um zu prüfen, ob Ihr Repository erstellt wurde:
gcloud artifacts repositories listUm die
gcloud-Befehle zu vereinfachen, legen Sie für das Standard-Repository den Wertquickstart-conda-repound für den Standard-Speicherortus-west1fest. Nachdem die Werte festgelegt wurden, müssen Sie sie nicht mehr ingcloud-Befehlen angeben, die ein Repository oder einen Standort erfordern.Führen Sie den folgenden Befehl aus, um das Repository festzulegen:
gcloud config set artifacts/repository quickstart-conda-repoFühren Sie den folgenden Befehl aus, um den Standort festzulegen:
gcloud config set artifacts/location us-west1Weitere 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
Listen Sie die Pakete im Repository quickstart-conda-repo auf, um zu prüfen, ob Ihr Paket hinzugefügt wurde.
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 für Conda-Pakete.
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.
Um das Repository
quickstart-conda-repozu löschen, führen Sie folgenden Befehl aus:gcloud artifacts repositories delete quickstart-conda-repoWenn 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
- Weitere Informationen zur Konfiguration der Authentifizierung
- Repositories verwalten
- Informationen zum Verwalten von Paketen.
- Lesen Sie unsere Ressourcen zu DevOps und gehen Sie unser Forschungsprogramm durch.