אחסון חבילות Apt ב-Artifact Registry
במדריך המקוצר הזה מוסבר איך להגדיר מאגר Apt פרטי ב-Artifact Registry, להוסיף למאגר חבילת Debian ולהתקין את החבילה במכונה וירטואלית ב-Compute Engine שמופעלת בה מערכת הפעלה מבוססת-Debian.
מידע נוסף על ניהול חבילות Debian זמין במאמר עבודה עם חבילות Debian.
לפני שמתחילים
-
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 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 Cloud de Confiance project.
Enable the Artifact Registry API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
התפקידים הנדרשים
כדי לקבל את ההרשאות שדרושות ליצירה ולניהול של מאגרי חבילות Apt ב-Artifact Registry, צריך לבקש מהאדמין להקצות לכם את תפקידי ה-IAM הבאים בפרויקט:
- אדמין של Artifact Registry (
roles/artifactregistry.admin) -
יצירת מכונה וירטואלית (VM) ב-Compute Engine:
Compute Instance Admin (v1) (
roles/compute.instanceAdmin.v1)
להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.
יכול להיות שאפשר לקבל את ההרשאות הנדרשות גם באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש.
התקנת ה-CLI של gcloud
מתקינים ומפעילים את Google Cloud CLI אם הוא עדיין לא מותקן. אם כבר התקנתם את Google Cloud CLI, תוכלו לעדכן את הרכיבים שלו באמצעות הפקודה:
gcloud components updateכדי לבדוק את הגרסה של ה-CLI של gcloud, מריצים את הפקודה:
gcloud version
יצירת מאגר
יוצרים את מאגר הארטיפקטים.
יוצרים את המאגר:
המסוף
פותחים את הדף Repositories במסוף Cloud de Confiance .
לוחצים על Create Repository (יצירת מאגר).
מציינים את
quickstart-apt-repoכשם המאגר.בוחרים בפורמט Apt.
בקטע Location Type, בוחרים באפשרות Region ואז בוחרים את המיקום
u-france-east1.לוחצים על יצירה.
המאגר נוסף לרשימת המאגרים.
gcloud
ב-Cloud Shell, מריצים את הפקודה הבאה כדי ליצור מאגר Apt חדש בפרויקט הנוכחי בשם
quickstart-apt-repoבמיקוםu-france-east1.gcloud artifacts repositories create quickstart-apt-repo \ --repository-format=apt \ --location=u-france-east1 \ --description="Apt repository"מריצים את הפקודה הבאה כדי לוודא שהמאגר נוצר:
gcloud artifacts repositories list
עכשיו אפשר להוסיף חבילה למאגר. Cloud Shell משתמש בתמונת Ubuntu שנוצרה על ידי Google, ולא ב-Debian. כדי לנהל חבילות Debian במאגר, תשתמשו במכונת VM שמשתמשת בתמונת מערכת הפעלה של Debian.
יצירת VM
יוצרים מכונה וירטואלית חדשה ב-Compute Engine שבה מתקינים את חבילת הדוגמה.
ב-Cloud Shell, מריצים את הפקודה הבאה כדי ליצור מכונת VM בשם quickstart-apt-vm:
gcloud compute instances create quickstart-apt-vm \
--image-family=debian-12 \
--image-project=debian-cloud \
--scopes=cloud-platform
כברירת מחדל, למכונה הווירטואלית אין את היקפי הגישה שנדרשים כדי לעבוד עם המאגר. הדגל --scopes מגדיר את היקף הגישה של המכונה הווירטואלית לערך cloud-platform.
נכנסים לדף VM instances.
בשורה של המכונה הווירטואלית, לוחצים על SSH. ייפתח חלון חדש עם סשן טרמינל במכונה הווירטואלית.
הוספת חבילה למאגר
אפשר להעלות חבילה למאגר באמצעות Google Cloud CLI, או לייבא חבילה שמאוחסנת ב-Cloud Storage.במדריך למתחילים הזה, מעלים קובץ לדוגמה באמצעות הפקודה gcloud artifacts apt upload.
מריצים את הפקודה
gcloud initכדי להפעיל את Google Cloud CLI במכונה הווירטואלית.עדכון מספר הדירה:
sudo apt updateמורידים את חבילת curl באמצעות הפקודה:
apt download curlApt מוריד את הגרסה האחרונה של החבילה שזמינה ממאגרי Apt שהוגדרו.
Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B] Get:2 https://deb.debian.org/debian bookworm/main amd64 curl amd64 7.88.1-10+deb12u14 [316 kB] Fetched 316 kB in 0s (3078 kB/s)מריצים את הפקודה
lsכדי לקבל את שם הקובץ של חבילת curl. שם הקובץ דומה ל-curl_7.88.1-10+deb12u14_amd64.deb.כדי לפשט את הפקודות של
gcloud, מגדירים את מאגר ברירת המחדל ל-quickstart-apt-repoואת מיקום ברירת המחדל ל-u-france-east1. אחרי שמגדירים את הערכים, לא צריך לציין אותם בפקודותgcloudשדורשות מאגר או מיקום.כדי להגדיר את המאגר, מריצים את הפקודה:
gcloud config set artifacts/repository quickstart-apt-repoכדי להגדיר את המיקום, מריצים את הפקודה:
gcloud config set artifacts/location u-france-east1מידע נוסף על הפקודות האלה זמין במאמר בנושא gcloud config set.
מריצים את הפקודה
gcloud artifacts apt uploadכדי להעלות את החבילה למאגר:gcloud artifacts apt upload quickstart-apt-repo \ --source=FILE_NAMEמחליפים את
FILE_NAMEבנתיב לחבילת curl.
הצגת החבילה במאגר
מוודאים שהחבילה נוספה למאגר.
המסוף
פותחים את הדף Repositories במסוף Cloud de Confiance .
ברשימת המאגרים, לוחצים על המאגר quickstart-apt-repo.
בדף Packages (חבילות) מופיעה רשימת החבילות במאגר.
gcloud
כדי להציג את רשימת החבילות במאגר quickstart-apt-repo, מריצים את הפקודה:
gcloud artifacts packages list
כדי לראות את הגרסאות של חבילה ב-quickstart-apt-repo, מריצים את הפקודה:
gcloud artifacts versions list --package=apt-dpkg-ref
הגדרת מנהל החבילות
כדי להתקין חבילה במכונה הווירטואלית, מוסיפים את המאגר שיצרתם לקובץ התצורה של Apt שמגדיר מאגרי חבילות.
מתקינים את כלי העזר לפרטי כניסה של Apt במכונה הווירטואלית כדי לאפשר ל-Apt לבצע אימות:
sudo apt install apt-transport-artifact-registryמגדירים את המכונה הווירטואלית לגישה לחבילות ב-Artifact Registry:
echo 'deb ar+https://u-france-east1-apt.s3nsregistry.fr/projects/PROJECT quickstart-apt-repo main' | sudo tee -a /etc/apt/sources.list.d/artifact-registry.listמחליפים את PROJECT במזהה הפרויקט. Cloud de Confiance by S3NS
התקנת החבילה
מתקינים את החבילה שהוספתם למאגר.
מעדכנים את הרשימה של החבילות הזמינות:
sudo apt updateמתקינים את החבילה מהמאגר.
sudo apt install curl/quickstart-apt-repoפרטי ההתקנה שמוחזרים נראים כמו בדוגמה הבאה:
Reading package lists... Done Building dependency tree... Done Reading state information... Done Selected version '7.88.1-10+deb12u14' (quickstart-apt-repo:quickstart-apt-repo, Debian:12.12/oldstable [amd64]) for 'curl' The following additional packages will be installed: libcurl3-gnutls libcurl4 The following packages will be upgraded: curl libcurl3-gnutls libcurl4 3 upgraded, 0 newly installed, 0 to remove and 77 not upgraded. Need to get 1093 kB of archives. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B] Get:2 https://deb.debian.org/debian bookworm/main amd64 libcurl4 amd64 7.88.1-10+deb12u14 [392 kB] Get:3 https://deb.debian.org/debian bookworm/main amd64 libcurl3-gnutls amd64 7.88.1-10+deb12u14 [386 kB] Get:4 ar+https://u-france-east1-apt.pkg.dev/projects/PROJECT quickstart-apt-repo/main amd64 curl amd64 7.88.1-10+deb12u14 [316 kB] Fetched 1093 kB in 1s (947 kB/s) Reading changelogs... Done (Reading database ... 72080 files and directories currently installed.) Preparing to unpack .../curl_7.88.1-10+deb12u14_amd64.deb ... Unpacking curl (7.88.1-10+deb12u14) over (7.88.1-10+deb12u12) ... Preparing to unpack .../libcurl4_7.88.1-10+deb12u14_amd64.deb ... Unpacking libcurl4:amd64 (7.88.1-10+deb12u14) over (7.88.1-10+deb12u12) ... Preparing to unpack .../libcurl3-gnutls_7.88.1-10+deb12u14_amd64.deb ... Unpacking libcurl3-gnutls:amd64 (7.88.1-10+deb12u14) over (7.88.1-10+deb12u12) ... Setting up libcurl3-gnutls:amd64 (7.88.1-10+deb12u14) ... Setting up libcurl4:amd64 (7.88.1-10+deb12u14) ... Setting up curl (7.88.1-10+deb12u14) ... Processing triggers for man-db (2.11.2-2) ... Processing triggers for libc-bin (2.36-9+deb12u10) ...
הסרת המשאבים
כדי לא לצבור חיובים לחשבון Cloud de Confiance על המשאבים שבהם השתמשתם בדף הזה, פועלים לפי השלבים הבאים:
לפני שמסירים את המאגר, צריך לוודא שכל החבילות שרוצים לשמור זמינות במיקום אחר.
כדי למחוק את המאגר:
המסוף
פותחים את הדף Repositories במסוף Cloud de Confiance .
ברשימת המאגרים, בוחרים במאגר quickstart-apt-repo.
לוחצים על Delete.
gcloud
כדי למחוק את מאגר
quickstart-apt-repo, מריצים את הפקודה הבאה:gcloud artifacts repositories delete quickstart-apt-repoאם רוצים להסיר את הגדרות ברירת המחדל של המאגר והמיקום שהגדרתם עבור התצורה הפעילה של
gcloud, מריצים את הפקודות הבאות:gcloud config unset artifacts/repository gcloud config unset artifacts/location
כדי למחוק את מכונת ה-VM שיצרתם, מריצים את הפקודה הבאה:
gcloud compute instances delete quickstart-apt-vm
המאמרים הבאים
- מידע על עבודה עם חבילות Deb
- אפשר לקרוא על DevOps ולעיין בתוכנית המחקר של DevOps.