Artifact Registry に他の形式を保存する
Artifact Registry の汎用形式のリポジトリを設定し、YAML ファイルをアップロードする方法を学習します。
始める前に
- アカウントにログインします。 Google Cloud を初めて使用する場合は、 アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。 Google Cloud新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
-
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.enablepermission. 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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
-
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.enablepermission. Learn how to grant roles.
必要なロール
Artifact Registry Package Repository の作成と管理に必要な権限を取得するには、プロジェクトに対するArtifact Registry 管理者 (roles/artifactregistry.admin)IAM ロールの付与を管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織に対するアクセス権の管理をご覧ください。
Cloud Shell を起動する
コンソールで Cloud Shell をアクティブにします。 Google Cloud
コンソールの下部にある Google Cloud Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。Cloud Shell はシェル環境です 。Google Cloud CLI がすでにインストールされており、現在のプロジェクトの値もすでに設定されています 。セッションが初期化されるまで数秒かかることがあります。
このクイックスタートでは、Cloud Shell を使用して gcloud コマンドを実行します。
汎用リポジトリを作成する
ロケーション
us-central1にGeneric repositoryという説明でquickstart-generic-repoという名前の汎用形式のリポジトリを作成するには、次のコマンドを実行します。gcloud artifacts repositories create quickstart-generic-repo \ --repository-format=generic \ --location=us-central1 \ --description="Generic repository"次のコマンドを実行して、リポジトリが作成されたことを確認します。
gcloud artifacts repositories listgcloudコマンドを簡単にするために、以下のコマンドを実行して、デフォルトのリポジトリをquickstart-generic-repoに、デフォルトのロケーションをus-central1に設定します。デフォルトのリポジトリを
quickstart-generic-repoに設定するには、次のコマンドを実行します。gcloud config set artifacts/repository quickstart-generic-repoデフォルトの場所を
us-central1に設定するには、次のコマンドを実行します。gcloud config set artifacts/location us-central1
デフォルト値を設定すると、
gcloudコマンドでリポジトリまたはロケーションが必要な場合でも指定の必要はありません。
リポジトリにアーティファクトをアップロードする
ホーム ディレクトリで、リポジトリにアップロードするファイルを作成します。
echo "hello world" > hello.yamlファイルをアーティファクトとしてリポジトリにアップロードするには、次のコマンドを実行します。
gcloud artifacts generic upload \ --source=hello.yaml \ --package=my-package \ --version=1.0.0説明:
hello.yamlは、アップロードするファイルのパスです。my-packageは、アップロードするパッケージです。1.0.0は、アーティファクトのバージョンです。リポジトリ内の既存のバージョンは上書きできません。
リポジトリ内のアーティファクトを表示する
アーティファクトがリポジトリに追加されたことを確認するには、次のコマンドを実行してすべてのアーティファクトを一覧表示します。
gcloud artifacts files list
レスポンスには、ファイルの詳細情報が PACKAGE:VERSION:FILE_NAME という形式で含まれます。
次の例では、hello.yaml が 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
汎用アーティファクトをダウンロードする
リポジトリから汎用アーティファクトをダウンロードするには、次のコマンドを実行します。
gcloud artifacts generic download \
--name=hello.yaml \
--package=my-package \
--version=1.0.0 \
--destination=DESTINATION
説明:
hello.yamlは、ダウンロードするファイルの名前です。my-packageは、ダウンロードするパッケージです。1.0.0は、アーティファクトのバージョンです。
DESTINATION は、ダウンロードしたものを保存するローカル ファイル システムのディレクトリに置き換えます。ダウンロード先フォルダはすでに存在している必要があります。存在しない場合、コマンドは失敗します。
クリーンアップ
このチュートリアルで使用したリソースについて Google Cloud アカウントに課金されないようにするには、リソースを含むプロジェクトを削除するか、プロジェクトを維持してリポジトリを削除します。
プロジェクトの削除
プロジェクトを削除します。 Google Cloud
gcloud projects delete PROJECT_ID
リポジトリを削除する
リポジトリを削除する前に、保持する必要があるパッケージが別の場所で使用可能であることを確認してください。
quickstart-generic-repoリポジトリを削除するには、次のコマンドを実行します。gcloud artifacts repositories delete quickstart-generic-repoアクティブな
gcloud構成のデフォルトのリポジトリとロケーション設定を削除するには、次のコマンドを実行します。gcloud config unset artifacts/repository gcloud config unset artifacts/location