Connect to Google Cloud Cloud from an App Engine Instance

I want to run the elixir application in a flexible environment of the Google engine.

I also have a postgresql server running on Google Cloud SQL.

I can deploy the application inside the docker container. The problem is that I cannot find how to configure the connection to the postgresql server.

As far as I understand, application kernel instances start the SQL Cloud proxy, but I continue to receive the following error inside the instance: [error] Postgrex.Protocol (# PID <0.232.0>) could not connect: ** (DBConnection.ConnectionError) tcp connect (localhost: 5432): connection reject -: econnrefused

+4
source share
1 answer

I get the same errors with the phoenix / elixir application that I try to exit the container and into the flexible environment of the application engine, I just can’t figure out what to use as the host name.

in my application php in the application engine i can just use :/cloudsql/projectname:region:dbnamefor the same database but it doesn't seem to work for elixir

I also tried directly using the IP address of the sql sql instance, but it didn't work 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.exsi

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
0
source

Source: https://habr.com/ru/post/1677094/


All Articles