在 Artifact Registry 中儲存其他格式
Artifact Registry 一般存放區可讓您儲存和版本化任意檔案、設定和自訂二進位檔,這些檔案不使用標準套件格式。在本快速入門導覽課程中,您將建立一般存放區並上傳 YAML 檔案。
事前準備
- 登入 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, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.
必要的角色
如要取得建立及管理 Artifact Registry 套件存放區所需的權限,請要求管理員授予您專案的「Artifact Registry 管理員」 (roles/artifactregistry.admin) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
啟動 Cloud Shell
在 Google Cloud 控制台中啟用 Cloud Shell。
Google Cloud 控制台底部會開啟 Cloud Shell 工作階段,並顯示指令列提示。Cloud Shell 是已安裝 Google Cloud CLI 的殼層環境,並已設定適用於您目前專案的值。工作階段可能要幾秒鐘的時間才能初始化。
在本快速入門導覽課程中,您將使用 Cloud Shell 執行 gcloud 指令。
建立一般存放區
如要在
us-central1位置建立名為quickstart-generic-repo的一般格式存放區,並將說明設為Generic repository,請執行下列指令:gcloud artifacts repositories create quickstart-generic-repo \ --repository-format=generic \ --location=us-central1 \ --description="Generic repository"執行下列指令,確認存放區已建立完成:
gcloud artifacts repositories list如要簡化
gcloud指令,請執行下列指令,將預設存放區設為quickstart-generic-repo,並將預設位置設為us-central1。如要將預設存放區設為
quickstart-generic-repo,請執行下列指令:gcloud config set artifacts/repository quickstart-generic-repo如要將預設位置設為
us-central1,請執行下列指令:gcloud config set artifacts/location us-central1
設定值後,您不需要在需要存放區或位置的
gcloud指令中指定這些值。
將構件上傳至存放區
在主目錄中,建立要上傳至存放區的檔案:
echo "hello world" > hello.yaml如要將檔案以構件形式上傳至存放區,請執行下列指令:
gcloud artifacts generic upload \ --source=hello.yaml \ --package=my-package \ --version=1.0.0其中:
hello.yaml是待上傳檔案的路徑。my-package是要上傳的套件。1.0.0是構件的版本。您無法覆寫存放區中的現有版本。
查看存放區中的構件
如要確認構件已新增至存放區,請執行下列指令,列出所有構件:
gcloud artifacts files list
回覆會以格式提供檔案詳細資料
PACKAGE:VERSION:FILE_NAME。
在以下範例中,hello.yaml 是 FILE_NAME:
FILE: my-package:1.0.0:hello.yaml
CREATE_TIME: 2023-03-09T20:55:07
UPDATE_TIME: 2023-03-09T20:55:07
SIZE (MB): 0.000
OWNER: projects/my-project/locations/us-central1/repositories/quickstart-generic-repo/packages/my-package/versions/1.0.0
下載一般構件
如要從存放區下載一般構件,請執行下列指令:
gcloud artifacts generic download \
--name=hello.yaml \
--package=my-package \
--version=1.0.0 \
--destination=DESTINATION
其中:
hello.yaml是要下載的檔案名稱。my-package是要下載的套件。1.0.0是構件版本。
將 DESTINATION 替換為本機檔案系統中要儲存下載內容的目錄。目的地資料夾必須已存在,否則指令會失敗。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本教學課程所用資源的費用,請刪除含有相關資源的專案,或者保留專案但刪除存放區。
刪除專案
刪除 Google Cloud 專案:
gcloud projects delete PROJECT_ID
刪除存放區
移除存放區之前,請先確認要保留的套件均已存放於其他位置。
如要刪除
quickstart-generic-repo存放區,請執行下列指令:gcloud artifacts repositories delete quickstart-generic-repo如要移除您為使用中的
gcloud設定建立的預設存放區和位置設定,請執行下列指令:gcloud config unset artifacts/repository gcloud config unset artifacts/location