Hi, i’d like to ask some help with connecting to gcp cloud sql (mysql, myxql ecto adapter). when im using dev env, i can query and everythings fine. Checked DATABASE_URL, also tried hard coding it in prod.exs, runtime (DB_PASSWORD, DB_HOST, etc.). Added the ip from fly ips list --app app-name to authorized networks in cloud sql dashboard. the mysql instance ip from gcp is public.
But when i deploy it, here’s what i get from monitoring:
Are the IPs returned from fly ips list the outgoing IPs
As far as I’m aware, Fly shows the IP it receives requests on (which you need for DNS entries, etc) however when your app makes outgoing requests, those would not come from that same IP. If that is the case it would explain this issue: Google’s firewall would block the request to connect and that would result in a timeout in your app.
You could confirm this (if this is not a production database!) by allowing access to any IP, briefly, then try and connect to it from your app. If that works, you will know the IP is the issue.
hi @greg, thanks for helping me out. I’m actually confused with how to allow any or wildcard, but ill try . Can confirm it works just by adding the ip from my local to the authorized networks (gcp cloud sql dashboard).
if i dig +short app_name.fly.dev it gives me the same thing with fly ips list --app app_name
gcp auth proxy is working fine from my local machine. I added wget in Dockerfile but it’s not installed when im connected via fly ssh (does that mean when im installing wget it’s going in builder but not in the app instance?). Deployed with --no-cache and --remote-only. Am I missing something?
Er, well it should at least be there if you run wget. Strange. I haven’t used it from Fly, but in theory you should be able to wget it, chmod it to make it executable, and then run it.
The one slight complication with this approach would be you would need to have the sql proxy running in parallel to your app process. So you would likely need something like supervisor (or equivalent) to keep both it and your app running. Take a look at Running Multiple Processes Inside A Fly.io App · Fly Docs for how
Yeah, from my read of that approach, that will indeed make the proxy work … but what if the vm restarts, or the proxy crashes (don’t know if that’s possible). I’m thinking you would still need some form of process manager running to keep it running. Else if it’s not running, database connections aren’t going to work. So I’ll leave that with you.