Debian パッケージを管理する

このページでは、Apt リポジトリで Debian パッケージを追加、表示、削除する方法について説明します。

始める前に

  1. ターゲット Apt リポジトリが存在しない場合は、新しいリポジトリを作成します。
  2. リポジトリにアクセスできるように VM を構成します。
  3. (省略可)gcloud コマンドのデフォルトを構成します。
  4. メタデータ内のパッケージ名が Debian パッケージ名の標準を満たしているようにしてください。

パッケージの追加

リポジトリ モード: 標準

パッケージを追加するリポジトリに対する読み取りと書き込み権限が必要です。

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

非常に長いインポートまたはアップロードのオペレーションの場合は、gcloud CLI が API の呼び出しに使用するトークンの有効期限が切れる場合があります。追加するパッケージが非常に多い場合は、小さいバッチ単位で追加し、各アップロードまたはインポート オペレーションをより短時間で完了することを検討してください。 詳細については、OS パッケージのトラブルシューティングのドキュメントをご覧ください。

直接アップロード

gcloud artifacts apt upload コマンドを使用して、パッケージを Apt リポジトリにアップロードするには:

gcloud artifacts apt upload REPOSITORY \
    --location=LOCATION \
    --source=PACKAGES

次の値を置き換えます。

  • REPOSITORY は Artifact Registry のリポジトリ名です。
  • LOCATION は、リポジトリのリージョンまたはマルチリージョンのロケーションです。
  • PACKAGES はパッケージのパスです。

たとえば、パッケージ my-package.deb をロケーション us-west1 の Apt リポジトリ my-repo にアップロードするには、次を実行します。

gcloud artifacts apt upload my-repo \
    --location=us-west1 \
    --source=my-package.deb

Cloud Storage

  1. 次の手順でパッケージを Cloud Storage にアップロードします。
    • パッケージを Cloud Storage バケットに直接アップロードする
    • Cloud Build でパッケージをビルドし、バケットに保存する
  2. 次のコマンドを実行します。
    gcloud artifacts apt import REPOSITORY \
      --location=LOCATION \
      --gcs-source=PACKAGES
    

    次の値を置き換えます。

    • REPOSITORY は Artifact Registry のリポジトリ名です。
    • LOCATION は、リポジトリのリージョンまたはマルチリージョンのロケーションです。
    • PACKAGES は、Cloud Storage 内のパッケージのカンマ区切りのリストです。ディレクトリからすべてのパッケージをアップロードするには、ディレクトリ ワイルドカード(*)を使用するか、再帰ディレクトリ ワイルドカード(**)を使用してすべてのサブディレクトリですべてのパッケージをアップロードします。

    たとえば、パッケージ package.debdirectory ディレクトリ内のすべてのパッケージを、バケット my-bucket からロケーション us-west1 の Apt リポジトリ my-repo にアップロードするには、次のコマンドを実行します。

    gcloud artifacts apt import my-repo \
      --location=us-west1 \
      --gcs-source=gs://my-bucket/path/to/package.deb,gs://my-bucket/directory*
    

アップロードまたはインポートのオペレーションが完了したら、Google Cloud コンソールまたは gcloud CLI を使用して、リポジトリ内のパッケージを表示して、それらが正常にアップロードされたことを確認できます。

多数のパッケージを含む大規模なリポジトリの場合、パッケージ インデックスが再生成され、新しいパッケージが Apt クライアントに表示されるまでに数分かかることがあります。

パッケージの表示

リポジトリ モード: 標準、リモート(プレビュー)

パッケージを表示するには、Artifact Registry 読み取り者のロールの権限が必要です。Artifact Registry はパッケージ内のファイルを一覧表示しません。

To view packages and package versions using the Google Cloud console or gcloud:

Console

  1. Open the Repositories page in the Google Cloud console.

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

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Click a package to view versions of the package.

gcloud

To list packages in a repository, run the following command:

gcloud artifacts packages list [--repository=REPOSITORY] [--location=LOCATION]

Replace the following:

  • REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
  • LOCATION is the regional or multi-regional location of the repository. If you configured a default location, then you can omit this flag to use the default.

To view versions of a package, run the following command:

gcloud artifacts versions list --package=PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION]

Replace the following:

  • PACKAGE is the ID of the package or fully qualified identifier for the package.
  • REPOSITORY is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.
  • LOCATION is the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.

パッケージのインストール

リポジトリ モード: 標準、リモート(プレビュー)

パッケージをインストールする前に、パッケージ管理システムとリポジトリが正しく構成されていることを確認してください。

リポジトリにパッケージをインストールするには:

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

    sudo apt update
    
  2. Apt で構成されたリポジトリの名前を指定して、パッケージをインストールします。

    sudo apt install PACKAGE/REPOSITORY
    

    次の値を置き換えます。

    • PACKAGE はパッケージ名です
    • REPOSITORY は、Artifact Registry リポジトリの名前です。 リモート リポジトリの場合は、標準アップストリーム リポジトリの名前を使用します。

    たとえば、リポジトリ my-repo からパッケージ my-package をインストールするには、次のコマンドを実行します。

    sudo apt install my-package -t my-repo
    

パッケージの削除

リポジトリ モード: 標準

Before you delete a package or package version, verify that any you have communicated or addressed any important dependencies on it.

To delete a package:

Console

  1. Open the Repositories page in the Google Cloud console.

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

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Select the package that you want to delete.

  4. Click DELETE.

  5. In the confirmation dialog box, click DELETE.

gcloud

Run the following command:

gcloud artifacts packages delete PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION] [--async]

Replace the following:

  • PACKAGE is the name of the package in the repository.
  • REPOSITORY is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.
  • LOCATION is the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.

The --async flag causes the command to return immediately, without waiting for the operation in progress to complete.

To delete versions of a package:

Console

  1. Open the Repositories page in the Google Cloud console.

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

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Click a package to view versions of that package.

  4. Select versions that you want to delete.

  5. Click DELETE.

  6. In the confirmation dialog box, click DELETE.

gcloud

Run the following command:

gcloud artifacts versions delete VERSION \
    --package=PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION] \
    [--async]

Replace the following:

  • VERSION is the name of the version to delete.
  • PACKAGE is the name of the package in the repository.
  • REPOSITORY is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.
  • LOCATION is the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.

The --async flag causes the command to return immediately, without waiting for the operation in progress to complete.

大規模なリポジトリの場合、削除を反映して Apt パッケージ インデックスを再生成するために数分かかることがあります。

次のステップ