cloud-sql-proxy icon indicating copy to clipboard operation
cloud-sql-proxy copied to clipboard

Add example script for invoking commands against the Proxy

Open felixhuttmann opened this issue 3 years ago • 3 comments
trafficstars

When trying to run a script or database migration, the user currently has to

  1. start the cloudsql proxy and wait for the port to open or unix domain socket to be created
  2. run the command
  3. stop the cloudsql proxy

The usage would be simplified if the cloudsql proxy offered an exec subcommand that could be used like this:

./cloudsql-proxy exec -- psql --command 'select 1;'

The cloudsql-proxy binary would establish the connection, then run the supplied shell command, and terminate after the termination of the command.

Similar functionality is already offered by the firestore emulator to run automated tests (e.g., firebase emulators:exec "./my-test.sh", see [1]).

Without this, waiting for the cloudsql proxy to become available and killing it reliably afterwards in a typical shell script that runs in a CI/CD pipeline is a significant hassle.

[1] https://firebase.google.com/docs/functions/local-emulator#run_the_emulator_suite

felixhuttmann avatar Dec 18 '21 18:12 felixhuttmann

Thanks for the suggestion. I’ll take a closer look at this in the new year. It seems like a pretty common use case.

enocom avatar Dec 18 '21 19:12 enocom

Thinking some more about this, I totally get the convenience of it. I worry a bit about the security vulnerabilities this might open up. What if this project provided a script that people could use instead?

enocom avatar Aug 29 '22 20:08 enocom

@enocom would you perhaps have time to look at my CI pipeline while your example is still pending? Hopefully it might help provide a context for a typical use case that contribute to the example script.

JannieT avatar Nov 26 '22 11:11 JannieT