Archiviare altri formati in Artifact Registry

Scopri come configurare un repository di formato generico di Artifact Registry e caricare un file YAML.

Prima di iniziare

  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 (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 (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. Avvia Cloud Shell

    In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

    In questa guida rapida utilizzerai Cloud Shell per eseguire i comandi gcloud.

    Crea un repository generico

    1. Per creare un repository di formato generico denominato quickstart-generic-repo nella località us-central1 con la descrizione Generic repository, esegui questo comando:

      gcloud artifacts repositories create quickstart-generic-repo \
          --repository-format=generic \
          --location=us-central1 \
          --description="Generic repository"
      
    2. Per verificare che il repository sia stato creato, esegui questo comando:

      gcloud artifacts repositories list
      
    3. Per semplificare i comandi gcloud, esegui i seguenti comandi per impostare il repository predefinito su quickstart-generic-repo e la località predefinita su us-central1.

      1. Per impostare il repository predefinito su quickstart-generic-repo, esegui il seguente comando:

        gcloud config set artifacts/repository quickstart-generic-repo
        
      2. Per impostare la posizione predefinita su us-central1, esegui il comando seguente:

        gcloud config set artifacts/location us-central1
        

      Una volta impostati i valori, non devi specificarli nei comandi gcloud che richiedono un repository o una posizione.

    Carica un artefatto nel repository

    1. Nella tua home directory, crea un file da caricare nel repository:

      echo "hello world" > hello.yaml
      
    2. Per caricare il file come artefatto nel repository, esegui questo comando:

      gcloud artifacts generic upload \
          --source=hello.yaml \
          --package=my-package \
          --version=1.0.0
      

      Dove:

      • hello.yaml è il percorso del file da caricare.
      • my-package è il pacchetto da caricare.
      • 1.0.0 è la versione dell'artefatto. Non puoi sovrascrivere una versione esistente nel repository.

    Visualizzare gli artefatti nel repository

    Per verificare che l'artefatto sia stato aggiunto al repository, puoi elencare tutti gli artefatti eseguendo questo comando:

    gcloud artifacts files list
    

    La risposta include i dettagli del file nel formato PACKAGE:VERSION:FILE_NAME.

    Nel seguente esempio, hello.yaml è il 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
    

    Scaricare un artefatto generico

    Per scaricare un artefatto generico dal repository, esegui questo comando:

    gcloud artifacts generic download \
        --name=hello.yaml \
        --package=my-package \
        --version=1.0.0 \
        --destination=DESTINATION
    

    Dove:

    • hello.yaml è il nome del file da scaricare.
    • my-package è il pacchetto da scaricare.
    • 1.0.0 è la versione dell'artefatto.

    Sostituisci DESTINATION con la directory nel file system locale in cui vuoi salvare il download. La cartella di destinazione deve già esistere, altrimenti il comando non andrà a buon fine.

    Esegui la pulizia

    Per evitare che al tuo account Google Cloud vengano addebitati costi relativi alle risorse utilizzate in questo tutorial, elimina il progetto che contiene le risorse oppure mantieni il progetto ed elimina il repository.

    Elimina il progetto

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    Elimina il repository

    Prima di rimuovere un repository, assicurati che tutti i pacchetti che vuoi conservare siano disponibili in un'altra posizione.

    1. Per eliminare il repository quickstart-generic-repo, esegui questo comando:

      gcloud artifacts repositories delete quickstart-generic-repo
      
    2. Se vuoi rimuovere il repository predefinito e le impostazioni di posizione configurate per la configurazione gcloud attiva, esegui i comandi seguenti:

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

    Passaggi successivi