RPM パッケージを Artifact Registry に保存する

このクイックスタートでは、プライベート Artifact Registry Yum リポジトリを設定し、リポジトリに RPM パッケージを追加して、CentOS 7 オペレーティング システムを実行している Compute Engine VM にパッケージをインストールする方法について説明します。DNF を使用する Yum リポジトリを構成する方法については、RPM パッケージをインストールするように VM を構成するをご覧ください。

このクイックスタートの手順は、Cloud Shell とこのクイックスタートで作成した VM のシェルを使用して行います。

RPM パッケージの管理の詳細については、RPM パッケージの操作をご覧ください。

始める前に

  1. 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.
  2. Google Cloud Console の [プロジェクト セレクタ] ページで、Google Cloud プロジェクトを選択または作成します。

    プロジェクト セレクタに移動

  3. Google Cloud プロジェクトで課金が有効になっていることを確認します

  4. Artifact Registry API を有効にします。

    API を有効にする

  5. Google Cloud Console の [プロジェクト セレクタ] ページで、Google Cloud プロジェクトを選択または作成します。

    プロジェクト セレクタに移動

  6. Google Cloud プロジェクトで課金が有効になっていることを確認します

  7. Artifact Registry API を有効にします。

    API を有効にする

Cloud Shell を起動する

Cloud Shell には、Google Cloud CLI がプリインストールされています。gcloud CLI は、Google Cloud への主要なコマンドライン インターフェースを提供します。

Cloud Shell を起動します。

  1. Google Cloud Console に移動します。

    Google Cloud Console

  2. Google Cloud コンソールのツールバーで、「Cloud Shell をアクティブにする」をクリックします:

コンソールの下部にあるフレーム内で Cloud Shell セッションが開きます。このシェルで gcloud コマンドを実行して、VM とリポジトリを作成します。

リポジトリを作成する

アーティファクトのリポジトリを作成します。

  1. リポジトリを作成します。

    コンソール

    1. Google Cloud コンソールで [リポジトリ] ページを開きます。

      [リポジトリ] ページを開く

    2. [リポジトリを作成] をクリックします。

    3. リポジトリ名として quickstart-yum-repo を指定します。

    4. 形式として [Yum] を選択します。

    5. [ロケーション タイプ] で、[リージョン] を選択し、ロケーション us-central1 を選択します。

    6. [作成] をクリックします。

    このリポジトリがリポジトリ リストに追加されます。

    gcloud

    1. Cloud Shell で次のコマンドを実行して、ロケーション us-central1 にある quickstart-yum-repo という現在のプロジェクトに新しい Yum リポジトリを作成します。

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

      gcloud artifacts repositories list
      

これで、リポジトリにパッケージを追加できるようになりました。

パッケージをリポジトリに追加する

Google Cloud CLI を使用してパッケージをリポジトリにアップロードすることも、Cloud Storage に保存されているパッケージをインポートすることもできます。Cloud Build を使用してパッケージをビルドする場合、このビルドは Cloud Storage にパッケージを保存してインポートできます。

このクイックスタートでは、gcloud artifacts yum upload コマンドを使用してサンプル ファイルをアップロードします。

  1. Cloud Shell で、次のコマンドを使用して nano テキスト エディタをダウンロードします。

    sudo yum install --downloaddir=. --downloadonly nano
    

    Yum により、構成済みの CentOS リポジトリから入手可能な最新バージョンのパッケージがダウンロードされます。

    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirror.dal.nexril.net
     * epel: ord.mirror.rackspace.com
     * extras: centos.mirror.lstn.net
     * updates: ftpmirror.your.org
    Resolving Dependencies
    --> Running transaction check
    ---> Package nano.x86_64 0:2.3.1-10.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package        Arch             Version                   Repository      Size
    ================================================================================
    Installing:
     nano           x86_64           2.3.1-10.el7              base           440 k
    
    Transaction Summary
    ================================================================================
    Install  1 Package
    
    Total download size: 440 k
    Installed size: 1.6 M
    Background downloading packages, then exiting:
    nano-2.3.1-10.el7.x86_64.rpm                               | 440 kB   00:00
    exiting because "Download Only" specified
    

    ls を実行してパッケージのファイル名を取得します。ファイル名は nano-2.3.1-10.el7.x86_64.rpm のようになります。

  2. gcloud コマンドを簡素化するには、デフォルトのリポジトリを quickstart-yum-repo に、デフォルトのロケーションを us-central1 に設定します。値を設定した後は、リポジトリまたはロケーションを必要とする gcloud コマンドでそれらを指定する必要はありません。

    リポジトリを設定するには、次のコマンドを実行します。

    gcloud config set artifacts/repository quickstart-yum-repo
    

    ロケーションを設定するには、次のコマンドを実行します。

    gcloud config set artifacts/location us-central1
    

    これらのコマンドの詳細については、gcloud config set のドキュメントをご覧ください。

  3. gcloud artifacts yum upload を実行してパッケージをリポジトリにアップロードします。

    gcloud artifacts yum upload quickstart-yum-repo \
        --source=FILE_NAME
    

    FILE_NAME は、nano パッケージへのパスに置き換えます。

