Gestire i pacchetti Debian

I repository Apt in Artifact Registry ti consentono di gestire centralmente i tuoi pacchetti Debian e di mantenere dipendenze software coerenti nei tuoi workload Linux. Puoi aggiungere, visualizzare ed eliminare i pacchetti o installarli sulle VM configurate.

Prima di iniziare

  1. Se il repository Apt di destinazione non esiste, crea un nuovo repository.
  2. Configura le VM per accedere al repository.
  3. (Facoltativo) Configura i valori predefiniti per i comandi gcloud.
  4. Assicurati che i nomi dei pacchetti nei metadati soddisfino gli standard dei nomi dei pacchetti Debian.

Aggiunta di pacchetti

Modalità repository: standard

Per aggiungere pacchetti, devi disporre delle autorizzazioni di lettura e scrittura per il repository.

Puoi caricare un pacchetto in un repository utilizzando Google Cloud CLI o importare un pacchetto archiviato in Cloud Storage. Se crei pacchetti utilizzando Cloud Build, la build può archiviare i pacchetti in Cloud Storage per l'importazione.

Le operazioni di importazione o caricamento molto lunghe potrebbero superare il periodo di scadenza del token utilizzato da gcloud CLI per chiamare l'API. Se hai un numero molto elevato di pacchetti da aggiungere, valuta la possibilità di aggiungerli in batch più piccoli in modo che ogni operazione di caricamento o importazione possa essere completata in un periodo di tempo più breve. Per saperne di più, consulta la documentazione sulla risoluzione dei problemi relativi ai pacchetti del sistema operativo.

Caricamento diretto

Utilizza il comando gcloud artifacts apt upload per caricare un pacchetto in un repository Apt:

gcloud artifacts apt upload REPOSITORY \
    --location=LOCATION \
    --source=PACKAGES

Sostituisci i seguenti valori:

  • REPOSITORY è il nome del repository Artifact Registry.
  • LOCATION è la località regionale o multiregionale del repository.
  • PACKAGES è il percorso del pacchetto.

Ad esempio, per caricare il pacchetto my-package.deb nel repository Apt my-repo nella località us-west1, esegui:

gcloud artifacts apt upload my-repo \
    --location=us-west1 \
    --source=my-package.deb

Cloud Storage

  1. Carica i pacchetti su Cloud Storage nel seguente modo:
    • Carica i pacchetti direttamente in un bucket Cloud Storage
    • Crea pacchetti con Cloud Build e archiviali in un bucket
  2. Esegui questo comando:
    gcloud artifacts apt import REPOSITORY \
      --location=LOCATION \
      --gcs-source=PACKAGES
    

    Sostituisci i seguenti valori:

    • REPOSITORY è il nome del repository Artifact Registry.
    • LOCATION è la località regionale o multiregionale del repository.
    • PACKAGES è un elenco separato da virgole di pacchetti in Cloud Storage. Per caricare tutti i pacchetti da una directory, utilizza un carattere jolly per la directory (*) o un carattere jolly per la directory ricorsiva (**) per caricare tutti i pacchetti in tutte le sottodirectory.

    Ad esempio, per caricare il pacchetto package.deb e tutti i pacchetti nella directory directory dal bucket my-bucket nel repository Apt my-repo nella località us-west1, esegui:

    gcloud artifacts apt import my-repo \
      --location=us-west1 \
      --gcs-source=gs://my-bucket/path/to/package.deb,gs://my-bucket/directory*
    

Al termine dell'operazione di caricamento o importazione, puoi utilizzare la consoleGoogle Cloud o gcloud CLI per visualizzare i pacchetti nel repository e verificare che siano stati caricati correttamente.

Se hai un repository di grandi dimensioni con molti pacchetti, la rigenerazione dell'indice dei pacchetti potrebbe richiedere diversi minuti, in modo che i nuovi pacchetti siano visibili al client Apt.

Visualizzazione dei pacchetti

Modalità repository: standard, remoto (anteprima)

Per visualizzare i pacchetti, devi disporre delle autorizzazioni nel ruolo Artifact Registry Reader. Artifact Registry non elenca i file all'interno dei pacchetti.

To view packages and package versions using the Google Cloud console or gcloud:

Console

  1. Open the Repositories page in the Google Cloud console.

    Apri la pagina Repositori

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Click a package to view versions of the package.

gcloud

To list packages in a repository, run the following command:

gcloud artifacts packages list [--repository=REPOSITORY] [--location=LOCATION]

Replace the following:

  • REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
  • LOCATION is the regional or multi-regional location of the repository. If you configured a default location, then you can omit this flag to use the default.

To view versions of a package, run the following command:

gcloud artifacts versions list --package=PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION]

Replace the following:

  • PACKAGE is the ID of the package or fully qualified identifier for the package.
  • REPOSITORY is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.
  • LOCATION is the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.

Installazione dei pacchetti

Repository modes: standard, remote (preview)

Prima di installare i pacchetti, verifica di aver configurato correttamente il gestore di pacchetti e il repository.

Per installare un pacchetto nel repository:

  1. Aggiorna l'elenco dei pacchetti disponibili:

    sudo apt update
    
  2. Installa il pacchetto, specificando il nome del repository configurato in Apt.

    sudo apt install PACKAGE/REPOSITORY
    

    Sostituisci i seguenti valori:

    • PACKAGE è il nome del pacchetto.
    • REPOSITORY è il nome del repository Artifact Registry. Per i repository remoti, utilizza il nome del repository standard upstream.

    Ad esempio, per installare il pacchetto my-package dal repository my-repo, esegui il comando:

    sudo apt install my-package -t my-repo
    

Eliminazione dei pacchetti

Modalità repository: standard

Before you delete a package or package version, verify that any you have communicated or addressed any important dependencies on it.

To delete a package:

Console

  1. Open the Repositories page in the Google Cloud console.

    Apri la pagina Repositori

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Select the package that you want to delete.

  4. Click DELETE.

  5. In the confirmation dialog box, click DELETE.

gcloud

Run the following command:

gcloud artifacts packages delete PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION] [--async]

Replace the following:

  • PACKAGE is the name of the package in the repository.
  • REPOSITORY is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.
  • LOCATION is the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.

The --async flag causes the command to return immediately, without waiting for the operation in progress to complete.

To delete versions of a package:

Console

  1. Open the Repositories page in the Google Cloud console.

    Apri la pagina Repositori

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Click a package to view versions of that package.

  4. Select versions that you want to delete.

  5. Click DELETE.

  6. In the confirmation dialog box, click DELETE.

gcloud

Run the following command:

gcloud artifacts versions delete VERSION \
    --package=PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION] \
    [--async]

Replace the following:

  • VERSION is the name of the version to delete.
  • PACKAGE is the name of the package in the repository.
  • REPOSITORY is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.
  • LOCATION is the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.

The --async flag causes the command to return immediately, without waiting for the operation in progress to complete.

Per i repository di grandi dimensioni, la rigenerazione dell'indice dei pacchetti Apt per riflettere le eliminazioni può richiedere alcuni minuti.

Passaggi successivi