本頁說明如何在 Apt 存放區中新增、查看及刪除 Debian 套件。
事前準備
- 如果目標 Apt 存放區不存在,請建立新的存放區。
- 設定 VM 以存取存放區。
- (選用) 設定 gcloud 指令的預設值。
- 請確認中繼資料中的套件名稱符合 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
- 請按照下列步驟,將套件上傳至 Cloud Storage:
- 上傳套件至 Cloud Storage 值區
- 使用 Cloud Build 建構套件,並將套件儲存在值區中
- 請執行下列指令:
gcloud artifacts apt import REPOSITORY \ --location=LOCATION \ --gcs-source=PACKAGES
替換下列值:
REPOSITORY是 Artifact Registry 存放區名稱。-
LOCATION是存放區的地區或多地區位置。 PACKAGES是以逗號分隔的 Cloud Storage 套件清單。如要上傳目錄中的所有套件,請使用目錄萬用字元 (*) 或遞迴目錄萬用字元 (**),上傳所有子目錄中的套件。
舉例來說,如要將套件
package.deb和directory目錄中的所有套件從值區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 不會列出套件內的檔案。
如要使用 Google Cloud 控制台或 gcloud 查看套件和套件版本,請按照下列步驟操作:
主控台
在 Google Cloud 控制台中開啟「Repositories」頁面。
在存放區清單中,按一下適當的存放區。
「Packages」頁面會列出存放區中的套件。
按一下套件即可查看套件版本。
gcloud
如要列出存放區中的套件,請執行下列指令:
gcloud artifacts packages list [--repository=REPOSITORY] [--location=LOCATION]
更改下列內容:
如要查看套件的版本,請執行下列指令:
gcloud artifacts versions list --package=PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION]
更改下列內容:
安裝套件
存放區模式:標準、遠端 (預先發布版)安裝套件前,請確認您已設定套件管理工具和存放區。
如要在存放區中安裝套件,請按照下列步驟操作:
更新可用套件清單:
sudo apt update安裝套件,指定在 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
Open the Repositories page in the Google Cloud console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Select the package that you want to delete.
Click DELETE.
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:
PACKAGEis the name of the package in the repository.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis 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
Open the Repositories page in the Google Cloud console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Click a package to view versions of that package.
Select versions that you want to delete.
Click DELETE.
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:
VERSIONis the name of the version to delete.PACKAGEis the name of the package in the repository.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis 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 套件索引以反映刪除作業可能需要幾分鐘的時間。