管理 Debian 套件

Artifact Registry 中的 Apt 存放區可讓您集中管理 Debian 套件,並在 Linux 工作負載中維持一致的軟體依附元件。您可以新增、查看及刪除套件,或將套件安裝至已設定的 VM。

事前準備

  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 上傳至位置 u-france-east1 中的 Apt 存放區 my-repo,請執行下列指令:

gcloud artifacts apt upload my-repo \
    --location=u-france-east1 \
    --source=my-package.deb

Cloud Storage

  1. 請按照下列步驟,將套件上傳至 Cloud Storage:
    • 直接將套件上傳至 Cloud Storage bucket
  2. 請執行下列指令:
    gcloud artifacts apt import REPOSITORY \
      --location=LOCATION \
      --gcs-source=PACKAGES
    

    替換下列值:

    • REPOSITORY 是 Artifact Registry 存放區名稱。
    • LOCATION 是存放區的區域位置。
    • PACKAGES 是 Cloud Storage 中以半形逗號分隔的套件清單。如要上傳目錄中的所有套件,請使用目錄萬用字元 (*),或使用遞迴目錄萬用字元 (**) 上傳所有子目錄中的所有套件。

    舉例來說,如要將套件 package.deb 和 directory 目錄中的所有套件,從 bucket my-bucket 上傳至位置 u-france-east1 的 Apt 存放區 my-repo,請執行下列指令:

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

上傳或匯入作業完成後,您可以使用Cloud de Confiance 控制台或 gcloud CLI 查看存放區中的套件,確認套件已成功上傳。

如果存放區很大,且包含許多套件,可能需要幾分鐘才能重新產生套件索引,讓 Apt 用戶端看到新套件。

查看套件

存放區模式:標準

如要查看套件,您必須具備 Artifact Registry 讀取者角色的權限。Artifact Registry 不會列出套件中的檔案。

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

Console

  1. Open the Repositories page in the Cloud de Confiance 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 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 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 Cloud de Confiance 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 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 Cloud de Confiance 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 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 套件索引,反映刪除作業。

後續步驟