在Google Cloud Platform“ App Engine Flexible Environment”上尝试ASP.NET Core
Last week I used Zeit and "now" to deploy an ASP.NET Core app (via a container) to the Zeit cloud. Tonight the kids are asleep so I thought I'd deploy to the Google Cloud. They've got beta support for open source ASP.NET so it's a perfect time. Google even has Google Cloud Tools for Visual Studio (2015).
上周,我使用Zeit和“现在”将ASP.NET Core应用程序(通过容器)部署到Zeit云中。 今晚孩子们睡着了,所以我认为我应该部署到Google Cloud。 他们已经获得了对开源ASP.NET的Beta支持,所以现在是个完美时机。 Google甚至拥有适用于Visual Studio的Google云工具(2015)。
I'll install the Google Cloud SDK. I checked "beta" as well.
我将安装Google Cloud SDK 。 我也检查了“测试版”。
Install it, login to your Google account and setup/select a project. I make a new folder and put an "app.yaml" in there with this inside as a directive to the Google Cloud Platform.
安装它,登录到您的Google帐户并设置/选择一个项目。 我创建了一个新文件夹,并在其中放入“ app.yaml”,并将其作为对Google Cloud Platform的指令。
runtime: aspnetcore
env: flex
Here's a gratuitous screenshot:
这是一个免费的屏幕截图:
I did a dotnet new, dotnet restore, and finally a:
我做了一个新的dotnet,还原了dotnet,最后做了一个:
dotnet publish -c Release
which makes a publish folder that will get sent up to the cloud.
这使得发布文件夹将被发送到云端。
IMPORTANT NOTE: I initially tried to push a .NET Core app using the .NET Core 1.1 runtime but Google Cloud's beta support in the flexible environment is set up for the 1.0.3 runtime (using their own custom docker base image) as of the time of this blog post, so you'll want to "dotnet new mvc --framework netcoreapp1.0" and set the "RuntimeFrameworkVersion" to get that specific shared LTS (Long Term Support) version. As soon as the Google Cloud flex runtime has the latest LTS (1.0.4, at the time of this writing) then apps would just roll forward.
重要说明:最初,我尝试使用.NET Core 1.1运行时推送.NET Core应用程序,但自1.60起,为1.0.3运行时(使用其自己的自定义docker基本映像)设置了Google Cloud在灵活环境中的beta支持。在撰写本文时,您将需要“ dotnet new mvc --framework netcoreapp1.0”并设置“ RuntimeFrameworkVersion”以获取特定的共享LTS(长期支持)版本。 只要Google Cloud flex运行时具有最新的LTS(在撰写本文时为1.0.4),应用程序就会向前滚动。
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<RuntimeFrameworkVersion>1.0.3</RuntimeFrameworkVersion>
</PropertyGroup>
Otherwise you'll get errors. Fortunately those errors are very clear.
否则会出现错误。 幸运的是,这些错误非常清楚。
The walkthrough on Google Cloud suggests you copy the app.yaml file using a standard CLI copy command. However, since you're going to need that app.yaml EVERY publish, just add it to the csproj like this:
Google Cloud上的演练建议您使用标准的CLI复制命令复制app.yaml文件。 但是,由于每次发布都需要该app.yaml,因此只需将其添加到csproj中,如下所示:
<ItemGroup>
<Content Include="app.yaml" CopyToOutputDirectory="Always" />
</ItemGroup>
This way it'll end up in publish automatically. You can then publish to the "AppEngine flexible environment:
这样,它将最终自动发布。 然后,您可以发布到“ AppEngine灵活环境:
dotnet restore
dotnet publish -c Release
gcloud beta app deploy .\bin\Release\netcoreapp1.0\publish\app.yaml
gcloud app browse // THIS IS JUST TO VISIT IT AFTER IT'S PUBLISHED
NOTE: You may get an ERROR that billing isn't enabled, or that the cloudbuild.googleapis.com aren't enabled. You'll need to ensure you have an active Free Trial, then go to the API Manager in the Google Cloud Platform dashboard and enable "Google Cloud Container Builder API." I also had to manually enable the API for the "Flexible" Environment and confirm I had a valid billing account.
注意:您可能会收到一个错误,表明未启用计费,或者未启用cloudbuild.googleapis.com。 您需要确保自己有一个有效的免费试用版,然后转到Google Cloud Platform仪表板中的API Manager并启用“ Google Cloud Container Builder API”。我还必须手动为“ Flexible”环境启用该API,并确认我有一个有效的帐单帐户。
Once I enabled a few APIs, I just did a standard "gcloud beta app deploy" as above:
一旦启用了一些API,我就可以像上面那样进行标准的“ gcloud beta应用程序部署”:
Pretty cool stuff! Here is my ASP.NET Core app running on GCP's Flex engine:
很酷的东西! 这是我在GCP的Flex引擎上运行的ASP.NET Core应用程序:
You can "tail" your app with "gcloud app logs tail -s default" and you'll see the output from .NET Core and ASP.NET (and Kestrel) in the Google Cloud!
您可以使用“ gcloud应用程序日志尾号-s默认值”“尾随”您的应用程序,然后您将在Google Cloud中看到.NET Core和ASP.NET(和Kestrel)的输出!
Or online in the Google "Stackdriver" logging page:
或在线访问Google“ Stackdriver”日志页面:
Go read up more on the Google Cloud Platform Blog. They even support Kubernetes clusters with ASP.NE Core apps packaged as Docker containers.
在Google Cloud Platform Blog上阅读更多内容。 他们甚至通过打包为Docker容器的ASP.NE Core应用程序支持Kubernetes集群。
Sponsor: Thanks to Redgate! Track every change to your database! See who made changes, what they did, & why, with SQL Source Control. Get a full version history in your source control system. See how.
赞助商:感谢Redgate! 跟踪对数据库的所有更改! 查看谁使用SQL Source Control进行了更改,他们做了什么以及为什么。 在源代码管理系统中获取完整的版本历史记录。 看如何。
关于斯科特 (About Scott)
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
斯科特·汉塞尔曼(Scott Hanselman)是前教授,前金融首席架构师,现在是演讲者,顾问,父亲,糖尿病患者和Microsoft员工。 他是一位失败的单口相声漫画家,一个玉米种植者和一本书的作者。