使用 App Lifecycle Manager 部署應用程式

App Lifecycle Manager 可自動部署及管理多元件應用程式的生命週期,協助您在 Google Cloud中佈建一致的環境。在本快速入門導覽課程中,您會在 Application Design Center 中使用 Cloud Run 和 Cloud Storage 建立複合應用程式範本模型,然後佈建實際運作的單元。

事前準備

  1. 登入 Google 帳戶。

    如果還沒有帳戶,請 申請新帳戶。

  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

  4. Enable the App Lifecycle Manager, Artifact Registry, Cloud Build, Cloud Run, Cloud Storage, Developer Connect, Infrastructure Manager, App Design Center, App Hub, Resource Manager, Identity and Access Management, Cloud Asset Inventory, Cloud Monitoring, Cloud Logging, and Service Health APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the APIs

  5. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    5. Click Create and continue.
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    7. Click Continue.
    8. Click Done to finish creating the service account.

  6. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

  8. Enable the App Lifecycle Manager, Artifact Registry, Cloud Build, Cloud Run, Cloud Storage, Developer Connect, Infrastructure Manager, App Design Center, App Hub, Resource Manager, Identity and Access Management, Cloud Asset Inventory, Cloud Monitoring, Cloud Logging, and Service Health APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the APIs

  9. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    5. Click Create and continue.
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    7. Click Continue.
    8. Click Done to finish creating the service account.

  10. 將必要權限授予 App Lifecycle Manager 服務帳戶:
    1. 在 Google Cloud 控制台中,依序前往「App Lifecycle Manager」 >「Overview」(總覽) >「Get started」(開始使用)。

      前往「開始使用 App Lifecycle Manager」

    2. 如果出現橫幅,顯示「The required permissions for App Lifecycle Manager account haven't been granted」(尚未授予 App Lifecycle Manager 帳戶必要權限) 訊息,請按一下「Grant permissions」(授予權限)。

使用複合範本建立產品模型

使用 App Lifecycle Manager 和 Application Design Center 建立複合範本 (run-storage-quickstart) 模型,將 Cloud Run 服務連結至 Cloud Storage bucket。

設定 SaaS 產品

  1. 在 Google Cloud 控制台中,依序前往「App Lifecycle Manager」 >「SaaS offering」。

    前往 SaaS 產品

  2. 點選「建立」。

  3. 在「SaaS offering name」(SaaS 產品名稱) 欄位中,輸入 run-storage-quickstart-offering。

  4. 在「Region」(區域) 清單中選取下列區域,然後按一下「OK」(確定):

    • us-central1
    • us-east1
    • us-east5
  5. 點選「建立」。建立 run-storage-quickstart-offering 需要幾分鐘的時間。

    SaaS 產品建立完成後,「SaaS offering details」(SaaS 產品詳細資料) 頁面會隨即開啟。

建立複合範本

  1. 在「SaaS offering details」(SaaS 產品詳細資料) 頁面,按一下「Create new template」(建立新範本)。
  2. 在「Create a new composite template」(建立新的複合範本) 頁面中,設定範本:

    1. 在「Template ID」(範本 ID) 欄位輸入 run-storage-quickstart。
    2. 點選「Create template」(建立範本)。

      App Lifecycle Manager 建立複合範本後,其詳細資料會顯示在「SaaS 產品詳細資料」頁面的「連結的應用程式範本」部分。

  3. 在「Connected application template」(連結的應用程式範本) 部分,依序點選「Manage template」(管理範本) 和「Configure in canvas」(在畫布中設定)。

    App Design Center 會在 Google Cloud 控制台中開啟。

  4. 在「Components」(元件) 區塊,將下列元件新增至設計畫布:

    1. 按一下「Cloud Run (Service)」,將 cloud-run-1 元件新增至畫布。
    2. 按一下「Cloud Storage」,將 cloud-storage-1 元件新增至畫布。
  5. 在畫布上,從「cloud-run-1」元件拖曳至「cloud-storage-1」元件,建立連線。

    連結元件後,Cloud Run 服務帳戶會傳遞至 Cloud Storage bucket 的 IAM 繫結,並具備 roles/storage.objectAdmin 角色。

  6. 在畫布上,按一下「cloud-run-1」元件,開啟「Configuration」(設定) 面板:

    1. 在「容器」區域中,展開「容器 1」。
    2. 在「Container Image」(容器映像檔) 欄位中,輸入公開範例容器映像檔 us-docker.pkg.dev/cloudrun/container/hello:latest。
    3. 按一下「儲存」。
  7. 依序點選「繼續」 >「透過 App Lifecycle Manager 大規模部署」。

    App Lifecycle Manager 會在 Google Cloud 控制台中開啟。

  8. 在「Connected application template」(連結的應用程式範本) 區段中,按一下「Update template revision」(更新範本修訂版本)。

  9. 在「Update template revision」(更新範本修訂版本) 頁面中,選取「Revision」(修訂版本) 清單中的 r-2,然後按一下「Update」(更新)。

    「Connected application template」(已連結的應用程式範本) 區段會顯示「Importing Application Template」(正在匯入應用程式範本)。匯入完成後,「Unit kinds」(單元 kind) 分頁會列出產生的 u-native-components 單元 kind。

