If you’re trying to setup .NET Core / ASP.NET 5 on Google Cloud, then this is the article for you! As a disclaimer, I’m building everything based on using a mac development environment.
As the time of writing this article, google is giving $300 to play around in the cloud and try out all the toys. Just go here!
Installing the Google cloud CLI
Now, we just need to setup the google cloud CLI. This is actually pretty nice and will be how you deploy your app.
You can try to install the CLI here:
I, personally, was getting an error when trying to install gcloud CLI and ran this instead and it worked:
curl https://dl.google.com/dl/cloudsdk/release/install_google_cloud_sdk.bash | bash
Setup your dotnetcore app
Assuming you have a basic dotnet core setup you can skip this step. If you don’t here’s a barebones setup.
1) Install the dotnet core CLI
2) Run these to create new kestrel web server
dotnet new web
dotnet publish -c Release
This will output a
bin folder which will be what is on the server.
Create a docker file
You don’t need docker installed or anything for this. If you aren’t familiar, a dockerfile is essentially a server installation script.
Just create a file named
dockerfile (no extension) and paste this in:
ADD ./yourpathtothebinfolder/bin/Release/netcoreapp2.0/publish/ /app
ENTRYPOINT [ "dotnet", "api.dll" ]
yourpathtothebinfolder with the appropriate path to the publish in the previous step. The path in this file means you don’t need to keep the dockerfile in the same
NOTE: Here’s where Google’s basic tutorial went wrong. The docker image they have is old and didn’t support the latest dotnet core version. So I went ahead and built out a new docker image and threw it out there for everyone to use! If you deploy your app and are getting errors, just uncomment the line that points to the image I created (the line starting with
#) and remove the other
FROM line pointing to
Create a google app engine server config
This is a basic script that creates a google app engine based on a dockerfile. Just create a file name
app.yaml and paste this in:
Deploy the app!
Just run this to deploy the app to google cloud!
gcloud app deploy --version v1
You can rerun this and change the version each time. It will version the app and shift traffic to the new deployment.
Hope you enjoyed the tutorial, and feel free to reach out with any questions!