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
- 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.
-
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 theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud 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.enable
permission. Learn how to grant roles. -
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 theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud 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.enable
permission. Learn how to grant roles. Per creare un repository di formato generico denominato
quickstart-generic-repo
nella localitàus-central1
con la descrizioneGeneric repository
, esegui questo comando:gcloud artifacts repositories create quickstart-generic-repo \ --repository-format=generic \ --location=us-central1 \ --description="Generic repository"
Per verificare che il repository sia stato creato, esegui questo comando:
gcloud artifacts repositories list
Per semplificare i comandi
gcloud
, esegui i seguenti comandi per impostare il repository predefinito suquickstart-generic-repo
e la località predefinita suus-central1
.Per impostare il repository predefinito su
quickstart-generic-repo
, esegui il seguente comando:gcloud config set artifacts/repository quickstart-generic-repo
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.Nella tua home directory, crea un file da caricare nel repository:
echo "hello world" > hello.yaml
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.
hello.yaml
è il nome del file da scaricare.my-package
è il pacchetto da scaricare.1.0.0
è la versione dell'artefatto.- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
Per eliminare il repository
quickstart-generic-repo
, esegui questo comando:gcloud artifacts repositories delete quickstart-generic-repo
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
Avvia Cloud Shell
In the Google Cloud console, 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
Carica un artefatto 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:
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
Elimina il repository
Prima di rimuovere un repository, assicurati che tutti i pacchetti che vuoi conservare siano disponibili in un'altra posizione.