將其他格式儲存在 Artifact Registry 中

瞭解如何設定 Artifact Registry 通用格式存放區,以及上傳 YAML 檔案。

事前準備

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Artifact Registry API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Artifact Registry API.

    Enable the API

啟動 Cloud Shell

In the Google Cloud console, activate Cloud Shell.

Activate Cloud Shell

At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

在本快速入門課程中,您將使用 Cloud Shell 執行 gcloud 指令。

建立一般存放區

  1. 如要在 us-central1 位置建立名為 quickstart-generic-repo 的通用格式存放區,並附上說明 Generic repository,請執行下列指令:

    gcloud artifacts repositories create quickstart-generic-repo \
        --repository-format=generic \
        --location=us-central1 \
        --description="Generic repository"
    
  2. 如要確認存放區是否已建立完成,請執行下列指令:

    gcloud artifacts repositories list
    
  3. 如要簡化 gcloud 指令,請執行下列指令,將預設存放區設為 quickstart-generic-repo,並將預設位置設為 us-central1

    1. 如要將預設存放區設為 quickstart-generic-repo,請執行下列指令:

      gcloud config set artifacts/repository quickstart-generic-repo
      
    2. 如要將預設位置設為 us-central1,請執行下列指令:

      gcloud config set artifacts/location us-central1
      

    設定值後,您不需要在需要存放區或位置的 gcloud 指令中指定這些值。

將構件上傳至存放區

  1. 在主目錄中建立要上傳至存放區的檔案:

    echo "hello world" > hello.yaml
    
  2. 如要將檔案上傳至存放區做為構件,請執行下列指令:

    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.yamlFILE_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 帳戶收取本教學課程所用資源的費用,請刪除含有相關資源的專案,或者保留專案但刪除存放區。

刪除專案

    Delete a Google Cloud project:

    gcloud projects delete PROJECT_ID

刪除存放區

移除存放區之前,請先確認要保留的套件均已存放於其他位置。

  1. 如要刪除 quickstart-generic-repo 存放區,請執行下列指令:

    gcloud artifacts repositories delete quickstart-generic-repo
    
  2. 如要移除您為使用中的 gcloud 設定建立的預設存放區和位置設定,請執行下列指令:

    gcloud config unset artifacts/repository
    gcloud config unset artifacts/location
    

後續步驟