Apt パッケージを Artifact Registry に保存する
このクイックスタートでは、限定公開の Artifact Registry Apt リポジトリを設定し、リポジトリに Debian パッケージを追加して、Debian ベースのオペレーティング システムを実行する Compute Engine VM にパッケージをインストールする方法を示します。
Debian パッケージの管理の詳細については、Debian パッケージの操作をご覧ください。
始める前に
- 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 role
(
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 role
(
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-apt-repoを指定します。形式として [Apt] を選択します。
[ロケーション タイプ] で、[リージョン] を選択し、ロケーション
us-west1を選択します。[作成] をクリックします。
このリポジトリがリポジトリ リストに追加されます。
gcloud
Cloud Shell で次のコマンドを実行して、ロケーション
us-west1のquickstart-apt-repoという名前の現在のプロジェクトに新しい Apt リポジトリを作成します。gcloud artifacts repositories create quickstart-apt-repo \ --repository-format=apt \ --location=us-west1 \ --description="Apt repository"次のコマンドを実行して、リポジトリが作成されたことを確認します。
gcloud artifacts repositories list
[VM インスタンス] ページに移動します。
VM がある行で [SSH] をクリックします。VM のターミナル セッションで新しいウィンドウが開きます。
gcloud initを実行して、VM で Google Cloud CLI を初期化します。Apt を更新するには:
sudo apt update次のコマンドを使用して curl パッケージをダウンロードします。
apt download curlApt は、構成した Apt リポジトリから入手可能な最新バージョンのパッケージをダウンロードします。
Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B] Get:2 https://deb.debian.org/debian bookworm/main amd64 curl amd64 7.88.1-10+deb12u14 [316 kB] Fetched 316 kB in 0s (3078 kB/s)lsを実行して、curl パッケージのファイル名を取得します。ファイル名はcurl_7.88.1-10+deb12u14_amd64.debのようになります。gcloudコマンドを簡素化するには、デフォルトのリポジトリをquickstart-apt-repoに、デフォルトのロケーションをus-west1に設定します。デフォルト値を設定すると、gcloudコマンドでリポジトリまたはロケーションが必要な場合でも指定の必要はありません。リポジトリを設定するには、次のコマンドを実行します。
gcloud config set artifacts/repository quickstart-apt-repoロケーションを設定するには、次のコマンドを実行します。
gcloud config set artifacts/location us-west1これらのコマンドの詳細については、gcloud config set のドキュメントをご覧ください。
gcloud artifacts apt uploadを実行して、パッケージをリポジトリにアップロードします。gcloud artifacts apt upload quickstart-apt-repo \ --source=FILE_NAMEFILE_NAMEは、curl パッケージのパスに置き換えます。Google Cloud コンソールで [リポジトリ] ページを開きます。
リポジトリ リストで、quickstart-apt-repo リポジトリをクリックします。
[パッケージ] ページに、リポジトリ内のパッケージが一覧表示されます。
VM に Apt 認証ヘルパーをインストールして、Apt が認証を実行できるようにします。
sudo apt install apt-transport-artifact-registryArtifact Registry パッケージにアクセスするように VM を構成します。
echo 'deb ar+https://us-west1-apt.pkg.dev/projects/PROJECT quickstart-apt-repo main' | sudo tee -a /etc/apt/sources.list.d/artifact-registry.listPROJECT は、実際の Google Cloudプロジェクト ID に置き換えます。
使用可能なパッケージのリストを更新するには:
sudo apt updateリポジトリからパッケージをインストールします。
sudo apt install curl/quickstart-apt-repo返されるインストール情報は、次の例のようになります。
Reading package lists... Done Building dependency tree... Done Reading state information... Done Selected version '7.88.1-10+deb12u14' (quickstart-apt-repo:quickstart-apt-repo, Debian:12.12/oldstable [amd64]) for 'curl' The following additional packages will be installed: libcurl3-gnutls libcurl4 The following packages will be upgraded: curl libcurl3-gnutls libcurl4 3 upgraded, 0 newly installed, 0 to remove and 77 not upgraded. Need to get 1093 kB of archives. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B] Get:2 https://deb.debian.org/debian bookworm/main amd64 libcurl4 amd64 7.88.1-10+deb12u14 [392 kB] Get:3 https://deb.debian.org/debian bookworm/main amd64 libcurl3-gnutls amd64 7.88.1-10+deb12u14 [386 kB] Get:4 ar+https://us-west1-apt.pkg.dev/projects/PROJECT quickstart-apt-repo/main amd64 curl amd64 7.88.1-10+deb12u14 [316 kB] Fetched 1093 kB in 1s (947 kB/s) Reading changelogs... Done (Reading database ... 72080 files and directories currently installed.) Preparing to unpack .../curl_7.88.1-10+deb12u14_amd64.deb ... Unpacking curl (7.88.1-10+deb12u14) over (7.88.1-10+deb12u12) ... Preparing to unpack .../libcurl4_7.88.1-10+deb12u14_amd64.deb ... Unpacking libcurl4:amd64 (7.88.1-10+deb12u14) over (7.88.1-10+deb12u12) ... Preparing to unpack .../libcurl3-gnutls_7.88.1-10+deb12u14_amd64.deb ... Unpacking libcurl3-gnutls:amd64 (7.88.1-10+deb12u14) over (7.88.1-10+deb12u12) ... Setting up libcurl3-gnutls:amd64 (7.88.1-10+deb12u14) ... Setting up libcurl4:amd64 (7.88.1-10+deb12u14) ... Setting up curl (7.88.1-10+deb12u14) ... Processing triggers for man-db (2.11.2-2) ... Processing triggers for libc-bin (2.36-9+deb12u10) ...
Google Cloud コンソールで [リポジトリ] ページを開きます。
リポジトリ リストで、quickstart-apt-repo リポジトリを選択します。
[削除] をクリックします。
quickstart-apt-repoリポジトリを削除するには、次のコマンドを実行します。gcloud artifacts repositories delete quickstart-apt-repoアクティブな
gcloud構成のデフォルトのリポジトリとロケーション設定を削除するには、次のコマンドを実行します。gcloud config unset artifacts/repository gcloud config unset artifacts/location- Deb パッケージの操作について学習する。
- DevOps に関するリソースを読む。また、DORA 研究プログラムについて確認する。
Cloud Shell を起動する
Cloud Shell には、Google Cloud CLI がプリインストールされています。gcloud CLI は、 Google Cloudの主要なコマンドライン インターフェースを提供します。
Cloud Shell を起動します。
コンソールの下部にあるフレーム内で Cloud Shell セッションが開きます。このシェルを使用して gcloud コマンドを実行し、VM とリポジトリを作成します。
リポジトリを作成する
アーティファクトのリポジトリを作成します。
これで、リポジトリにパッケージを追加できるようになりました。Cloud Shell は、Debian ではなく Google がビルドした Ubuntu イメージを使用します。リポジトリ内の Debian パッケージを管理するには、Debian OS イメージを使用する VM を使用します。
VM を作成する
サンプル パッケージをインストールする新しい Compute Engine VM を作成します。
Cloud Shell で次のコマンドを実行して、quickstart-apt-vm という名前の VM インスタンスを作成します。
gcloud compute instances create quickstart-apt-vm \
--image-family=debian-12 \
--image-project=debian-cloud \
--scopes=cloud-platform
デフォルトでは、VM にはリポジトリの操作に必要なアクセス スコープがありません。--scopes フラグを使用して、VM のアクセス スコープを cloud-platform に設定します。
リポジトリにパッケージを追加する
Google Cloud CLI を使用してパッケージをリポジトリにアップロードすることも、Cloud Storage に保存されているパッケージをインポートすることもできます。Cloud Build を使用してパッケージをビルドする場合、このビルドは Cloud Storage にパッケージを保存してインポートできます。このクイックスタートでは、gcloud artifacts apt upload コマンドを使用してサンプル ファイルをアップロードします。
リポジトリ内のパッケージを表示する
パッケージがリポジトリに追加されたことを確認します。
コンソール
gcloud
quickstart-apt-repo リポジトリ内のパッケージを一覧表示するには、次のコマンドを実行します。
gcloud artifacts packages list
パッケージのバージョンを quickstart-apt-repo に表示するには、次のコマンドを実行します。
gcloud artifacts versions list --package=apt-dpkg-ref
パッケージ管理システムを構成する
VM にパッケージをインストールするには、作成したリポジトリを、パッケージ リポジトリを定義する Apt 構成ファイルに追加します。
パッケージをインストールする
リポジトリに追加したパッケージをインストールします。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。
リポジトリを削除する前に、保持する必要があるパッケージが別の場所で使用可能であることを確認してください。
リポジトリを削除するには、次の手順を行います。
コンソール
gcloud
作成した VM を削除するには、次のコマンドを実行します。
gcloud compute instances delete quickstart-apt-vm