Skip to main content
  1. Posts/

Cloud Build + Cloud Run

·150 words·1 min· loading · loading · ·
ADSFAaron
Author
ADSFAaron
Table of Contents

開發測試環境完程式後,想必最重要的步驟就是實際執行了,而 GCP 也位開發者提供一個良好的部屬流程。就跟著接下來的步驟一起執行看看吧!

前置流程
#

在推送專案前,必須得要在 Google Cloud 建立專案,這部份就不在多撰述。

同時也需準備好下面的前置作業

  1. 啟動 Cloud Build API

  2. 安裝 Google Cloud CLI

  3. (第一次啟用) 在 Terminal 輸入 gcloud init,設定專案等必要步驟

  4. 取得 Project ID,可以透過 Terminal 指令 gcloud config get-value project 或是網頁中查詢,如圖片中紅色底線處

    Google Cloud get Project ID

Build-1
#

根據 官網文件 介紹,可以使用 gcloud 指令達成,但經過測試,使用此方式會跳出 Error 如下:

frontend git:main ❯ gcloud builds submit --tag gcr.io/cloud-build-demo/buyerinfo-streamlit:20250525 .    

ERROR: (gcloud.builds.submit) Invalid value for [source]: Dockerfile required when specifying --tag

如果指定 Dockerfile,會跳出另個 Error:

frontend git:main ❯ gcloud builds submit -t gcr.io/cloud-build-demo/buyerinfo-streamlit ./dockerfile

ERROR: (gcloud.builds.submit) Local file [{src}] is none of .zip, .tgz, .gz

經過 Stackoverflow 查詢,推薦使用 Build-2 方式。

Build-2
#

這邊假設 Project ID 是 cloud-build-demo

  1. 建立 yaml

    steps:
    - name: 'gcr.io/cloud-builders/docker'
    args: [ 'build', '-t', 'gcr.io/cloud-build-demo/buyerinfo-streamlit', '.' ]
    images:
    - 'gcr.io/cloud-build-demo/buyerinfo-streamlit'
    
  2. gcloud builds submit --config cloudbuild.yaml .

接著等他執行完,出現 Success 就可以囉!

Cloud Build Success

也可以透過 Google Cloud > Cloud Build 中的紀錄查看

Cloud Build Record

接著可以透過 Cloud Run 取得雲端中的 Image 來作其他部屬。

Reference
#