Menyimpan paket Apt di Artifact Registry

Panduan memulai ini menunjukkan cara menyiapkan repositori Apt Artifact Registry pribadi, menambahkan paket Debian ke repositori, dan menginstal paket di VM Compute Engine yang menjalankan sistem operasi berbasis Debian.

Untuk mempelajari lebih lanjut cara mengelola paket Debian, lihat Bekerja dengan paket Debian.

Sebelum memulai

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  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. Verify that billing is enabled for your Google Cloud project.

  4. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

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

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

  7. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. Meluncurkan Cloud Shell

    Cloud Shell telah diinstal lebih dulu dengan Google Cloud CLI. gcloud CLI menyediakan antarmuka command line utama untuk Google Cloud.

    Meluncurkan Cloud Shell:

    1. Buka Google Cloud console.

      Google Cloud console

    2. Di konsol Google Cloud , klik Activate Cloud Shell Tombol Aktifkan Cloud Shell.

    Sesi Cloud Shell akan terbuka di dalam frame yang lebih rendah di konsol. Anda akan menggunakan shell ini untuk menjalankan perintah gcloud guna membuat VM dan repositori.

    Membuat repositori

    Buat repositori untuk artefak Anda.

    1. Buat repositori:

      Konsol

      1. Buka halaman Repositori di Google Cloud konsol.

        Buka halaman Repositori

      2. Klik Create Repository.

      3. Tentukan quickstart-apt-repo sebagai nama repositori.

      4. Pilih Apt sebagai format.

      5. Di bawah Jenis Lokasi, pilih Region dan kemudian pilih lokasi us-west1.

      6. Klik Buat.

      Repositori ditambahkan ke daftar repositori.

      gcloud

      1. Di Cloud Shell, jalankan perintah berikut untuk membuat repositori Apt baru di project saat ini bernama quickstart-apt-repo di lokasi us-west1.

        gcloud artifacts repositories create quickstart-apt-repo \
            --repository-format=apt \
            --location=us-west1 \
            --description="Apt repository"
        
      2. Jalankan perintah berikut untuk memverifikasi bahwa repositori Anda telah dibuat:

        gcloud artifacts repositories list
        

    Sekarang Anda dapat menambahkan paket ke repositori. Cloud Shell menggunakan image Ubuntu buatan Google, bukan Debian. Untuk mengelola paket Debian di repositori, Anda akan menggunakan VM yang menggunakan image OS Debian.

    Membuat VM

    Buat VM Compute Engine baru tempat Anda akan menginstal paket contoh.

    Di Cloud Shell, jalankan perintah berikut untuk membuat instance VM bernama quickstart-apt-vm:

    gcloud compute instances create quickstart-apt-vm \
        --image-family=debian-12 \
        --image-project=debian-cloud \
        --scopes=cloud-platform
    

    Secara default, VM tidak memiliki cakupan akses yang diperlukan untuk bekerja dengan repositori. Flag --scopes menetapkan cakupan akses untuk VM ke cloud-platform.

    1. Buka halaman VM instances.

      Buka halaman instance VM

    2. Di baris dengan VM Anda, klik SSH. Jendela baru akan terbuka dengan sesi terminal di VM.

    Menambahkan paket ke repositori

    Anda dapat mengupload paket ke repositori menggunakan Google Cloud CLI, atau Anda dapat mengimpor paket yang disimpan di Cloud Storage. Jika Anda membuat paket menggunakan Cloud Build, build dapat menyimpan paket di Cloud Storage agar Anda dapat mengimpornya.

    Untuk panduan memulai ini, Anda akan mengupload contoh file menggunakan perintah gcloud artifacts apt upload.

    1. Jalankan gcloud init untuk menginisialisasi Google Cloud CLI di VM Anda.

    2. Update Apt:

      sudo apt update
      
    3. Download paket curl dengan perintah:

      apt download curl
      

      Apt mendownload versi terbaru paket yang tersedia dari repositori Apt yang Anda konfigurasi.

      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)
      

      Jalankan ls untuk mendapatkan nama file paket curl. Nama file mirip dengan curl_7.88.1-10+deb12u14_amd64.deb.

    4. Untuk menyederhanakan perintah gcloud, tetapkan repositori default ke quickstart-apt-repo dan lokasi default ke us-west1. Setelah nilai ditetapkan, Anda tidak perlu menentukannya dalam perintah gcloud yang memerlukan repositori atau lokasi.

      Untuk menyetel repositori, jalankan perintah:

      gcloud config set artifacts/repository quickstart-apt-repo
      

      Untuk menyetel lokasi, jalankan perintah:

      gcloud config set artifacts/location us-west1
      

      Untuk mengetahui informasi selengkapnya tentang perintah ini, lihat dokumentasi gcloud config set.

    5. Jalankan gcloud artifacts apt upload untuk mengupload paket ke repositori:

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

      Ganti FILE_NAME dengan jalur ke paket curl.

    Melihat paket di repositori

    Pastikan paket Anda telah ditambahkan ke repositori.

    Konsol

    1. Buka halaman Repositori di Google Cloud konsol.

      Buka halaman Repositori

    2. Di daftar repositori, klik repositori quickstart-apt-repo.

      Halaman Paket mencantumkan paket di repositori.

    gcloud

    Untuk mencantumkan paket di repositori quickstart-apt-repo, jalankan perintah:

     gcloud artifacts packages list
    

    Untuk melihat versi paket di quickstart-apt-repo, jalankan perintah:

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

    Mengonfigurasi pengelola paket

    Untuk menginstal paket di VM, tambahkan repositori yang Anda buat ke file konfigurasi Apt yang menentukan repositori paket.

    1. Instal helper kredensial Apt di VM untuk mengaktifkan Apt melakukan autentikasi:

      sudo apt install apt-transport-artifact-registry
      
    2. Konfigurasi VM Anda untuk mengakses paket 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
      

      Ganti PROJECT dengan Google Cloud project ID Anda.

    Menginstal paket

    Instal paket yang Anda tambahkan ke repositori.

    1. Perbarui daftar paket yang tersedia:

      sudo apt update
      
    2. Instal paket dari repositori Anda.

      sudo apt install curl/quickstart-apt-repo
      

      Informasi penginstalan yang ditampilkan akan terlihat seperti contoh berikut:

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

    Pembersihan

    Agar akun Google Cloud Anda tidak dikenai biaya untuk resource yang digunakan pada halaman ini, ikuti langkah-langkah berikut.

    Sebelum menghapus repositori, pastikan semua paket yang ingin Anda simpan tersedia di lokasi lain.

    Untuk menghapus repositori:

    Konsol

    1. Buka halaman Repositori di Google Cloud konsol.

      Buka halaman Repositori

    2. Di daftar repositori, pilih repositori quickstart-apt-repo.

    3. Klik Hapus.

    gcloud

    1. Untuk menghapus repositori quickstart-apt-repo, jalankan perintah berikut:

      gcloud artifacts repositories delete quickstart-apt-repo
      
    2. Jika Anda ingin menghapus setelan repositori dan lokasi default yang Anda konfigurasi untuk konfigurasi gcloud aktif, jalankan perintah berikut:

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

    Untuk menghapus VM yang Anda buat, jalankan perintah berikut:

    gcloud compute instances delete quickstart-apt-vm
    

    Langkah berikutnya