在 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. Verify 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. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Artifact Registry API.

    Enable the API

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

    刪除專案

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    刪除存放區

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

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

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

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

    後續步驟