0

Hi I am trying to deploy a grafana docker container to a google app engine flex. Grafana will use postgresql (cloud sql) as internal database.

I am currently using this Dockefile:

FROM grafana/grafana:latest
ENV GF_SERVER_HTTP_PORT 8080
ENV GF_DATABASE_URL postgres://postgres:passwd@127.0.0.1:5432/grafana
ENV GF_DATABASE_TYPE postgres
EXPOSE 8080

and this app.yaml:

runtime: custom
env: flex
service: grafana
beta_settings:
  cloud_sql_instances: miproj:europe-west1:midb=tcp:5432

I have also activated the Cloud SQL Admin API

After doing

gcloud app deploy

however I get

 msg="Server shutdown" logger=server reason="Service init failed: Migration failed err: dial tcp 127.0.0.1:5432: connect: connection refused"

I have also tried

cloud_sql_instances: miproj:europe-west1:midb

and

ENV GF_DATABASE_URL postgres://postgres:passwd@/cloudsql/miproj:europe-west1:midb:5432/grafana

but I get

t=2019-05-09T10:12:56+0000 lvl=eror msg="Server shutdown" logger=server reason="Service init failed: Migration failed err: dial tcp: lookup port=5432: no such host"

but I think this might be more a problem of how grafana parses a connection chain which has ":" in the middle of the host name.

Any ideas of what am I doing wrong?

jartieda
  • 1
  • 1

1 Answers1

0

There are 2 options to connect to Postgresql from App Engine. You can either connect through TCP or via Unix Sockets. App Engine flex supports both, standard supports only sockets. When I look at your app.yaml, it looks like you already set up the correct connection name for a TCP connection.

On the other hand, the connection string you are using as an environment variable seems to be wrong. Change this:

postgres://postgres:passwd@/cloudsql/miproj:europe-west1:midb:5432/grafana

To:

postgres://postgres:passwd@172.17.0.1:5432/grafana

Docker uses 172.17.0.1 as a loopback address instead of 127.0.0.1! A detailed overview can be found on Google's cloudsql doc.