發表文章

目前顯示的是 2026的文章

Azure Static Web Apps 搭配後端 API 的實作心得

圖片
  開頭 如果你手上有一個靜態前端專案,但又需要一點後端能力,例如查詢資料、處理簡單商業邏輯,Azure Static Web Apps 是一條很值得考慮的路線。 這篇筆記整理的是我在 Azure Static Web Apps 免費方案下,搭配 Azure Functions 當後端 API 的實作觀察。重點不是把架構講得很大,而是記下真正上線時會碰到的幾個關鍵限制。 背景 我這次是拿一個 Blazor WebAssembly 測試網站來做實驗,想確認前端部署到 Azure Static Web Apps 之後,能不能順便把 API 一起帶上去。 結果是可以,但不是「把前端丟上去就結束」這麼簡單。實際上還要注意部署流程、專案相依關係,以及免費方案底下的受控模式限制。 說明 1. 免費方案下,API 其實是受控的 Azure Functions Azure Static Web Apps 的免費方案可以搭配後端 API,但那個 API 不是你平常獨立管理的 Function App,而是由 SWA 受控的 Azure Functions。 這代表幾件事: 你不會在 Azure Portal 的 Function Apps 清單裡看到它 它比較適合輕量 API 如果要做長時間執行、排程或佇列處理,就不太適合放在這裡 2. 部署流程要一起調整,不能只看前端 一開始如果是 Azure 自動產生的部署流程,常常只夠發前端。 但當你把 Function 一起加進來時,workflow 通常還要再調整一次,確保前端和 API 都有被正確發行。參考 github workflows yml 3. 專案之間不能互相依賴 當 Function 加進來之後,架構上要保持乾淨分離。 我在這次測試裡特別注意到: 前端專案與 Function 專案不能互相相依 TargetFramework 要從 net48 改成 net9.0 。 Azure Static Web Apps 不支援 .NET 10 。 如果目標框架不在 Azure Static Web Apps 支援範圍內,部署就會卡住 這類問題通常不是程式碼本身錯,而是平台與專案結構不合。 4. 免費方案有自己的配額與邊界 Azure Static Web Ap...

Docker Image To Azure Container App

圖片
  前言 續前一篇  Docker Image To GCP Cloud Run 本文記錄,將一個.NET Web程式,使用docker image放到Azure Container上。 由於Azure Container Registry,沒有免費的,本文採docker hub的方式(有免費額度) ps: GCP Azure Container,有每月前0.5G免費 使用方式 推送到Docker Hub 先到docker.com 註冊帳號 用command 登入,或直接用docker for window登入 docker login Build image docker build -f AzureConatinerLab/Dockerfile -t azurecontainerlab . 標記並推送到 Docker Hub docker tag azurecontainerlab:latest kimxinfo/azurecontainerlab:latest docker push kimxinfo/azurecontainerlab:latest Azure Container App 建立 Container App,輸入Hub上的image 設定 Ingress 完成後,Overview 可以使用Application Url瀏覽 其他 如果希望服務閒置時不持續計費,可以保留  Min replicas = 0 免費額度 請求次數 :每月前  200 萬次  請求免費。 CPU 資源 :每月前  180,000 vCPU-秒  免費。 記憶體資源 :每月前  360,000 GiB-秒  免費。 特點 :支援「縮減至零 (Scale to Zero)」,沒流量時不計費。 總結 本文重點是 Docker Hub + Azure Container App 的串接 相關參考 Docker Image To GCP Cloud Run

Docker Image To GCP Cloud Run

圖片
  前言 本文記錄,將一個.NET Web程式,使用docker image放到Cloud run上。 使用方式 本地初始化環境 安裝GCP CLI (New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:Temp\GoogleCloudSDKInstaller.exe") & $env:Temp\GoogleCloudSDKInstaller.exe 裝完後,會接著要你登入及選擇預設的專案(畫面..略) 啟用必要的 GCP 服務 gcloud services enable run.googleapis.com cloudbuild.googleapis.com Google Consle 建立 Artifact Registry repo 設定 Docker 對 GCP Registry 的驗證 gcloud auth configure-docker asia-east1-docker.pkg.dev Build image docker build -f MondayAr/Dockerfile -t mondayart100 . 標記並推送 image 到 Artifact Registry # 標記 image docker tag mondayart100 asia-east1-docker.pkg.dev/gen-lang-client-xxxxx/monday-ar-t100/mondayart100:latest # 推送至 GCP docker push asia-east1-docker.pkg.dev/gen-lang-client-xxxxx/monday-ar-t100/mondayart100:latest 在 Cloud Run 建立服務,並選擇 Artifact Registry 裡的 image 設定個數量下限0,閒置不算費用。Ingress允許網路使用 設定  .env  或其他環境變數 完成,在服務可以取得網址 後續更新 之後image更新,一樣先Build Image再標記並推送 ...