martes, 28 de noviembre de 2017

.NET on Google Cloud Platform

Original: https://github.com/salrashid123/gcpdotnet
Sample code demonstrating running trivial .NET web applications on Google Cloud Platform services.
These simply builds off of existing technologies and samples but configures it to run on GCP effeciently with healh checking and load balancing.

The example here uses Microsofts's .NET Core 1.0.0 RC/preview (dotnet-dev-1.0.0-preview2-003121).
FROM microsoft/dotnet:1.1.0-sdk-projectjson

ADD . /app
WORKDIR /app
RUN ["dotnet", "restore"]

EXPOSE 8080
WORKDIR /app/src/WebApplication1/
ENTRYPOINT ["dotnet", "run", "-p", "project.json"]

in project.json:
"Microsoft.NETCore.App": {
   "type": "platform",
   "version": "1.1.0"
}
You can use Visutal Studio 2015 to create and extend the sample from scratch. VS2015
  • WebApplication1 Default webapplication generated by Visual Studio 2015: "New Project
    • C#
      • Web
        • ASP.NET Core Web Application (.NET Core) ; (Change Authenticaiton --> No Authentication)
(optionally, if you want to try out Google APIs, see Using Google API Libraries)
Basic Configuration
Sample application simply spins up inside a Docker container an runs Kestrel to host the application. The sample is modified from the baseline in the following way to run with healthchecks in GCP:
  • port: 8080
  • GET requests to endpoint /_ah/health must return a 200 OK HTTP response
  • Use Kestrel Webserver

WebApplication1
Pack/Publish steps
If you want to pack the deployment to a .dll using dotnet publish
in project.json, if the following artifiact from Visual Studio exists, remove
  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
Then make the build/release .dll
cd WebApplication1/src/WebApplication1
dotnet restore
dotnet publish  -c Release
To run the local pack directly:
dotnet bin/Release/netcoreapp1.0/publish/WebApplication1.dll
Finally, edit the Dockerfile
FROM microsoft/dotnet:1.1.0-sdk-projectjson

ADD . /app
WORKDIR /app

EXPOSE 8080
WORKDIR /app/src/WebApplication1/
ENTRYPOINT ["dotnet", "bin/Release/netcoreapp1.0/publish/WebApplication1.dll"]
Note: As of 8/16, dotnet is currently not supported on Alpine Linux.
Deploying
Deploying to GCP requires your gcloud environment to get setup:
gcloud auth login
gcloud config set project <your_project>
AppEngine
Deploying to GAE is pretty simple:
gcloud app deploy app.yaml
Then, http://your_project.appspot.com
ContainerEngine
To deploy on GKE, you need to setup the replication controllers and frontend loadbalancer services as well as a small cluster.




No hay comentarios:

Publicar un comentario