![](/img/trans.png)
[英]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.