אחסון חבילות Conda ב-Artifact Registry

במדריך למתחילים הזה מוסבר איך להגדיר מאגר פרטי של Conda ב-Artifact Registry ואז להעלות חבילה למאגר הזה.

לפני שמתחילים

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance 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

  2. Verify that billing is enabled for your Cloud de Confiance project.

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

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

    Check for the roles

    1. In the Cloud de Confiance 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 Cloud de Confiance 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 identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies, or contact your administrator.

    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.
  5. כדי להשתמש ב-CLI של Conda בסביבת Cloud de Confiance , מתקינים אחד ממנהלי החבילות הבאים של Conda:

הפעלת Cloud Shell

במדריך למתחילים הזה תשתמשו ב-Cloud Shell, שהיא סביבת מעטפת לניהול משאבים שמתארחים ב-Cloud de Confiance by S3NS.

ב-Cloud Shell מותקנים מראש Google Cloud CLI ו-Conda. ה-CLI של gcloud מספק את ממשק שורת הפקודה הראשי ל- Cloud de Confiance.

מפעילים את Cloud Shell:

  1. עוברים אל Cloud de Confiance המסוף.

    ‫Cloud de Confiance console

  2. בסרגל הכלים של מסוף Cloud de Confiance , לוחצים על Activate Cloud Shell (הפעלת Cloud Shell).

בחלק התחתון של המסוף ייפתח סשן של Cloud Shell בתוך מסגרת. משתמשים בשורת הפקודות הזו כדי להריץ פקודות gcloud.

הגדרת אימות

ערוץ של Conda הוא הכתובת של מיקום שבו מאוחסנות חבילות Conda. כדי להתקין חבילות בסביבת Conda, צריך להוסיף את הערוץ של החבילה לקובץ ההגדרות של Conda.

כדי לאפשר ל-CLI של Conda לקרוא ישירות את Artifact Registry, צריך לאמת את ערוץ Conda ב- Cloud de Confiance by S3NS באמצעות הפעולות הבאות:

  1. ב-CLI של gcloud, מריצים את הפקודה הבאה כדי לאחסן את הזהות של אסימון oauth במשתנה TOKEN:

    export TOKEN="oauth2accesstoken:$(gcloud auth print-access-token)"
    
  2. מוסיפים את מאגר Conda כערוץ בקובץ התצורה של Conda:

    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
    

    כאשר:

    • הטוקן TOKEN מאחסן את הערך של הטוקן oauth שנוצר בהרצת הפקודה oauth2accesstoken:$(gcloud auth print-access-token).
    • ‫LOCATION הוא המיקום האזורי או המיקום במספר אזורים של המאגר.
    • ‫PROJECT הוא מזהה הפרויקט שמכיל את המאגר.
    • ‫REPOSITORY הוא המזהה של המאגר.

רענון של טוקן oauth שפג התוקף שלו

התוקף של אסימון oauth פג אחרי שעה אחת. כדי לאמת מחדש את הערוץ באמצעות טוקן חדש, מבצעים את הפעולות הבאות:

  1. מסירים את הערוץ מקובץ ההגדרות:

    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. פועלים לפי השלב הקודם שבו מתואר איך ליצור אסימון oauth חדש.

  3. מוסיפים את מאגר Conda בחזרה לקובץ ההגדרות של Conda באמצעות ערך הטוקן החדש.

יצירת מאגר

יוצרים את המאגר לחבילה.

  1. מריצים את הפקודה הבאה כדי ליצור מאגר Conda חדש בפרויקט הנוכחי בשם quickstart-conda-repo במיקום us-west1.

    gcloud artifacts repositories create quickstart-conda-repo \
        --repository-format=conda \
        --location=us-west1 \
        --description="Conda repository"
    
  2. מריצים את הפקודה הבאה כדי לוודא שהמאגר נוצר:

    gcloud artifacts repositories list
    
  3. כדי לפשט את הפקודות של 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.

הסרת המשאבים

כדי לא לצבור חיובים לחשבון Cloud de Confiance על המשאבים שבהם השתמשתם בדף הזה, פועלים לפי השלבים הבאים:

לפני שמסירים את המאגר, צריך לוודא שכל החבילות שרוצים לשמור זמינות במיקום אחר.

  1. כדי למחוק את מאגר quickstart-conda-repo, מריצים את הפקודה הבאה:

    gcloud artifacts repositories delete quickstart-conda-repo
    
  2. אם רוצים להסיר את הגדרות ברירת המחדל של המאגר והמיקום שהגדרתם עבור התצורה הפעילה של gcloud, מריצים את הפקודות הבאות:

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

המאמרים הבאים