Is there a way to run the scripts to download the proxy, have Google authentication set up, and begin listening for connections from an application in Heroku with the appropriate credentials? I have an application in Heroku with Express routes that connect to a Google Cloud SQL instance, and I would like to use the cloud_sql_proxy to connect it.
I can run the application locally, starting the proxy locally and listening for events. It seems to me that the proxy needs to run on the same machine/instance as the application, so it would seem to have to run in the cloud with Heroku. If so, how do I set up the proxy invocation to do so? Should it be invoked within Node/Express?
You will need to do this work yourself, but you can download the proxy and add it to your slug using a custom buildpack. You would then also need to write a script (and use that in your Procfile) that starts both the proxy and the express server together.
A coworker pointed me to heroku's pg-bouncer that uses a very similar strategy, which you can look at: https://github.com/heroku/heroku-buildpack-pgbouncer
Sorry that this is pretty convoluted.
It was a bit convoluted, but I did get it to work using a specific instantiation of the Procfile using a bash script to download and start the instance.
For others' reference, I used a file called proxy.sh that looks like below:
#!/bin/bash
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.386
mv cloud_sql_proxy.linux.386 cloud_sql_proxy
chmod +x cloud_sql_proxy
./cloud_sql_proxy -instances=[instance-name]=tcp:3306 -credential_file=[path-to-file]
and a Procfile that looks like this:
web: (bash ./proxy.sh &) & node start.js
This was very helpful. Thank you!
Thanks for figuring this out!
Most helpful comment
It was a bit convoluted, but I did get it to work using a specific instantiation of the Procfile using a bash script to download and start the instance.
For others' reference, I used a file called proxy.sh that looks like below:
and a Procfile that looks like this: