אחסון פורמטים אחרים ב-Artifact Registry

כאן מוסבר איך להגדיר מאגר בפורמט כללי ב-Artifact Registry ולהעלות אליו קובץ YAML.

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

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  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. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Artifact Registry API.

    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

  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. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Artifact Registry API.

    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

התפקידים הנדרשים

כדי לקבל את ההרשאות שנדרשות ליצירה ולניהול של מאגרי חבילות ב-Artifact Registry, צריך לבקש מהאדמין להקצות לכם את תפקיד ה-IAM‏ Artifact Registry Administrator (אדמין של Artifact Registry) ‏(roles/artifactregistry.admin) בפרויקט. כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

יכול להיות שאפשר לקבל את ההרשאות הנדרשות גם באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש.

הפעלת Cloud Shell

במסוף Google Cloud , מפעילים את Cloud Shell.

הפעלת Cloud Shell

בחלק התחתון של Google Cloud המסוף יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.

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

יצירת מאגר כללי

  1. כדי ליצור מאגר בפורמט גנרי בשם quickstart-generic-repo במיקום us-central1 עם התיאור Generic repository, מריצים את הפקודה הבאה:

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

    gcloud artifacts repositories list
    
  3. כדי לפשט את הפקודות של gcloud, מריצים את הפקודות הבאות כדי להגדיר את מאגר ברירת המחדל ל-quickstart-generic-repo ואת מיקום ברירת המחדל ל-us-central1.

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

      gcloud config set artifacts/repository quickstart-generic-repo
      
    2. כדי להגדיר את מיקום ברירת המחדל ל-us-central1, מריצים את הפקודה הבאה:

      gcloud config set artifacts/location us-central1
      

    אחרי שמגדירים את הערכים, לא צריך לציין אותם בפקודות gcloud שדורשות מאגר או מיקום.

העלאת פריט מידע שנוצר בתהליך פיתוח (Artifact) למאגר

  1. בספריית הבית, יוצרים קובץ להעלאה למאגר:

    echo "hello world" > hello.yaml
    
  2. כדי להעלות את הקובץ כארטיפקט למאגר, מריצים את הפקודה הבאה:

    gcloud artifacts generic upload \
        --source=hello.yaml \
        --package=my-package \
        --version=1.0.0
    

    כאשר:

    • hello.yaml הוא הנתיב של הקובץ להעלאה.
    • my-package היא החבילה שמעלים.
    • 1.0.0 היא הגרסה של הארטיפקט. אי אפשר להחליף גרסה קיימת במאגר.

הצגת פריטי מידע במאגר

כדי לוודא שהארטיפקט נוסף למאגר, אפשר להריץ את הפקודה הבאה כדי להציג רשימה של כל הארטיפקטים:

gcloud artifacts files list

התשובה כוללת את פרטי הקובץ בפורמט PACKAGE:VERSION:FILE_NAME.

בדוגמה הבאה, hello.yaml הוא FILE_NAME:

FILE: my-package:1.0.0:hello.yaml
CREATE_TIME: 2023-03-09T20:55:07
UPDATE_TIME: 2023-03-09T20:55:07
SIZE (MB): 0.000
OWNER: projects/my-project/locations/us-central1/repositories/quickstart-generic-repo/packages/my-package/versions/1.0.0

הורדה של פריט מידע שנוצר בתהליך פיתוח (Artifact) כללי

כדי להוריד ארטיפקט כללי מהמאגר, מריצים את הפקודה הבאה:

gcloud artifacts generic download \
    --name=hello.yaml \
    --package=my-package \
    --version=1.0.0 \
    --destination=DESTINATION

כאשר:

  • hello.yaml הוא שם הקובץ שרוצים להוריד.
  • my-package היא החבילה שצריך להוריד.
  • 1.0.0 היא הגרסה של הארטיפקט.

מחליפים את DESTINATION בספרייה במערכת הקבצים המקומית שבה רוצים לשמור את ההורדה. תיקיית היעד צריכה להיות קיימת, אחרת הפקודה תיכשל.

הסרת המשאבים

כדי להימנע מחיובים בחשבון Google Cloud על המשאבים שבהם השתמשתם במדריך הזה, אתם יכולים למחוק את הפרויקט שמכיל את המשאבים או להשאיר את הפרויקט ולמחוק את המאגר.

מחיקת הפרויקט

    כדי למחוק Google Cloud פרויקט:

    gcloud projects delete PROJECT_ID

מחיקת המאגר

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

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

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

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

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