אחסון פורמטים אחרים ב-Artifact Registry
כאן מוסבר איך להגדיר מאגר בפורמט כללי ב-Artifact Registry ולהעלות אליו קובץ YAML.
לפני שמתחילים
- נכנסים לחשבון 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.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry API.
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.-
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.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry API.
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.
התפקידים הנדרשים
כדי לקבל את ההרשאות שנדרשות ליצירה ולניהול של מאגרי חבילות ב-Artifact Registry, צריך לבקש מהאדמין להקצות לכם את תפקיד ה-IAM Artifact Registry Administrator (אדמין של Artifact Registry) (roles/artifactregistry.admin) בפרויקט.
כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.
יכול להיות שאפשר לקבל את ההרשאות הנדרשות גם באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש.
הפעלת Cloud Shell
במסוף Google Cloud , מפעילים את Cloud Shell.
בחלק התחתון של Google Cloud המסוף יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.
במדריך למתחילים הזה תשתמשו ב-Cloud Shell כדי להריץ פקודות gcloud.
יצירת מאגר כללי
כדי ליצור מאגר בפורמט גנרי בשם
quickstart-generic-repoבמיקוםus-central1עם התיאורGeneric repository, מריצים את הפקודה הבאה:gcloud artifacts repositories create quickstart-generic-repo \ --repository-format=generic \ --location=us-central1 \ --description="Generic repository"כדי לוודא שהמאגר נוצר, מריצים את הפקודה הבאה:
gcloud artifacts repositories listכדי לפשט את הפקודות של
gcloud, מריצים את הפקודות הבאות כדי להגדיר את מאגר ברירת המחדל ל-quickstart-generic-repoואת מיקום ברירת המחדל ל-us-central1.כדי להגדיר את מאגר ברירת המחדל ל-
quickstart-generic-repo, מריצים את הפקודה הבאה:gcloud config set artifacts/repository quickstart-generic-repoכדי להגדיר את מיקום ברירת המחדל ל-
us-central1, מריצים את הפקודה הבאה:gcloud config set artifacts/location us-central1
אחרי שמגדירים את הערכים, לא צריך לציין אותם בפקודות
gcloudשדורשות מאגר או מיקום.
העלאת פריט מידע שנוצר בתהליך פיתוח (Artifact) למאגר
בספריית הבית, יוצרים קובץ להעלאה למאגר:
echo "hello world" > hello.yamlכדי להעלות את הקובץ כארטיפקט למאגר, מריצים את הפקודה הבאה:
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
מחיקת המאגר
לפני שמסירים מאגר, צריך לוודא שכל החבילות שרוצים לשמור זמינות במיקום אחר.
כדי למחוק את מאגר
quickstart-generic-repo, מריצים את הפקודה הבאה:gcloud artifacts repositories delete quickstart-generic-repoאם רוצים להסיר את הגדרות ברירת המחדל של המאגר והמיקום שהגדרתם עבור התצורה הפעילה של
gcloud, מריצים את הפקודות הבאות:gcloud config unset artifacts/repository gcloud config unset artifacts/location