Search code examples
google-cloud-platformgcloud.net-5google-cloud-run

How to remake `gcloud run deploy` with .NET Cloud Client Libraries?


I am trying to deploy an already built image to Cloud Run using .NET Cloud Client Libraries.

I need exactly the same behavior as gcloud run deploy hello --image=us-docker.pkg.dev/cloudrun/container/hello but with .NET Cloud Client Libraries.

Unfortunately, I cannot find an API that does that in https://cloud.google.com/dotnet/docs/reference.

I also tried downloading Cloud SDK from https://cloud.google.com/sdk/docs/install and inspecting the code with PyCharm.


Solution

  • The API is called Cloud Run Admin API.

    Cloud Run Admin API

    There is an SDK for .NET.

    Cloud Run Admin API Client Library for .NET

    Namespace Google.Apis.CloudRun.v1

    Creating a Cloud Run service is fairly complicated. I recommend that you study the REST API first so that you understand the request body. The .NET library models the REST API.

    Method: namespaces.services.create

    The key item is the service resource:

    Resource: Service

    There is a quick way to learn the API request body. Create a simple Cloud Run example and then add the command line option --log-http. Save the output to a file and then study the HTTP request parameters and request body to decipher the very large data structures that are required to create a service.

    gcloud run deploy --log-http
    

    I wrote two articles on the Cloud Run Admin API:

    1. Google Cloud Run Deep Dive – Understanding the APIs – Part 1
    2. Google Cloud Run Deep Dive – Understanding the APIs – Part 2

    Note: I wrote those articles two years ago. Cloud Run has advanced a lot since then. However, these articles will help you understand the low-level details of the service that were not published elsewhere at the time.