Apt パッケージを Artifact Registry に保存する
このクイックスタートでは、限定公開の Artifact Registry Apt リポジトリを設定し、リポジトリに Debian パッケージを追加して、Debian ベースのオペレーティング システムを実行する Compute Engine VM にパッケージをインストールする方法を示します。
Debian パッケージの管理の詳細については、Debian パッケージを操作するをご覧ください。
始める前に
- アカウントにログインします。 Google Cloud を初めて使用する場合は、 アカウントを作成して、 実際のシナリオでプロダクトがどのように機能するかを評価してください。 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 Apt パッケージ リポジトリの作成と管理に必要な権限を取得するには、プロジェクトに対する次の IAM ロールの付与を管理者に依頼してください。
-
Artifact Registry 管理者 (
roles/artifactregistry.admin) -
Compute Engine で仮想マシン(VM)を作成する:
Compute インスタンス管理者(v1) (
roles/compute.instanceAdmin.v1)
ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。
Cloud Shell を起動する
Cloud Shell には、 Google Cloud CLI がプリインストールされています。gcloud CLI は、 Google Cloudの主要なコマンドライン インターフェースを提供します。
Cloud Shell を起動します。
コンソールに移動します。 Google Cloud
コンソールで、[Cloud Shell をアクティブにする]
をクリックします。 Google Cloud
コンソールの下部にあるフレーム内で Cloud Shell セッションが開きます。
このシェルを使用して、gcloud コマンドを実行して VM とリポジトリを作成します。
リポジトリを作成する
アーティファクトのリポジトリを作成します。
リポジトリを作成します。
コンソール
[リポジトリ] ページを Google Cloud コンソールで開きます。
[リポジトリを作成] をクリックします。
リポジトリ名として
quickstart-apt-repoを指定します。フォーマットとして [Apt] を選択します。
[ロケーション タイプ] で、[リージョン] を選択し、ロケーション
us-west1を選択します。[作成] をクリックします。
このリポジトリがリポジトリ リストに追加されます。
gcloud
Cloud Shell で次のコマンドを実行して、現在のプロジェクトに新しい Apt リポジトリを
quickstart-apt-repoという名前でロケーションus-west1に作成します。gcloud artifacts repositories create quickstart-apt-repo \ --repository-format=apt \ --location=us-west1 \ --description="Apt repository"次のコマンドを実行して、リポジトリが作成されたことを確認します。
gcloud artifacts repositories list
これで、リポジトリにパッケージを追加できます。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 に設定します。
[VM インスタンス] ページに移動します。
VM がある行で [SSH] をクリックします。VM のターミナル セッションで新しいウィンドウが開きます。
リポジトリにパッケージを追加する
Google Cloud CLI を使用してパッケージをリポジトリにアップロードすることも、Cloud Storage に保存されているパッケージをインポートすることもできます。Cloud Build を使用してパッケージをビルドする場合、このビルドは Cloud Storage にパッケージを保存してインポートできます。このクイックスタートでは、gcloud artifacts apt upload コマンドを使用してサンプル ファイルをアップロードします。
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 リポジトリをクリックします。
[パッケージ] ページに、リポジトリ内のパッケージが一覧表示されます。
gcloud
quickstart-apt-repo リポジトリ内のパッケージを一覧表示するには、次のコマンドを実行します。
gcloud artifacts packages list
quickstart-apt-repo のパッケージのバージョンを表示するには、次のコマンドを実行します。
gcloud artifacts versions list --package=apt-dpkg-ref
パッケージ管理システムを構成する
VM にパッケージをインストールするには、作成したリポジトリを、パッケージ リポジトリを定義する Apt 構成ファイルに追加します。
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 アカウントに課金されないようにするには、 次の手順を実施します。
リポジトリを削除する前に、保持する必要があるパッケージが別の場所で使用可能であることを確認してください。
リポジトリを削除するには、次の手順を行います。
コンソール
[リポジトリ] ページを Google Cloud コンソールで開きます。
リポジトリ リストで、quickstart-apt-repo リポジトリを選択します。
[削除] をクリックします。
gcloud
quickstart-apt-repoリポジトリを削除するには、次のコマンドを実行します。gcloud artifacts repositories delete quickstart-apt-repoアクティブな
gcloud構成のデフォルトのリポジトリとロケーション設定を削除するには、次のコマンドを実行します。gcloud config unset artifacts/repository gcloud config unset artifacts/location
作成した VM を削除するには、次のコマンドを実行します。
gcloud compute instances delete quickstart-apt-vm
次のステップ
- Deb パッケージの操作について学習する。
- DevOps に関するリソースを読む。また、DORA 研究プログラムについて確認する。