[英]How do I store user quiz scores in ASP.NET Core 3 backend using an Angular 8 frontend application?
[英]How to deploy asp.net core (backend) and angular 8 (frontend) appplications together to Google App Engine?
我正在嘗試將我的項目從共享主機遷移到 Google Cloud Platform。
我的應用程序由一個后端(asp.net core)和一個前端(angular 8)組成。 它們僅通過 web api 調用進行通信。 在我的本地環境和我當前的主機(共享 windows 主機)上,它運行良好。 I only need to publish my web project via web deploy from Visual Studio and it deploys the .net and the angular app together with this one click.
我的 Startup.cs 的一部分:
if (!Environment.IsDevelopment())
{
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "MyAngularApp/dist";
});
}
在其他可能的解決方案中,我找到了我想要將我的應用程序部署到的App Engine 。 我為我的后端和前端創建了 app.yaml 文件。
我可以一一部署它們(“默認”服務的后端/“api”服務的前端),因此它們將被部署到單獨的域。
我的解決方案不起作用,我想我的方法是錯誤的。 是否應該在一個 yaml 文件中配置這兩個應用程序? 我正在尋找應該如何完成的最佳實踐。
特別是對於您的場景,由於 aspnet.core 和 angular 之間存在依賴關系,因此最順利的遷移到 Google App Engine 將是容器化您的應用程序並使用帶有自定義運行時的 App Engine Flex。
這將解決“它適用於開發但不適用於生產”的常見問題。 否則,您在部署到其他 App Engine 產品(如 Standard 或 Flex)時可能會遇到一些錯誤,因為它們的運行時可能不包括您的項目所具有的所有依賴項。
總而言之,您需要:
創建一個 Dockerfile 容器化您的 aspdotnet/angular 應用程序。 我發現了如何將 dotnet 應用程序容器化的這個很好的例子。 跟隨后者可能還不夠,因為它不包含所有 docker 語句,但您也可以使用另一個來幫助您填寫 angular 缺少的 docker 語句。
使用以下配置創建app.yaml
文件。
runtime: custom
env: flex
service: [SERVICE_NAME]
運行gcloud app deploy
正如您所看到的,上面列表中最復雜的部分是 docker,但由於使用 Google App Engine flex 自定義運行時進行部署是最小的,因此將您的應用程序放在容器中有很多好處。
可以通過一個應用程序解決。yaml 無需容器化:
runtime: aspnetcore
env: flex
instance_class: F2
automatic_scaling:
min_num_instances: 1
max_num_instances: 5
cool_down_period_sec: 120
cpu_utilization:
target_utilization: 0.6
target_concurrent_requests: 10
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: AngularApp/dist/index.html
upload: AngularApp/dist/index.html
- url: /
static_dir: AngularApp/dist
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.