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

במדריך המקוצר הזה מוסבר איך להגדיר מאגר Apt פרטי ב-Artifact Registry, להוסיף למאגר חבילת Debian ולהתקין את החבילה במכונה וירטואלית ב-Compute Engine שמופעלת בה מערכת הפעלה מבוססת-Debian.

מידע נוסף על ניהול חבילות Debian זמין במאמר עבודה עם חבילות Debian.

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

  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

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

כדי לקבל את ההרשאות שדרושות ליצירה ולניהול של מאגרי חבילות Apt ב-Artifact Registry, צריך לבקש מהאדמין להקצות לכם את תפקידי ה-IAM הבאים בפרויקט:

להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

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

הפעלת Cloud Shell

Google Cloud CLI מותקן מראש ב-Cloud Shell. ה-CLI של gcloud הוא ממשק שורת הפקודה העיקרי ל- Google Cloud.

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

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

    Google Cloud console

  2. במסוף Google Cloud , לוחצים על Activate Cloud Shell הלחצן Activate Cloud Shell.

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

יצירת מאגר

יוצרים את מאגר הארטיפקטים.

  1. יוצרים את המאגר:

    המסוף

    1. פותחים את הדף Repositories במסוף Google Cloud .

      פתיחת הדף Repositories

    2. לוחצים על Create Repository (יצירת מאגר).

    3. מציינים את quickstart-apt-repo כשם המאגר.

    4. בוחרים בפורמט Apt.

    5. בקטע Location Type, בוחרים באפשרות Region ואז בוחרים את המיקום us-west1.

    6. לוחצים על יצירה.

    המאגר נוסף לרשימת המאגרים.

    gcloud

    1. ב-Cloud Shell, מריצים את הפקודה הבאה כדי ליצור מאגר Apt חדש בפרויקט הנוכחי בשם quickstart-apt-repo במיקום us-west1.

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

      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.

  1. נכנסים לדף VM instances.

    פתיחת הדף VM instances

  2. בשורה של המכונה הווירטואלית, לוחצים על SSH. ייפתח חלון חדש עם סשן טרמינל במכונה הווירטואלית.

הוספת חבילה למאגר

אפשר להעלות חבילה למאגר באמצעות Google Cloud CLI, או לייבא חבילה שמאוחסנת ב-Cloud Storage. אם אתם יוצרים חבילות באמצעות Cloud Build, התהליך יכול לאחסן את החבילות ב-Cloud Storage כדי שתוכלו לייבא אותן.

במדריך למתחילים הזה, מעלים קובץ לדוגמה באמצעות הפקודה gcloud artifacts apt upload.

  1. מריצים את הפקודה gcloud init כדי להפעיל את Google Cloud CLI במכונה הווירטואלית.

  2. עדכון מספר הדירה:

    sudo apt update
    
  3. מורידים את חבילת curl באמצעות הפקודה:

    apt download curl
    

    ‫Apt מוריד את הגרסה האחרונה של החבילה שזמינה ממאגרי 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.

  4. כדי לפשט את הפקודות של gcloud, מגדירים את מאגר ברירת המחדל ל-quickstart-apt-repo ואת מיקום ברירת המחדל ל-us-west1. אחרי שמגדירים את הערכים, לא צריך לציין אותם בפקודות gcloud שדורשות מאגר או מיקום.

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

    gcloud config set artifacts/repository quickstart-apt-repo
    

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

    gcloud config set artifacts/location us-west1
    

    מידע נוסף על הפקודות האלה זמין במאמר בנושא gcloud config set.

  5. מריצים את הפקודה gcloud artifacts apt upload כדי להעלות את החבילה למאגר:

    gcloud artifacts apt upload quickstart-apt-repo \
        --source=FILE_NAME
    

    מחליפים את FILE_NAME בנתיב לחבילת curl.

הצגת החבילה במאגר

מוודאים שהחבילה נוספה למאגר.

המסוף

  1. פותחים את הדף Repositories במסוף Google Cloud .

    פתיחת הדף Repositories

  2. ברשימת המאגרים, לוחצים על המאגר quickstart-apt-repo.

    בדף Packages (חבילות) מופיעה רשימת החבילות במאגר.

gcloud

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

 gcloud artifacts packages list

כדי לראות את הגרסאות של חבילה ב-quickstart-apt-repo, מריצים את הפקודה:

gcloud artifacts versions list --package=apt-dpkg-ref

הגדרת מנהל החבילות

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

  1. מתקינים את כלי העזר לפרטי כניסה של Apt במכונה הווירטואלית כדי לאפשר ל-Apt לבצע אימות:

    sudo apt install apt-transport-artifact-registry
    
  2. מגדירים את המכונה הווירטואלית לגישה לחבילות ב-Artifact Registry:

    echo 'deb ar+https://us-west1-apt.pkg.dev/projects/PROJECT quickstart-apt-repo main' | sudo tee -a  /etc/apt/sources.list.d/artifact-registry.list
    

    מחליפים את PROJECT במזהה הפרויקט. Google Cloud

התקנת החבילה

מתקינים את החבילה שהוספתם למאגר.

  1. מעדכנים את הרשימה של החבילות הזמינות:

    sudo apt update
    
  2. מתקינים את החבילה מהמאגר.

    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://us-west1-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) ...
    

הסרת המשאבים

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

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

כדי למחוק את המאגר:

המסוף

  1. פותחים את הדף Repositories במסוף Google Cloud .

    פתיחת הדף Repositories

  2. ברשימת המאגרים, בוחרים במאגר quickstart-apt-repo.

  3. לוחצים על Delete.

gcloud

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

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

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

כדי למחוק את מכונת ה-VM שיצרתם, מריצים את הפקודה הבאה:

gcloud compute instances delete quickstart-apt-vm

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