【发布时间】:2019-11-29 20:47:52
【问题描述】:
启动部署到 Google Application Engine Flexible 的应用程序时,由于 307 重定向过多而失败。它在 VS IDE 本地成功运行。
开发和计算堆栈包括:
- MacOS
- .NET Core 3
- Visual Studio 2019 for Mac
- 码头工人
- 谷歌应用引擎
我使用 VS api 模板(天气预报)创建了一个项目。
- 创建 API 项目
- 添加 Docker 支持(通过菜单)
- 创建和导出 SSL 证书:
dotnet dev-certs https -v -ep /Users/QQQQQQQ/Projects/CostZzzzzzzzzz/xxxxx.Orchestration.Cost/Certificate/dev-certificate.pfx -p ufo
(我随后将其移至项目的根目录)
- 修改Dockerfile如下:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY Xxxxx.Orchestration.Cost/Xxxxx.Orchestration.Cost.csproj Xxxxx.Orchestration.Cost/
RUN dotnet restore "Xxxxx.Orchestration.Cost/Xxxxx.Orchestration.Cost.csproj"
COPY . .
WORKDIR "/src/Xxxxx.Orchestration.Cost"
RUN dotnet build "Xxxxx.Orchestration.Cost.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Xxxxx.Orchestration.Cost.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_ENVIRONMENT=Development
ENV ASPNETCORE_URLS=http://*:8080;https://*:443
ENV ASPNETCORE_HTTPS_PORT=443
ENV ASPNETCORE_Kestrel__Certificates__Default__Path=Xxxxx.Orchestration.Cost/dev-certificate.pfx
ENV ASPNETCORE_Kestrel__Certificates__Default__Password=ufo
ENTRYPOINT ["dotnet", "Xxxxx.Orchestration.Cost.dll"]
- 创建 app.yaml
runtime: custom
env: flex
# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
network:
name: default
subnetwork_name: default-us-east1
service: get-cost
env_variables:
# The __ in My__Greeting will be translated to a : by ASP.NET.
My__Greeting: Hello AppEngine Flex!
- 修改 Program.cs 以支持 kestrel 和 ssl
public class Program
{
public static void Main(string[] args)
{
//CreateHostBuilder(args).Build().Run();
CreateWebHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel(options =>
{
// //options.Listen(IPAddress.Loopback, 5000); // http:localhost:5000
options.Listen(IPAddress.Any, 8080); // http:*:80
options.Listen(IPAddress.Any, 443, listenOptions =>
{
listenOptions.UseHttps("dev-certificate.pfx", "ufo");
});
})
.UseStartup<Startup>();
}
- 将服务部署到 GAE:gcloud app deploy
此解决方案是几篇描述如何通过 Docker 创建 .NET Core 应用程序并将其部署到 GAE 的文章的合并。
错误日志的主要信息是: XXX.YYY.ZZZ.AAA - "GET /" 307 undefined "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
我正在寻求有关如何正确配置应用程序以使其在 GAE 中正确运行的帮助。
PS:通过删除 Dockerfile 中的 ENV 指令,docker 容器将在我的 mac 上本地运行。但是,在 GAE 上运行它让我望而却步。
【问题讨论】:
标签: docker google-app-engine .net-core