在私人集區中建立及執行建構作業

本頁說明如何建立連線至服務生產端網路的 Cloud Build 私人集區,並在私人集區中執行建構作業。

服務供應商網路是代管私人集區的網路。根據預設,私人集區會設定為使用服務供應商網路,為建構環境提供下列項目:

  • 可設定的機器類型
  • 可設定的磁碟大小
  • 存取公開網際網路中的資源,例如存放區或註冊資料庫中的資源

如要直接在 Cloud Shell 編輯器中按照逐步指南操作,請按一下「Guide me」(逐步引導)

逐步引導


事前準備

  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 Cloud Build API.

    Enable the API

  5. Install the Google Cloud CLI.

  6. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

  7. 如要初始化 gcloud CLI,請執行下列指令:

    gcloud init
  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Cloud Build API.

    Enable the API

  11. Install the Google Cloud CLI.

  12. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

  13. 如要初始化 gcloud CLI,請執行下列指令:

    gcloud init
  14. 建立私人集區

    1. 在 Google Cloud 控制台中,開啟「Cloud Build Worker pool」(Cloud Build 工作站集區) 分頁:

      開啟 Cloud Build 工作站集區分頁

    2. 按一下「Create」(建立)

    3. 在「Create private pool」(建立私人集區) 面板中輸入下列設定:

      1. 「Name」(名稱) 欄位中輸入 my-first-privatepool

      2. 「Region」(區域) 欄位中選取「us-central1」。

      3. 「Machine type」(機器類型) 欄位中選取「e2-standard-2」。

      4. 「Available disk size」(可用磁碟大小) 欄位中輸入 800

      5. 「Network project number」(網路專案編號) 欄位留空。

      6. 「Network」(網路) 欄位留空。

      7. 確認已選取「Assign external IPs」(指派外部 IP)

    按一下「Create」(建立) 來建立私人集區。

    建立私人集區會花費一些時間。私人集區建立完成後,就會列在「Worker pool」(工作站集區) 分頁中。

    私人集區頁面的螢幕截圖

    在私人集區中執行建構作業

    1. 開啟終端機視窗。

    2. 建立名為 quickstart-private-pool 的新目錄,然後前往該目錄:

      mkdir quickstart-private-pool
      cd quickstart-private-pool
      
    3. 建立名為 cloudbuild.yaml 的檔案,並在當中加入下列內容:

      steps:
      - name: "bash"
        script: echo "I am running in a private pool!"
      options:
        pool:
          name: "projects/$PROJECT_ID/locations/us-central1/workerPools/my-first-privatepool"
      
    4. 使用建構設定檔展開建構作業:

      gcloud builds submit
      

    建構完成時,畫面會顯示類似以下的輸出:

    I am running in a private pool!
    PUSH
    DONE
    ------------------------------------------------------------------------------------------------------------------------------------     ------------------------------------------------------------------------
    
    ID                                    CREATE_TIME                DURATION  SOURCE                                                                                       IMAGES  STATUS
    5df45735-6414-40b7-9e10-e6d2023c8cea  2020-08-31T13:16:18+00:00  10S       gs://private-pool-test_cloudbuild/source/1598879777.206444-    58901ecbd14e431f8cdacc85d5dd0fc3.tgz  -       SUCCESS
    

    查看建構作業詳細資料

    1. 在 Google Cloud 控制台中開啟「建構記錄」頁面。

      開啟 Cloud Build 頁面

    2. 「Region」(區域) 下拉式方塊中選取「us-central1」

      畫面會顯示您在私人集區中執行的建構作業。
    3. 按一下建構作業即可查看建構作業詳細資料,例如建構作業摘要及構件。

    4. 清除所用資源

      如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。

      1. 在 Google Cloud 控制台中開啟「Worker pool」(工作站集區) 頁面:

        開啟 Cloud Build 私人集區頁面

      2. 在您的私人集區那一列中,點選「垃圾桶」圖示。

      3. 在「Delete private pool?」(要刪除私人集區嗎?) 彈出式方塊中點選「Delete」(刪除)

      您在本快速入門導覽課程中建立的私人集區現在已刪除。如果無法透過「Worker pool」(工作站集區) 頁面刪除私人集區,您可能必須重新整理畫面。

      後續步驟