Artifact Registry に他の形式を保存する

Artifact Registry の汎用形式のリポジトリを設定し、YAML ファイルをアップロードする方法を学習します。

始める前に

  1. アカウントにログインします。 Google Cloud を初めて使用する場合は、 アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。 Google Cloud新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
  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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. 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.

  4. Verify that billing is enabled for your Google Cloud project.

  5. 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

  6. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. 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.

  8. Verify that billing is enabled for your Google Cloud project.

  9. 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

必要なロール

Artifact Registry Package Repository の作成と管理に必要な権限を取得するには、プロジェクトに対するArtifact Registry 管理者 roles/artifactregistry.admin)IAM ロールの付与を管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織に対するアクセス権の管理をご覧ください。

必要な権限は、カスタム ロールや他の事前定義 ロールから取得することもできます。

Cloud Shell を起動する

コンソールで Cloud Shell をアクティブにします。 Google Cloud

Cloud Shell をアクティブにする

コンソールの下部にある Google Cloud Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。Cloud Shell はシェル環境です 。Google Cloud CLI がすでにインストールされており、現在のプロジェクトの値もすでに設定されています 。セッションが初期化されるまで数秒かかることがあります。

このクイックスタートでは、Cloud Shell を使用して gcloud コマンドを実行します。

汎用リポジトリを作成する

  1. ロケーション us-central1Generic repository という説明で quickstart-generic-repo という名前の汎用形式のリポジトリを作成するには、次のコマンドを実行します。

    gcloud artifacts repositories create quickstart-generic-repo \
        --repository-format=generic \
        --location=us-central1 \
        --description="Generic repository"
    
  2. 次のコマンドを実行して、リポジトリが作成されたことを確認します。

    gcloud artifacts repositories list
    
  3. gcloud コマンドを簡単にするために、以下のコマンドを実行して、デフォルトのリポジトリを quickstart-generic-repo に、デフォルトのロケーションを us-central1 に設定します。

    1. デフォルトのリポジトリを quickstart-generic-repo に設定するには、次のコマンドを実行します。

      gcloud config set artifacts/repository quickstart-generic-repo
      
    2. デフォルトの場所を us-central1 に設定するには、次のコマンドを実行します。

      gcloud config set artifacts/location us-central1
      

    デフォルト値を設定すると、gcloud コマンドでリポジトリまたはロケーションが必要な場合でも指定の必要はありません。

リポジトリにアーティファクトをアップロードする

  1. ホーム ディレクトリで、リポジトリにアップロードするファイルを作成します。

    echo "hello world" > hello.yaml
    
  2. ファイルをアーティファクトとしてリポジトリにアップロードするには、次のコマンドを実行します。

    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.yamlFILE_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

リポジトリを削除する

リポジトリを削除する前に、保持する必要があるパッケージが別の場所で使用可能であることを確認してください。

  1. quickstart-generic-repo リポジトリを削除するには、次のコマンドを実行します。

    gcloud artifacts repositories delete quickstart-generic-repo
    
  2. アクティブな gcloud 構成のデフォルトのリポジトリとロケーション設定を削除するには、次のコマンドを実行します。

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

次のステップ