info2000
info2000

Reputation: 183

How to connect via ssh to google cloud run or appengine?

I know cloud run and appengine are different services. I need connect via ssh to an appengine or cloud run instance to execute some process manually.

The reason to use one of these services is they charge only when I use it, not 24x7 hours

Some way to do that? Thanks

Upvotes: 1

Views: 10464

Answers (3)

user1170117
user1170117

Reputation: 153

It is actually really easy to do this here is how.

1.- Choose your service from the cloud run services list

2.- In the service page, go to revision tab.

3.- Click on image URL.

4.- In the image details page, click on Pull

    • Press the first run cloud sheel for the "gcloud auth configure-docker xxxxxxx"
    • Press the second Pull by tag "Run In Cloud Shell"
  1. Once all that is done type

    docker run -it --entrypoint sh {image-url}

Where {image-url} is the second line under docker pull\ it will look something like this

 us-central1-docker.pkg.dev/acountname/cloud-run-source-deploy/project/project:c8fe03d92d490d7abafb4134eb7b33851bffa1ef

so it will be something like this

docker run -it --entrypoint sh us-central1-docker.pkg.dev/acountname/cloud-run-source-deploy/project/project:c8fe03d92d490d7abafb4134eb7b33851bffa1ef

Please note that if you need something like nano you will need to preinstall it.

Upvotes: 5

info2000
info2000

Reputation: 183

Context I code using codeanywhere, because I had multiple places with desktop computers to work and don't want to load a laptop Actually I had vps's as enviroments, like my projects are long time, don't need to rebuild or change the enviroment in years

The need: I run some times per month shell commands like test nodejs scripts, before to move them to serverless (cloud run)

The old-approach: try to run these scripts on a working enviroment connecting via ssh

The moderm developer way: use codeanywhere containers as code storage and testing + create a gitlab ci/cd to deploy automatically on google cloud run instances

Upvotes: 1

guillaume blaquiere
guillaume blaquiere

Reputation: 75970

Short answer: you can't.

In fact, these services are designed to answer to HTTP request, and only when an HTTP request is processed you pay for the service. If you log into an instance in SSH, will you pay for the HTTP request? If you run a process on the instances, will you pay for the HTTP request?

Of course not. But the cost isn't the main reason. Cloud Run and App Engine can create and destroy instances as they wish, according with the traffic or something else. It's useless to log into an instance and to run a process and few seconds/minutes after the instance is deleted and a new one created, you will lost all what you do.

If you use these services, you must accept that the servers are managed by Google, that you can only deploy a service and use it through HTTP. It's not a traditional VM instance, it's "serverless".


After saying that, if you want to explore the runtime configuration, you can use a HTTP reverse shell. But, at the end, it's not very useful...

Upvotes: 8

Related Questions