このページでは、次のタスクについて説明します。
- パッケージとパッケージ バージョンの表示と削除
- タグの表示、作成、更新、削除
始める前に
- ターゲット リポジトリが存在しない場合は、新しいリポジトリを作成します。
- リポジトリに必要な権限が付与されていることを確認します。
- npm の認証を構成します。
- (省略可)gcloud コマンドのデフォルトを構成します。
- npm 認証情報ヘルパーを使用して認証する場合は、npm でリポジトリに接続する前にアクセス トークンを取得します。
必要なロール
パッケージの管理に必要な権限を取得するには、リポジトリに対する次の IAM ロールの付与を管理者に依頼してください。
-
パッケージ、パッケージ内のファイル、タグを表示する:
Artifact Registry 読み取り (
roles/artifactregistry.reader) -
パッケージをダウンロードまたはインストールする:
Artifact Registry 読み取り (
roles/artifactregistry.reader) -
リポジトリにパッケージを追加する:
Artifact Registry 書き込み (
roles/artifactregistry.writer) -
パッケージを削除する:
Artifact Registry リポジトリ管理者 (
roles/artifactregistry.repoAdmin)
ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。
必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。
アクセス トークンの取得
アクセス トークンは 60 分間有効です。リポジトリを操作するコマンドを実行する直前にアクセス トークンを生成します。
トークンを取得するには、次のいずれかのオプションを使用します。
npxコマンドを使用して、アクセス トークンを更新する。公開 npm レジストリに接続するための認証情報が、ユーザーの npm 構成ファイル
~/.npmrcに含まれていることを確認します。Node.js プロジェクト ディレクトリで次のコマンドを実行します。
npx google-artifactregistry-authArtifact Registry リポジトリがグローバル レジストリとして設定され、パッケージのスコープが設定されていない場合は、次のコマンドを使用すると、Artifact Registry リポジトリではなく公開 npm レジストリから認証情報ヘルパーをダウンロードできます。
npm_config_registry=https://registry.npmjs.org npx google-artifactregistry-auth
プロジェクトの
package.jsonファイルにスクリプトを追加します。"scripts": { "artifactregistry-login": "npx google-artifactregistry-auth" }Node.js プロジェクト ディレクトリでスクリプトを実行します。
npm run artifactregistry-login
Artifact Registry はプロジェクト .npmrc ファイル内の Artifact Registry リポジトリの設定を読み取り、それらを使用してユーザーの .npmrc ファイルにトークン認証情報を追加します。ユーザーの .npmrc ファイルにトークンを保存すると、認証情報がソースコードとソース コントロール システムから分離されます。
パッケージの追加
リポジトリ モード: 標準
パッケージの特定のバージョンを公開できるのは 1 回のみです。これは npm の制限であり、公開されるパッケージ バージョンの内容が常に同じになるようにします。そのため、次のことはできません。
- パッケージ バージョンをリポジトリに再度公開して上書きする
- リポジトリからパッケージまたはそのバージョンを削除してから、同じ名前とバージョン番号のパッケージを公開する
パッケージを公開するときにタグを指定しない場合、npm は latest タグを追加します。特定の開発段階でパッケージのインストールを簡素化するには、beta や dev などのタグを使用してパッケージを公開することを検討してください。
Artifact Registry は、npm パッケージに英数字の小文字のパッケージ名を適用します。
パッケージを追加するには、次の手順を行います。
package.jsonのパッケージ名に、リポジトリに設定されたスコープが含まれていることを確認します。次の例は、dev-repoというスコープを持つパッケージを示しています。"name": "@dev-repo/my-package"認証情報ヘルパーを使用してアクセス トークンで認証する場合は、新しいトークンを取得します。
リポジトリにパッケージを追加する。
npm、もしくはyarnコマンドを使用できます。パッケージにタグを付けるには、
--tagフラグを指定し、TAG を使用するタグに置き換えます。--tagフラグを指定しない場合、npm はタグを自動的にlatestに設定します。npm publish --tag=TAGyarn publish --tag TAG
パッケージとバージョンを表示する
リポジトリ モード: 標準、リモート、仮想
npm または yarn を使用してパッケージ情報を取得するには:
認証情報ヘルパーを使用してアクセス トークンで認証する場合は、新しいトークンを取得します。
適切なコマンドを実行します。
npm viewyarn info
Google Cloud コンソールまたは gcloud を使用してパッケージとパッケージのバージョンを表示するには:
コンソール
Google Cloud コンソールで [リポジトリ] ページを開きます。
リポジトリ リストで、適切なリポジトリをクリックします。
[パッケージ] ページに、リポジトリ内のパッケージが一覧表示されます。
パッケージをクリックして、そのパッケージのバージョンを表示します。
gcloud
リポジトリ内のパッケージを一覧表示するには、次のコマンドを実行します。
gcloud artifacts packages list [--repository=REPOSITORY] [--location=LOCATION]
以下を置き換えます。
REPOSITORYはリポジトリの名前です。デフォルト リポジトリを構成した場合は、このフラグを省略してデフォルトを使用できます。-
LOCATIONは、リポジトリのリージョンまたはマルチリージョンのロケーションです。 デフォルト ロケーションを構成している場合は、このフラグを省略してデフォルトを使用できます。
パッケージのバージョンを表示するには、次のコマンドを実行します。
gcloud artifacts versions list --package=PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION]
以下を置き換えます。
Google Cloud コンソールまたは gcloud CLI からパッケージとバージョンを表示する機能は、標準リポジトリとリモート リポジトリでのみ使用できます。
リモート リポジトリの場合、返されるリストには、リポジトリにキャッシュ保存されているすべての直接的な依存関係と一時的な依存関係が含まれます。
ファイルのリスティング
リポジトリ モード: 標準、リモート
リポジトリ内のファイル、指定したパッケージのすべてのバージョン内のファイル、またはパッケージの特定のバージョン内のファイルを一覧表示できます。
次のすべてのコマンドについては、コマンドに --limit フラグを追加することで、返されるファイルの最大数を設定できます。
デフォルト値が構成されている場合にデフォルトのプロジェクト、リポジトリ、ロケーションのすべてのファイルを一覧表示するには次のようにします。
gcloud artifacts files list
指定したプロジェクト、リポジトリ、ロケーション内のファイルを一覧表示するには、次のコマンドを実行します。
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION
特定のパッケージのすべてのバージョン内のファイルを一覧表示するには:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION \
--package=PACKAGE
特定のパッケージ バージョンのファイルを一覧表示するには:
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
次の値を置き換えます。
LOCATION: リポジトリのリージョンまたはマルチリージョン ロケーション。PROJECT: Google Cloud プロジェクト ID。プロジェクト ID にコロン(:)が含まれている場合は、ドメインをスコープとするプロジェクトをご覧ください。REPOSITORY: イメージが保存されるリポジトリの名前。PACKAGE: パッケージの名前。VERSION: パッケージのバージョン。TAG: パッケージに関連付けられているタグ。
例
次のパッケージ情報について考慮するには:
- プロジェクト:
my-project - リポジトリ:
my-repo - リポジトリの場所:
us-west1 - パッケージ:
my-app
次のコマンドは、デフォルト プロジェクト内のロケーション us-west1 のリポジトリ my-repo 内のすべてのファイルを一覧表示します。
gcloud artifacts files list \
--location=us-west1 \
--repository=my-repo
1.0 内のファイルを一覧表示します。
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
パッケージへのタグ付け
リポジトリ モード: 標準
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
パッケージのインストール
リポジトリ モード: 標準、リモート、仮想
Node.js パッケージ レポジトリ からパッケージをインストールするには:
認証情報ヘルパーを使用してアクセス トークンで認証する場合は、新しいトークンを取得します。
npm installコマンドまたはyarn addコマンドを使用します。npm
latestタグを使用してバージョンをインストールするには:npm install @SCOPE/PACKAGE別のタグを使用してバージョンをインストールするには:
npm install @SCOPE/PACKAGE@TAG特定のバージョンをインストールするには:
npm install @SCOPE/PACKAGE@VERSIONyarn
latestタグを使用してバージョンをインストールするには:yarn add @SCOPE/PACKAGE別のタグを使用してバージョンをインストールするには:
yarn add @SCOPE/PACKAGE@TAG特定のバージョンをインストールするには:
yarn add @SCOPE/PACKAGE@VERSION次の値を置き換えます。
- SCOPE は、リポジトリに関連付けられているスコープです。Node.js パッケージ リポジトリでスコープが構成されていない場合は、コマンドから
@SCOPE/を省略します。 - PACKAGE は、リポジトリ内のイメージの名前です。
- TAG は、インストールするバージョンのタグです。
- VERSION は、インストールするバージョン番号です。
- SCOPE は、リポジトリに関連付けられているスコープです。Node.js パッケージ リポジトリでスコープが構成されていない場合は、コマンドから
package.json でパッケージを依存関係として指定する場合は、リポジトリのスコープを含めるようにしてください。次の例では、@dev-repo という名前のパッケージの my-package スコープを示します。
"dependencies": {
"@dev-repo/my-package": ">=1.0.0"
}
標準リポジトリの場合は、リポジトリからパッケージを直接ダウンロードします。
リモート リポジトリの場合は、パッケージとその依存関係のキャッシュに保存されたコピーをダウンロードします。キャッシュに保存されたコピーが存在しない場合は、リモート リポジトリがアップストリーム ソースからパッケージをダウンロードし、それを提供する前にキャッシュに保存します。リモート リポジトリがアップストリーム ソースからパッケージを取得したことを確認するには、リポジトリ内のパッケージの一覧を表示します。
仮想リポジトリの場合は、Artifact Registry はリクエストされたパッケージのアップストリーム リポジトリを検索します。
- キャッシュに保存されたコピーが存在しない場合、アップストリームのリモート リポジトリは、リクエストされたパッケージをダウンロードしてキャッシュに保存します。仮想リポジトリはリクエストされたパッケージを提供だけして、保存しません。
- 複数のアップストリーム リポジトリに存在する利用可能なバージョンをリクエストすると、Artifact Registry は仮想リポジトリ用に構成された優先度設定に基づいて、使用するアップストリーム リポジトリを選択します。
たとえば、アップストリーム リポジトリに次の優先度設定がある仮想リポジトリについて考えます。
main-repo: 優先度が100に設定secondary-repo1: 優先度が80に設定secondary-repo2: 優先度が80に設定test-repo: 優先度が20に設定
main-repo の優先度の値は最も高いため、仮想リポジトリは常に最初に検索します。
secondary-repo1 と secondary-repo2 はどちらも優先度が 80 に設定されています。リクエストされたパッケージが main-repo にない場合、Artifact Registry は次にこれらのリポジトリを検索します。どちらも同じ優先度を持つため、両方にそのバージョンがある場合、Artifact Registry はどちらか一方のリポジトリからパッケージを提供するように選択できます。
test-repo の優先度は最も低くなります。他のアップストリーム リポジトリにアーティファクトがない場合、保存されたアーティファクトが提供されます。
パッケージの削除
リポジトリ モード: 標準、リモート
パッケージとそのすべてのバージョンを削除することや、特定のバージョンを削除することができます。
- パッケージを削除すると、その操作は元に戻せません。
- リモート リポジトリの場合は、パッケージのキャッシュに保存されたコピーのみが削除されます。アップストリーム ソース はこの影響を受けません。キャッシュに保存されたパッケージを削除し、次回、リポジトリが同じパッケージ バージョンのリクエストを受け取った場合、Artifact Registry は、そのパッケージを再度ダウンロードしてキャッシュに保存します。
パッケージ バージョンが公開された後は、バージョンを削除した後でも、同じ名前とバージョンの組み合わせを持つパッケージは再公開できません。これは npm の制限であり、公開されるパッケージ バージョンの内容が常に同じになるようにします。
ユーザーに更新されたパッケージ バージョンのインストールを促すには、npm deprecate コマンドを使用して、古いバージョンのパッケージを非推奨としてマークします。ユーザーが非推奨パッケージをインストールしようとすると、Artifact Registry から非推奨警告が返されます。
パッケージまたはパッケージのバージョンを削除する前に、そのパッケージの重要な依存関係を送信済み、または対処済みであることを確認してください。
パッケージを削除するには:
コンソール
Google Cloud コンソールで [リポジトリ] ページを開きます。
リポジトリ リストで、適切なリポジトリをクリックします。
[パッケージ] ページに、リポジトリ内のパッケージが一覧表示されます。
削除するパッケージを選択します。
[削除] をクリックします。
確認のダイアログ ボックスで、[削除] をクリックします。
gcloud
次のコマンドを実行します。
gcloud artifacts packages delete PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION] [--async]
以下を置き換えます。
PACKAGEは、リポジトリ内のイメージの名前です。REPOSITORYはリポジトリの名前です。デフォルト リポジトリを構成した場合は、このフラグを省略してデフォルトを使用できます。-
LOCATIONは、リポジトリのリージョンまたはマルチリージョンのロケーションです。 このフラグを使用して、特定のロケーションのリポジトリを表示します。デフォルト ロケーションを構成している場合は、このフラグを省略してデフォルトを使用できます。
--async フラグを使用すると、処理中のオペレーションの完了を待たずに、コマンドがすぐに返されます。
パッケージのバージョンを削除するには:
コンソール
Google Cloud コンソールで [リポジトリ] ページを開きます。
リポジトリ リストで、適切なリポジトリをクリックします。
[パッケージ] ページに、リポジトリ内のパッケージが一覧表示されます。
パッケージをクリックして、そのパッケージのバージョンを表示します。
削除するバージョンを指定します。
[削除] をクリックします。
確認のダイアログ ボックスで、[削除] をクリックします。
gcloud
次のコマンドを実行します。
gcloud artifacts versions delete VERSION \
--package=PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION] \
[--async]
以下を置き換えます。
VERSIONは、削除するバージョンの名前です。PACKAGEは、リポジトリ内のイメージの名前です。REPOSITORYはリポジトリの名前です。デフォルト リポジトリを構成した場合は、このフラグを省略してデフォルトを使用できます。-
LOCATIONは、リポジトリのリージョンまたはマルチリージョンのロケーションです。 このフラグを使用して、特定のロケーションのリポジトリを表示します。デフォルト ロケーションを構成している場合は、このフラグを省略してデフォルトを使用できます。
--async フラグを使用すると、処理中のオペレーションの完了を待たずに、コマンドがすぐに返されます。