Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Automation of Cloud run deployment

Hi, I am trying to automate the Cloud run deployment from local machine using C# console application.

Is it possible? If yes then How Can I achieve this.  I have tried Google.cloud.shell.v1 nuget package but in that documentation I found nothing to write command directly from local machine to cloud shell.

So please help me in this. 

0 8 1,496
8 REPLIES 8

There is a C# library that provides an interface to admin tasks related to Cloud Run ... here is a link.  The way I think about this is that anything and everything you can do through the Google Cloud Console, you can do through API programming (various languages) as well as gcloud (CLI app) and Terraform (Infrastructure as Code).  There are also higher level concepts such as Cloud Build  that can be invoked to not only deploy Cloud Run apps but also build those apps, containerize them and then deploy.  What I'd suggest is to have a skim at these links and see if that assists.  If not, please post back and flesh out the concepts and description you would like to achieve in more detail.

Hey, thanks for answering. In documentation I found that there is an cloud shell api from that we can interact with cloud shell. But I did not find any code example from that we can run a gcloud commands from using C# code. As to make docker image and then for deploying it to cloud run I need to run gcloud commands. Is there any ways to do it from C#.

Howdy my friend.  Can you post the link to the documentation you referenced.  I'm still not quite grasping the concept and if I could see the docs themselves, that may help.   As for calling from C#, the way I like to think about it is that EVERYTHING in Google Cloud is exposed via an API.  These APIs are fully documented.  The APIs can be called via REST but Google tries to make it easier by proving "Client Libraries" in a variety of languages (including C#) that means you don't have to drop down into low level REST programming.  The Google supplied "gcloud" program is a command line program (CLI) that itself uses the exposed APIs from Google Cloud.  This means that anything you can do in gcloud, you can also do through API and hence through C#.    Depending on your needs, I see a lot of customers using Terraform for infrastructure building and Cloud Build also provides high level wrappers.

I am talking about Google.cloud.shell.v1.

Can you give me a link of code snippet in which we are running any command in cloud shell using C# console application.

That will help me a lot.

Thanks.

I found this link:

https://cloud.google.com/shell/docs/reference/rpc/google.cloud.shell.v1

however, after reviewing it, I can't see any relationship between this API and Cloud Run.   Reading the above API, I seem to see it is used for creating an instance of Cloud Shell.  When reading your original post, I heard "Hi, I am trying to automate the Cloud run deployment from local machine using C# console application."   From this, I sense you want to work with Cloud Run from your local machine (a laptop or local PC/Mac).  I'm not seeing how this relates to Cloud Shell which is a Linux command line interface that is accessible through a browser.

 

Hi,

I am talking about cloud shell of google cloud platform.

To make a docker image from dockerfile we run command in cloud shell. 

And now I want to run those command from C# console application.

Howdy... and thanks for your patience.  I got confused when the thread started.  I usually think of a local machine as a PC or laptop where you are running local commands.  But I get the notion now that you want to run commands in Cloud Shell.   Cloud Shell is a virtual machine (VM) meaning that it is a computer that you login into using SSH and run commands interactively.   You can write applications in a variety of languages that you can use Cloud Shell to run those commands.   If your goal is to create a docker image from a Dockerfile, my immediate recommendation would be to use Cloud Build.  Cloud Build is a service from Google that, when invoked, takes your Dockerfile, builds the docker image and stores the result in Googles Artifact Registry.  Here is a quick-start to do that.   You can launch Cloud Build using the gcloud command line ... but I hear you say you want to run a C# app to achieve the task.  Perhaps you can explain further more of your design?   If you do want to launch Cloud Build from C#, there is an API for that ... https://cloud.google.com/build/docs/api/reference/rest/v1/projects.builds#Build

I looked to see if there was a C# binding ... but I didn't see one, so we would have to invoke it as a REST call.

Thanks for sharing this.