GCP Cloud Run
將 Vue3 Docker image 部署 Google Cloud Run 簡易教學

Table Of Content
前提條件 要閱讀本文,您需要:
- JavaScript 和 React 的基本知識,
- 安裝 Node (version 16 以上)
- 安裝了 npm 或 yarn(npm 的 v6 更適合安裝 strapi)。注意:如果您在安裝 strapi 時遇到問題,我建議完全清除 npm 緩存並通過從系統中完全卸載更高版本的 node 來降級到 node 14 以及節點可能出現的任何地方)。接受對我有用的附加安裝(python 腳本等)。
- Docker 基本知識和環境
- GCP 基本知識和環境
那就開始吧
在既有的專案下新增與下圖一樣檔案
說明: 圖中號碼 1: shell 檔案的作用是將需要手動打的指令做一個結合,只需要執行 shell 檔案就可以做到很長串的指令 圖中號碼 2: Dockerfile 是用來建構 docker images 的指令檔。 圖中號碼 3: Nginx 的主配置文件是 nginx.conf
shell 檔案範本:
圖片編號 1:PROJECTID → 換上各自的 Google 的 project id 圖片編號 2:PROJECT → 換上各自的 Google Cloud Run 的專案名稱 圖片編號 3:使用 Docker 指令 Build Images

圖片編號 4:使用 Docker tag 將剛剛建好的 docker images 加上 GCP 指定的 tag 圖片編號 5:將加好 tag 的 docker images 推倒 Google Artifact Registry 上 圖片編號 6:將最新的 Image 部署到 Cloud Run 上

Dockerfile 檔案範本:
根據不用的開發環境調整,此範例是使用 yarn 安裝套件為範例

Nginx.conf 檔案範本: 使用 Nginx 作為 Web Server 不需要再架設 Node 伺服器

部署環節
以上的檔案都會是放在專案的根目錄 在 termianl 中輸入 sh shell 檔案名稱 環境名稱 版號

部署成功啦

在 Artifacts Registry 上可以看到 Image 成功推上去的樣子

在 Cloud Run 上可以看到部署成功
