אחסון חבילות 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.
-
- כדי להשתמש ב-CLI של Conda בסביבת 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).
בחלק התחתון של המסוף ייפתח סשן של Cloud Shell בתוך מסגרת.
משתמשים בשורת הפקודות הזו כדי להריץ פקודות gcloud.
הגדרת אימות
ערוץ של Conda הוא הכתובת של מיקום שבו מאוחסנות חבילות Conda. כדי להתקין חבילות בסביבת Conda, צריך להוסיף את הערוץ של החבילה לקובץ ההגדרות של Conda.
כדי לאפשר ל-CLI של Conda לקרוא ישירות את 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 ולעיין בתוכנית המחקר שלנו.