Artifact Registry に RPM パッケージを保存する
このクイックスタートでは、限定公開の Artifact Registry Yum リポジトリを設定し、リポジトリに RPM パッケージを追加して、CentOS 7 オペレーティング システムを実行する Compute Engine VM にパッケージをインストールする方法を示します。DNF を使用する Yum リポジトリを構成する方法については、RPM パッケージをインストールするように VM を構成するをご覧ください。
RPM パッケージの管理の詳細については、RPM パッケージの操作をご覧ください。
始める前に
- 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.
-
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
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
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
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
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. Google Cloud コンソールに移動します。
Google Cloud コンソールで、Cloud Shell をアクティブにするアイコン
をクリックします。リポジトリを作成します。
コンソール
Google Cloud コンソールで [リポジトリ] ページを開きます。
[リポジトリを作成] をクリックします。
リポジトリ名として
quickstart-yum-repoを指定します。形式として [Yum] を選択します。
[ロケーション タイプ] で、[リージョン] を選択し、ロケーション
us-west1を選択します。[作成] をクリックします。
このリポジトリがリポジトリ リストに追加されます。
gcloud
Cloud Shell で次のコマンドを実行して、ロケーション
us-west1のquickstart-yum-repoという名前の現在のプロジェクトに新しい Yum リポジトリを作成します。gcloud artifacts repositories create quickstart-yum-repo \ --repository-format=yum \ --location=us-west1 \ --description="Yum repository"次のコマンドを実行して、リポジトリが作成されたことを確認します。
gcloud artifacts repositories list
Cloud Shell で、次のコマンドを使用して nano テキスト エディタをダウンロードします。
sudo yum install --downloaddir=. --downloadonly nanoYum は、構成した 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" specifiedlsを実行して、パッケージのファイル名を取得します。ファイル名はnano-2.3.1-10.el7.x86_64.rpmのようになります。gcloudコマンドを簡素化するには、デフォルトのリポジトリをquickstart-yum-repoに、デフォルトのロケーションをus-west1に設定します。値を設定した後は、リポジトリまたはロケーションを必要とするgcloudコマンドでそれらを指定する必要はありません。リポジトリを設定するには、次のコマンドを実行します。
gcloud config set artifacts/repository quickstart-yum-repoロケーションを設定するには、次のコマンドを実行します。
gcloud config set artifacts/location us-west1これらのコマンドの詳細については、gcloud config set のドキュメントをご覧ください。
gcloud artifacts yum uploadを実行して、パッケージをリポジトリにアップロードします。gcloud artifacts yum upload quickstart-yum-repo \ --source=FILE_NAMEFILE_NAMEは、nano パッケージへのパスに置き換えます。Google Cloud コンソールで [リポジトリ] ページを開きます。
リポジトリ リストで、quickstart-yum-repo リポジトリをクリックします。
[パッケージ] ページに、リポジトリ内のパッケージが一覧表示されます。
[VM インスタンス] ページに移動します。
VM がある行で [SSH] をクリックします。VM のターミナル セッションで新しいウィンドウが開きます。
Yum を更新します。
sudo yum makecacheYum 認証ヘルパーを VM にインストールして、Yum が認証を実行できるようにするには、次のコマンドを使用します。
sudo yum install yum-plugin-artifact-registry次のコマンドを使用して、Artifact Registry パッケージにアクセスするように VM を構成します。
sudo tee -a /etc/yum.repos.d/artifact-registry.repo << EOF [yum-quickstart] name=My Repository baseurl=https://us-west1-yum.pkg.dev/projects/PROJECT/quickstart-yum-repo enabled=1 repo_gpgcheck=0 gpgcheck=0 EOFPROJECT は、実際の Google Cloudプロジェクト ID に置き換えます。
使用可能なパッケージのリストを更新するには:
sudo yum makecacheリポジトリにパッケージをインストールします。
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 コンソールで [リポジトリ] ページを開きます。
リポジトリ リストで、quickstart-yum-repo リポジトリを選択します。
[削除] をクリックします。
quickstart-yum-repoリポジトリを削除するには、次のコマンドを実行します。gcloud artifacts repositories delete quickstart-yum-repoアクティブな
gcloud構成のデフォルトのリポジトリとロケーション設定を削除するには、次のコマンドを実行します。gcloud config unset artifacts/repository gcloud config unset artifacts/location- RPM パッケージの操作について学習する。
- DevOps に関するリソースを読む。また、DORA 研究プログラムについて確認する。
Cloud Shell を起動する
Cloud Shell には、Google Cloud CLI がプリインストールされています。gcloud CLI は、 Google Cloudの主要なコマンドライン インターフェースを提供します。
Cloud Shell を起動します。
コンソールの下部にあるフレーム内で Cloud Shell セッションが開きます。このシェルを使用して gcloud コマンドを実行し、VM とリポジトリを作成します。
リポジトリを作成する
アーティファクトのリポジトリを作成します。
これで、リポジトリにパッケージを追加できるようになりました。
リポジトリにパッケージを追加する
Google Cloud CLI を使用してパッケージをリポジトリにアップロードすることも、Cloud Storage に保存されているパッケージをインポートすることもできます。Cloud Build を使用してパッケージをビルドする場合、このビルドは Cloud Storage にパッケージを保存してインポートできます。このクイックスタートでは、gcloud artifacts yum
upload コマンドを使用してサンプル ファイルをアップロードします。
リポジトリ内のパッケージを表示する
パッケージがリポジトリに追加されたことを確認します。
コンソール
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 ファイルに追加します。
パッケージをインストールする
リポジトリに追加したパッケージをインストールします。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。
リポジトリを削除する前に、保持する必要があるパッケージが別の場所で使用可能であることを確認してください。
リポジトリを削除するには、次の手順を行います。
コンソール
gcloud
作成した VM を削除するには、次のコマンドを実行します。
gcloud compute instances delete quickstart-yum-vm