אחסון חבילות Conda ב-Artifact Registry
במדריך למתחילים הזה נסביר איך להגדיר מאגר Conda פרטי ב-Artifact Registry, ואז להעלות חבילה למאגר הזה.
לפני שמתחילים
- נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 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.
-
- כדי להשתמש ב-Conda CLI בסביבת Google Cloud , צריך להתקין את אחד ממנהלי החבילות הבאים של Conda:
הפעלת Cloud Shell
במדריך למתחילים הזה תשתמשו ב-Cloud Shell, שהיא סביבת מעטפת לניהול משאבים שמתארחים ב-Google Cloud.
ב-Cloud Shell מותקנים מראש Google Cloud CLI ו-Conda. ה-CLI של gcloud מספק את ממשק שורת הפקודה הראשי ל- Google Cloud.
מפעילים את Cloud Shell:
נכנסים למסוף Google Cloud .
בסרגל הכלים של מסוף Google Cloud , לוחצים על Activate Cloud Shell.
בחלק התחתון של המסוף ייפתח סשן של Cloud Shell בתוך מסגרת.
אתם משתמשים במעטפת הזו כדי להריץ פקודות gcloud.
הגדרת אימות
ערוץ Conda הוא הכתובת של מיקום שבו מאוחסנת חבילת Conda אחת או יותר. כדי להתקין חבילות בסביבת Conda, צריך להוסיף את הערוץ של החבילה לקובץ התצורה של Conda.
כדי לאפשר ל-Conda CLI לקרוא ישירות ל-Artifact Registry, צריך לאמת את ערוץ Conda ב- Google Cloud באופן הבא:
ב-CLI של gcloud, מריצים את הפקודה הבאה כדי לאחסן את הזהות של אסימון
oauthבמשתנה 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 מאחסן את הערך של הטוקן
oauthשנוצר על ידי הפעלתoauth2accesstoken:$(gcloud auth print-access-token). - LOCATION הוא המיקום של המאגר, באזור אחד או במספר אזורים.
- PROJECT הוא מזהה הפרויקט שמכיל את המאגר.
- REPOSITORY הוא המזהה של המאגר.
- TOKEN מאחסן את הערך של הטוקן
רענון של טוקן oauth שפג תוקפו
התוקף של אסימון oauth פג אחרי שעה. כדי לאמת מחדש את הערוץ באמצעות אסימון חדש:
מסירים את הערוץ מקובץ התצורה:
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, באמצעות ערך הטוקן החדש.
יצירת מאגר
יוצרים את המאגר של החבילה.
מריצים את הפקודה הבאה כדי ליצור מאגר Conda חדש בפרויקט הנוכחי בשם
quickstart-conda-repoבמיקוםus-west1.gcloud artifacts repositories create quickstart-conda-repo \ --repository-format=conda \ --location=us-west1 \ --description="Conda repository"מריצים את הפקודה הבאה כדי לוודא שהמאגר נוצר:
gcloud artifacts repositories listכדי לפשט את הפקודות של
gcloud, מגדירים את מאגר ברירת המחדל ל-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 הוא המזהה של המאגר.
- PROJECT הוא מזהה הפרויקט שמכיל את המאגר.
- 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 ולעיין בתוכנית המחקר שלנו.