リポジトリ内のパッケージを表示する

パッケージがリポジトリに追加されたことを確認します。

コンソール

  1. Google Cloud コンソールで [リポジトリ] ページを開きます。

    [リポジトリ] ページを開く

  2. リポジトリ リストで、[quickstart-yum-repo] リポジトリをクリックします。

    [パッケージ] ページには、リポジトリ内のパッケージが一覧表示されます。

gcloud

quickstart-yum-repo リポジトリ内のパッケージを一覧表示するには、次のコマンドを実行します。

 gcloud artifacts packages list

パッケージのバージョンを quickstart-yum-repo に表示するには、次のコマンドを実行します。

gcloud artifacts versions list --package=nano

VM を作成する

サンプル パッケージをインストールする新しい Compute Engine VM を作成します。

Cloud Shell で次のコマンドを実行して、quickstart-yum-vm という名前の VM インスタンスを作成します。

gcloud compute instances create quickstart-yum-vm \
    --image-family=centos-7 \
    --image-project=centos-cloud \
    --scopes=cloud-platform

デフォルトでは、VM にはリポジトリの操作に必要なアクセス スコープがありません。--scopes フラグによって、VM のアクセス スコープが cloud-platform に設定されます。

パッケージ マネージャーを構成する

VM にパッケージをインストールするには、作成したリポジトリをパッケージ リポジトリを定義する Yum ファイルに追加します。

  1. [VM インスタンス] ページに移動します。

    [VM インスタンス] ページを開く

  2. VM がある行で [SSH] をクリックします。VM のターミナル セッションで新しいウィンドウが開きます。

  3. Yum を更新します。

    sudo yum makecache
    
  4. Yum 認証ヘルパーを VM にインストールして、Yum が認証を実行できるようにするには、次のコマンドを使用します。

    sudo yum install yum-plugin-artifact-registry
    
  5. 次のコマンドを使用して、Artifact Registry パッケージにアクセスするように VM を構成します。

    sudo tee -a /etc/yum.repos.d/artifact-registry.repo << EOF
    [yum-quickstart]
    name=My Repository
    baseurl=https://us-central1-yum.pkg.dev/projects/PROJECT/quickstart-yum-repo
    enabled=1
    repo_gpgcheck=0
    gpgcheck=0
    EOF
    

    PROJECT は、実際の Google Cloud プロジェクト ID に置き換えます。

パッケージをインストールする

リポジトリに追加したパッケージをインストールします。

  1. 使用可能なパッケージのリストを更新するには:

    sudo yum makecache
    
  2. リポジトリにパッケージをインストールします。

    sudo yum --enablerepo=yum-quickstart install nano
    

    プロンプトが表示されたら、「y」と入力します。

    返されるインストール情報は、次の例のようになります。

    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.cmich.edu
     * epel: ord.mirror.rackspace.com
     * extras: mirror.team-cymru.com
     * updates: mirror.us-midwest-1.nexcess.net
    quickstart-yum-repo                                      | 1.3 kB     00:00
    Resolving Dependencies
    --> Running transaction check
    ---> Package nano.x86_64 0:2.3.1-10.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package        Arch             Version                   Repository      Size
    ================================================================================
    Installing:
     nano           x86_64           2.3.1-10.el7              base           440 k
    
    Transaction Summary
    ================================================================================
    Install  1 Package
    
    Total size: 440 k
    Installed size: 1.6 M
    Is this ok [y/d/N]: y
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : nano-2.3.1-10.el7.x86_64                                     1/1
      Verifying  : nano-2.3.1-10.el7.x86_64                                     1/1
    
    Installed:
      nano.x86_64 0:2.3.1-10.el7
    
    Complete!
    

クリーンアップ

このページで使用したリソースについて、Google Cloud アカウントに課金されないようにするには、次の手順を行います。

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

リポジトリを削除するには、次の手順を行います。

コンソール

  1. Google Cloud コンソールで [リポジトリ] ページを開きます。

    [リポジトリ] ページを開く

  2. リポジトリ リストで、[quickstart-yum-repo] リポジトリを選択します。

  3. [削除] をクリックします。

gcloud

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

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

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

作成した VM を削除するには、次のコマンドを実行します。

gcloud compute instances delete quickstart-yum-vm

次のステップ