Questa pagina descrive le seguenti attività:
- Visualizzazione ed eliminazione di pacchetti e versioni di pacchetti
- Visualizzazione, creazione, aggiornamento ed eliminazione di tag
Prima di iniziare
- Se il repository di destinazione non esiste, creane uno nuovo.
- Verifica di disporre delle autorizzazioni richieste per il repository.
- Configura l'autenticazione per npm.
- (Facoltativo) Configura le impostazioni predefinite per i comandi gcloud.
- Se utilizzi l'helper per le credenziali npm per l'autenticazione, ottieni un token di accesso prima di connetterti a un repository con npm.
Ruoli obbligatori
Per ottenere le autorizzazioni necessarie per gestire i pacchetti, chiedi all'amministratore di concederti i seguenti ruoli IAM per il repository:
-
Visualizza pacchetti, file nei pacchetti e tag:
Lettore di Artifact Registry (
roles/artifactregistry.reader) -
Scarica o installa pacchetti:
Lettore di Artifact Registry (
roles/artifactregistry.reader) -
Aggiungi pacchetti a un repository:
Writer di Artifact Registry (
roles/artifactregistry.writer) -
Elimina pacchetti:
Amministratore del repository di Artifact Registry (
roles/artifactregistry.repoAdmin)
Per saperne di più sulla concessione dei ruoli, consulta Gestisci l'accesso a progetti, cartelle e organizzazioni.
Potresti anche riuscire a ottenere le autorizzazioni richieste tramite i ruoli personalizzati o altri ruoli predefiniti.
Ottenere un token di accesso
I token di accesso sono validi per 60 minuti. Genera un token di accesso poco prima di eseguire i comandi che interagiscono con i repository.
Per ottenere un token, utilizza una di queste opzioni:
Utilizza il comando
npxper aggiornare il token di accesso.Assicurati che le credenziali per la connessione al registro npm pubblico siano nel file di configurazione npm dell'utente,
~/.npmrc.Esegui il comando seguente nella directory del progetto Node.js.
npx google-artifactregistry-authSe il repository Artifact Registry è impostato come registro globale e i pacchetti non sono inclusi nell'ambito, utilizza il seguente comando in modo che il comando possa scaricare l'helper per le credenziali dal registro npm pubblico anziché dal repository Artifact Registry.
npm_config_registry=https://registry.npmjs.org npx google-artifactregistry-auth
Aggiungi uno script al file
package.jsonnel progetto."scripts": { "artifactregistry-login": "npx google-artifactregistry-auth" }Esegui lo script nella directory del progetto Node.js.
npm run artifactregistry-login
Artifact Registry legge le impostazioni del repository Artifact Registry nel file .npmrc del progetto e le utilizza per aggiungere le credenziali del token al file .npmrc dell'utente. L'archiviazione del token nel file .npmrc dell'utente isola le credenziali dal codice sorgente e dal sistema di controllo del codice sorgente.
Aggiungere pacchetti
Modalità repository: standard
Puoi pubblicare una versione specifica di un pacchetto una sola volta. Si tratta di una limitazione npm per garantire che i contenuti di una versione del pacchetto pubblicato siano sempre gli stessi. Di conseguenza, non puoi:
- Sovrascrivere una versione del pacchetto pubblicandola di nuovo nel repository
- Rimuovere un pacchetto o la relativa versione dal repository e poi pubblicare un pacchetto con lo stesso nome e numero di versione
Se non specifichi un tag quando pubblichi un pacchetto, npm aggiunge il tag latest.
Per semplificare l'installazione dei pacchetti in una fase di sviluppo specifica, valuta la possibilità di pubblicare i pacchetti con un tag, ad esempio beta o dev.
Artifact Registry applica nomi di pacchetti alfanumerici in minuscolo per i pacchetti npm.
Per aggiungere un pacchetto:
Assicurati che il nome del pacchetto in
package.jsonincluda l' ambito configurato per il repository. L'esempio seguente mostra un pacchetto con l'ambitodev-repo."name": "@dev-repo/my-package"Se utilizzi l'helper per le credenziali per l'autenticazione con un token di accesso, ottieni un nuovo token.
Aggiungi i pacchetti al repository. Puoi utilizzare un comando
npmoyarn.Per taggare il pacchetto, includi il
--tagflag e sostituisci TAG con il tag che vuoi utilizzare. Se non includi il flag--tag, npm imposta automaticamente il tag sulatest.npm publish --tag=TAGyarn publish --tag TAG
Visualizzare pacchetti e versioni
Modalità repository: standard, remoto, virtuale
Per ottenere informazioni sui pacchetti con npm o yarn:
Se utilizzi l'helper per le credenziali per l'autenticazione con un token di accesso, ottieni un nuovo token.
Esegui il comando appropriato:
npm viewyarn info
Per visualizzare i pacchetti e le versioni dei pacchetti utilizzando la Google Cloud console
o gcloud:
Console
Apri la pagina Repository nella Google Cloud console.
Nell'elenco dei repository, fai clic sul repository appropriato.
La pagina Pacchetti elenca i pacchetti nel repository.
Fai clic su un pacchetto per visualizzarne le versioni.
gcloud
Per elencare i pacchetti in un repository, esegui questo comando:
gcloud artifacts packages list [--repository=REPOSITORY] [--location=LOCATION]
Sostituisci quanto segue:
REPOSITORYè il nome del repository. Se hai configurato un repository predefinito, puoi omettere questo flag per utilizzare quello predefinito.-
LOCATIONè la località regionale o multiregionale del repository. Se hai configurato una località predefinita, puoi omettere questo flag per utilizzare quella predefinita.
Per visualizzare le versioni di un pacchetto, esegui questo comando:
gcloud artifacts versions list --package=PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION]
Sostituisci quanto segue:
PACKAGEè l'ID del pacchetto o l'identificatore completo del pacchetto.REPOSITORYè il nome del repository. Se hai configurato un repository predefinito, puoi omettere questo flag per utilizzare quello predefinito.-
LOCATIONè la località regionale o multiregionale del repository. Utilizza questo flag per visualizzare i repository in una località specifica. Se hai configurato una località predefinita, puoi omettere questo flag per utilizzare quella predefinita.
La visualizzazione di pacchetti e versioni da Google Cloud console o da gcloud CLI è disponibile solo per i repository standard e remoti.
Per i repository remoti, l'elenco restituito deve includere tutte le dipendenze dirette e transitive memorizzate nella cache nel repository.
Elencare i file
Modalità repository: standard, remoto
Puoi elencare i file in un repository, i file in tutte le versioni di un pacchetto specificato o i file in una versione specifica di un pacchetto.
Per tutti i comandi seguenti, puoi impostare un numero massimo di file da restituire aggiungendo il flag --limit al comando.
Per elencare tutti i file nel progetto, nel repository e nella località predefiniti quando sono configurati i valori predefiniti:
gcloud artifacts files list
Per elencare i file in un progetto, in un repository e in una località specificati, esegui il comando:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION
Per elencare i file per tutte le versioni di un pacchetto specifico:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION \
--package=PACKAGE
Per elencare i file per una versione specifica del pacchetto:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION \
--package=PACKAGE \
--version=VERSION
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION \
--package=PACKAGE \
--tag=TAG
Sostituisci i seguenti valori:
LOCATION: la località regionale o multiregionale del repository.PROJECT: il tuo Google Cloud ID progetto. Se l'ID progetto contiene due punti (:), consulta Progetti basati sul dominio.REPOSITORY: il nome del repository in cui è archiviata l'immagine.PACKAGE: il nome del pacchetto.VERSION: la versione del pacchetto.TAG: il tag associato al pacchetto.
Esempi
Considera le seguenti informazioni sul pacchetto:
- Progetto:
my-project - Repository:
my-repo - Località del repository:
us-west1 - Pacchetto:
my-app
Il comando seguente elenca tutti i file nel repository my-repo nella
località us-west1 all'interno del progetto predefinito:
gcloud artifacts files list \
--location=us-west1 \
--repository=my-repo
1.0 del pacchetto.
gcloud artifacts files list \
--project=my-project \
--location=us-west1 \
--repository=my-repo \
--package=my-app \
--version=1.0
1.0-dev
gcloud artifacts files list \
--project=my-project \
--location=us-west1 \
--repository=my-repo \
--package=my-app \
--tag=1.0-dev
Tagging dei pacchetti
Modalità repository: standard
You can view, add, update, and delete tags. Tags can help you manage semantic versions of your packages and streamline installation of packages at a specific stage of development.
For example, you can tag the current release candidate build with rc. Your
team can then install the correct version based on the tag instead of a
version specifier, and unpublishing unused pre-release versions won't break
your dependencies on the release candidate package.
Viewing tags
To view tags for a package:
Console
Open the Repositories page in the Google Cloud console.
Click the package to view versions and the associated tags.
Select the package version to tag.
In the row of the selected version, click More actions (
),
and then click Edit tags.Type new tags into the field and then click SAVE.
gcloud
Run the command:
gcloud artifacts tags list --package=PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION]
Where
- PACKAGE is the name of the package in the repository.
- REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
- LOCATION is a regional or multi-regional location. Use this flag to view repositories in a specific location. If you configured a default location, you can omit this flag to use the default.
For example, to view tags for the package my-package in the repository
my-repo in the default location, run the command:
gcloud artifacts tags list --package=my-pkg --repository=my-repo
Creating tags
You can create a tag for a specific version of a package.
To tag an existing image in a repository:
Console
Open the Repositories page in the Google Cloud console.
Click the package to view versions of the package.
Select the package version to tag.
In the row of the selected version, click More actions (
),
and then click Edit tags.Type new tags into the field and then click SAVE.
gcloud
Run the following command:
gcloud artifacts tags create TAG --package=PACKAGE \
version=VERSION [--location=LOCATION] [--repository=REPOSITORY]
Where
- TAG is the tag you want to apply to the package.
- PACKAGE is the name of the package in the repository.
- VERSION is version of the package that you want to tag.
- LOCATION is a regional or multi-regional location. Use this flag to view repositories in a specific location. If you configured a default location, you can omit this flag to use the default.
- REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
For example, to create the tag release-candidate for version 1.0.0 of package
my-package in the repository my-repo in the default location, run the
command:
gcloud artifacts tags create release-candidate --version=1.0.0 \
--package=my-pkg --repository=my-repo
Updating tags
You can change a tag associated with a package version.
To change an existing tag:
Console
Open the Repositories page in the Google Cloud console.
Click the package to view versions of the package.
Select the package version with the tag to change.
In the row of the selected version, click More actions (
),
and then click Edit tags.Edit the tag and then click SAVE.
gcloud
Run the following command:
gcloud artifacts tags update TAG --package=PACKAGE \
version=VERSION [--location=LOCATION] [--repository=REPOSITORY]
Where
- TAG is the tag you want to apply to the package.
- PACKAGE is the name of the package in the repository.
- VERSION is version of the package that you want to tag.
- LOCATION is a regional or multi-regional location. Use this flag to view repositories in a specific location. If you configured a default location, you can omit this flag to use the default.
- REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
For example, to change the tag for version 1.0.0 of package
my-package to production in the repository my-repo in the default
location, run the command:
gcloud artifacts tags update production --version=1.0.0 \
--package=my-pkg --repository=my-repo
Untagging package versions
You can remove an existing tag from a package version.
To remove a tag:
Console
Open the Repositories page in the Google Cloud console.
Click the image to view versions of the image.
Select the image version to untag.
In the row of the selected version, click More actions (
),
and then click Edit tags.Delete the tag and then click SAVE.
gcloud
Run the following command:
gcloud artifacts tags delete TAG --package=PACKAGE \
[--location=<LOCATION] [--repository=REPOSITORY]
Where
- TAG is the tag you want to apply to the package.
- PACKAGE is the name of the package in the repository.
- LOCATION is a regional or multi-regional location. Use this flag to view repositories in a specific location. If you configured a default location, you can omit this flag to use the default.
- REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
For example, to remove the tag release-candidate from package
my-package in the repository my-repo in the default
location, run the command:
gcloud artifacts tags delete release-candidate --package=my-pkg \
--repository=my-repo
Installare i pacchetti
Modalità repository: standard, remoto, virtuale
Per installare un pacchetto dal repository di pacchetti Node.js:
Se utilizzi l'helper per le credenziali per l'autenticazione con un token di accesso, ottieni un nuovo token.
Utilizza il comando
npm installoyarn add.npm
Per installare la versione con il tag
latest:npm install @SCOPE/PACKAGEPer installare la versione con un tag diverso:
npm install @SCOPE/PACKAGE@TAGPer installare una versione specifica:
npm install @SCOPE/PACKAGE@VERSIONyarn
Per installare la versione con il tag
latest:yarn add @SCOPE/PACKAGEPer installare la versione con un tag diverso:
yarn add @SCOPE/PACKAGE@TAGPer installare una versione specifica:
yarn add @SCOPE/PACKAGE@VERSIONSostituisci i seguenti valori:
- SCOPE è l'ambito associato al repository. Se il
repository di pacchetti Node.js non è configurato con un ambito, ometti
@SCOPE/dal comando. - PACKAGE è il nome del pacchetto nel repository.
- TAG è il tag della versione che vuoi installare.
- VERSION è il numero di versione che vuoi installare.
- SCOPE è l'ambito associato al repository. Se il
repository di pacchetti Node.js non è configurato con un ambito, ometti
Quando specifichi un pacchetto come dipendenza in package.json, assicurati di includere l'ambito del repository. L'esempio seguente mostra l'ambito @dev-repo per un pacchetto denominato my-package.
"dependencies": {
"@dev-repo/my-package": ">=1.0.0"
}
Per i repository standard, scarichi un pacchetto direttamente dal repository.
Per un repository remoto, scarichi una copia memorizzata nella cache del pacchetto e delle relative dipendenze. Se non esiste una copia memorizzata nella cache, il repository remoto scarica il pacchetto dall'origine upstream e lo memorizza nella cache prima di fornirtelo. Puoi verificare che il repository remoto abbia recuperato i pacchetti dall' origine upstream visualizzando l'elenco dei pacchetti nel repository.
Per un repository virtuale, Artifact Registry cerca il pacchetto richiesto nei repository upstream.
- I repository remoti upstream scaricheranno e memorizzeranno nella cache il pacchetto richiesto se non esiste una copia memorizzata nella cache. I repository virtuali forniscono solo i pacchetti richiesti, non li archiviano.
- Se richiedi una versione disponibile in più repository upstream, Artifact Registry sceglie un repository upstream da utilizzare in base alle impostazioni di priorità configurate per il repository virtuale.
Considera ad esempio un repository virtuale con le seguenti impostazioni di priorità per i repository upstream:
main-repo: priorità impostata su100secondary-repo1: priorità impostata su80.secondary-repo2: priorità impostata su80.test-repo: priorità impostata su20.
main-repo ha il valore di priorità più alto, quindi il repository virtuale lo cerca sempre per primo.
Sia secondary-repo1 sia secondary-repo2 hanno la priorità impostata su 80. Se un pacchetto richiesto non è disponibile in main-repo, Artifact Registry cerca questi repository successivamente. Poiché hanno lo stesso valore di priorità, Artifact Registry può scegliere di fornire un pacchetto da uno dei due repository se la versione è disponibile in entrambi.
test-repo ha il valore di priorità più basso e fornirà un artefatto archiviato se nessuno degli altri repository upstream lo ha.
Eliminare i pacchetti
Modalità repository: standard, remoto
Puoi eliminare un pacchetto e tutte le relative versioni oppure eliminare una versione specifica.
- Una volta eliminato un pacchetto, non puoi annullare l'azione.
- Per i repository remoti, viene eliminata solo la copia memorizzata nella cache del pacchetto. L'origine upstream non è interessata. Se elimini un pacchetto memorizzato nella cache, Artifact Registry lo scaricherà e lo memorizzerà di nuovo nella cache la prossima volta che il repository riceverà una richiesta per la stessa versione del pacchetto.
Dopo la pubblicazione di una versione del pacchetto, non puoi ripubblicare un pacchetto con la stessa combinazione di nome e versione, anche dopo aver eliminato la versione. Si tratta di una limitazione npm per garantire che i contenuti di una versione del pacchetto pubblicato siano sempre gli stessi.
Se vuoi incoraggiare gli utenti a installare una versione aggiornata del pacchetto, utilizza il comando npm deprecate per contrassegnare la versione precedente del pacchetto come obsoleta. Quando un utente tenta di installare il pacchetto obsoleto, Artifact Registry restituisce un avviso di obsolescenza.
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
Open the Repositories page in the Google Cloud console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Select the package that you want to delete.
Click DELETE.
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:
PACKAGEis the name of the package in the repository.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis 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
Open the Repositories page in the Google Cloud console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Click a package to view versions of that package.
Select versions that you want to delete.
Click DELETE.
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:
VERSIONis the name of the version to delete.PACKAGEis the name of the package in the repository.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis 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.
Passaggi successivi
- Scopri di più sulla gestione dei pacchetti Maven
- Scopri di più sulla gestione delle immagini container
- Scarica singoli file all'interno di un pacchetto