使用 App Lifecycle Manager 佈建應用程式

  1. 在「run-storage-quickstart-offering」的「SaaS 產品詳細資料」頁面中,按一下「佈建」。

    「Provision」(佈建) 頁面隨即開啟。

  2. 在「Provision」(佈建) 頁面的「Region」(區域) 清單中選取「us-central1」,然後按一下「Add」(新增)。

  3. 在「Add unit to provision」(新增要佈建的單元) 面板中,設定單元:

    1. 在「Unit name」(單位名稱) 欄位中輸入 run-storage-quickstart-unit-1。
    2. 在「Unit kind」(單位種類) 清單中,選取「u-native-components」單位種類。
    3. 在「Release」(版本) 清單中,選取為範本修訂版本產生的版本。
    4. 在「Service account」(服務帳戶) 清單中,選取您在「事前準備」一節建立的操作服務帳戶。
  4. 按一下「Add tenant project variables」(新增租戶專案變數),然後選取要用於佈建資源的專案。

  5. 在「Other input variables」(其他輸入變數) 區域,點選「Add input variable」(新增輸入變數),然後輸入下列元件輸入變數的值:

    • 名稱:cloud-run-1_project_id、變數類型:String、變數值:您的專案 ID
    • 名稱:cloud-run-1_location、變數類型:String、變數值:us-central1
    • 名稱:cloud-run-1_service_name、變數類型:String、變數值:quickstart-web
    • 名稱:cloud-storage-1_project_id、變數類型:String、變數值:您的專案 ID
    • 名稱:cloud-storage-1_location、變數類型:String、變數值:us-central1
    • 名稱:cloud-storage-1_name、變數類型:String,以及變數值:全域不重複的 bucket 名稱,例如 PROJECT_ID-quickstart-bkt
  6. 按一下「Add」(新增)。run-storage-quickstart-unit-1 單位會顯示在「Units to be provisioned」(要佈建的單位) 表格中。

  7. 點選「佈建」,部署 run-storage-quickstart-unit-1。

    Cloud Run 服務和 Cloud Storage 會在幾分鐘後佈建。

  8. 如要在其他區域佈建額外單位,請從「Region」(區域) 清單中選取區域,然後按一下「Add」(新增)。

查看部署的單元

確認 App Lifecycle Manager 已佈建單元和資源。

  1. 在 Google Cloud 控制台,依序前往「App Lifecycle Manager」 >「Units」頁面。

    前往「單位」

  2. 按一下 run-storage-quickstart-unit-1,開啟「Unit details」(單位詳細資料) 頁面。

  3. 在「Unit details」(單位詳細資料) 頁面中,查看「State」(狀態) 欄位:

    • Ready:Cloud Run 服務和 Cloud Storage bucket 已佈建。
    • 佈建中:部署作業仍在進行中。

清除所用資源

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

刪除專案

如果您是在新的 Google Cloud 專案中部署應用程式資源,且不再需要該專案,請按照下列步驟刪除:

  1. 前往 Google Cloud 控制台的「Manage resources」(管理資源) 頁面。

    前往「Manage resources」(管理資源)

  2. 從專案清單中選取要刪除的專案,然後點選「Delete」(刪除)。
  3. 收到提示時,請輸入專案 ID,然後點選「Shut down」(關閉)。

後續步驟