Apt パッケージを Artifact Registry に保存する
このクイックスタートでは、限定公開の Artifact Registry Apt リポジトリを設定し、リポジトリに Debian パッケージを追加して、Debian ベースのオペレーティング システムを実行する Compute Engine VM にパッケージをインストールする方法を示します。
Debian パッケージの管理の詳細については、Debian パッケージを操作するをご覧ください。
始める前に
-
In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance 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 Cloud de Confiance 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)
ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。
gcloud CLI をインストールする
Google Cloud CLI がまだインストールされていない場合は、インストールして初期化します。既存のインストール環境の場合は、 コマンドを使用して Google Cloud CLI のコンポーネントを更新します。
gcloud components updategcloud CLI のバージョンを確認するには、次のコマンドを実行します。
gcloud version
リポジトリを作成する
アーティファクトのリポジトリを作成します。
リポジトリを作成します。
コンソール
コンソールで [**リポジトリ**] ページを開きます。 Cloud de Confiance
[リポジトリを作成] をクリックします。
リポジトリ名として
quickstart-apt-repoを指定します。形式として [Apt] を選択します。
[ロケーション タイプ] で、[リージョン] を選択し、ロケーション
u-france-east1を選択します。[作成] をクリックします。
このリポジトリがリポジトリ リストに追加されます。
gcloud
Cloud Shell で次のコマンドを実行して、現在のプロジェクトに新しい Apt リポジトリを
quickstart-apt-repoという名前でロケーションu-france-east1に作成します。gcloud artifacts repositories create quickstart-apt-repo \ --repository-format=apt \ --location=u-france-east1 \ --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 に保存されているパッケージをインポートすることもできます。このクイックスタートでは、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に、デフォルトのロケーションをu-france-east1に設定します。デフォルト値を設定すると、gcloudコマンドでリポジトリまたはロケーションが必要な場合でも指定の必要はありません。リポジトリを設定するには、次のコマンドを実行します。
gcloud config set artifacts/repository quickstart-apt-repoロケーションを設定するには、次のコマンドを実行します。
gcloud config set artifacts/location u-france-east1これらのコマンドの詳細については、gcloud config set のドキュメントをご覧ください。
gcloud artifacts apt uploadを実行して、パッケージをリポジトリにアップロードします。gcloud artifacts apt upload quickstart-apt-repo \ --source=FILE_NAMEFILE_NAMEは、curl パッケージのパスに置き換えます。
リポジトリ内のパッケージを表示する
パッケージがリポジトリに追加されたことを確認します。
コンソール
コンソールで [**リポジトリ**] ページを開きます。 Cloud de Confiance
リポジトリ リストで、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://u-france-east1-apt.s3nsregistry.fr/projects/PROJECT quickstart-apt-repo main' | sudo tee -a /etc/apt/sources.list.d/artifact-registry.listPROJECT は、実際の Cloud de Confiance by S3NSプロジェクト 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://u-france-east1-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) ...
クリーンアップ
このページで使用したリソースについて、 Cloud de Confiance アカウントに課金されないようにするには、 次の手順を実施します。
リポジトリを削除する前に、保持する必要があるパッケージが別の場所で使用可能であることを確認してください。
リポジトリを削除するには、次の手順を行います。
コンソール
コンソールで [**リポジトリ**] ページを開きます。 Cloud de Confiance
リポジトリ リストで、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 研究プログラムについて確認する。