I want to run an elixir application in google app engine flexible environment.
I also have a postgresql server running on google cloud SQL.
I am able to deploy the application inside the docker container. The problem is that I can't find how to configure the connection to the postgresql server.
As far as I understand the app engine instances run the cloud SQL proxy but I keep getting the following error inside the instance: [error] Postgrex.Protocol (#PID<0.232.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
In the Google Cloud console, go to the Cloud SQL Instances page. To open the Overview page of an instance, click the instance name. Select Connections from the SQL navigation menu. In the Authorized networks section, click Add network and enter the IP address of the machine where the client is installed.
Because App Engine and Compute Engine use the same networking infrastructure, you can use the VPN connection to establish a connection between the App Engine app and your on-premises database using the database server's internal IP address.
i'm getting the same errors with a phoenix/elixir app that i'm trying to move out of container engine and into app engine flexible environment, just can't figure out what to use as the hostname.
in my php app in app engine i can just use :/cloudsql/projectname:region:dbname
for the same database, but it doesn't seem to work that way for elixir
I also tried using the IP address of the cloud sql instance directly, but that wasn't working either.
in my app.yaml i have
env_variables:
MIX_ENV: staging
port: 8080
DB_ENV_POSTGRES_HOST: :/cloudsql/projectname:region:dbame
DB_ENV_POSTGRES_USER: userman
DB_ENV_POSTGRES_PASSWORD: password
and in conf/staging.exs
i have
config :guidebooks_api, GuidebooksApi.Repo,
adapter: Ecto.Adapters.Postgres,
username: System.get_env("DB_ENV_POSTGRES_USER") || "postgres",
password: System.get_env("DB_ENV_POSTGRES_PASSWORD") || "postgres",
hostname: System.get_env("DB_ENV_POSTGRES_HOST") || "localhost",
database: "databasename",
pool_size: 10,
types: GuidebooksApi.PostgresTypes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With