Original: https://github.com/salrashid123/gcpdotnet
Sample code demonstrating running trivial .NET web
applications on Google Cloud Platform services.
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)
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
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"]
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