So, I have a specific chain of kubernetes and bash commands that I have to execute on gcloud, I'd like to know if there is any way to execute those commands automatically via scripting, without the need of actually having to open and interact with gcloud CLI. Maybe using a npm package but i don't know if there is a package for this usage.
I already have gcloud cli installed locally, should exec and/or spawn commands work? I've tried but ultimately failed.
TL;DR: I just want to know how to automate gcloud commands using code! Preferably on node.js, but i can learn it on another language too.
Please provide a little more detail as to what it is you're trying to automate as this will help guide recommendations.
There are several challenges automating subprocesses (e.g. invoking bash and it running gcloud
) from within another program. High among these is that shell-scripting doesn't provide very strong parameter passing (and no typing beyond strings) and error handling is difficult.
For NodeJS you can use child_process
. You'll need to ensure that the child process environment is able to access the gcloud
binary and its configuration and that it can authenticate too. Since you're running a program to interact with gcloud
, I recommend you use a service account to authenticate if you choose this approach and then you may need (if you run off-GCP) to provide a service account key to your code too.
There are alternatives although these require more work, they provide much more robust solutions:
If you add more details to your question, I can add more details to this answer.