dcaputo-harmoni / open-balena-admin

Open Balena Admin
MIT License
90 stars 18 forks source link

Postgrest cannot translate hostname, resulting in database connection error #1

Closed saveriogzz closed 2 years ago

saveriogzz commented 2 years ago

Hi @dcaputo-harmoni ! Thanks a lot for the amazing project, I'm very much interested in using and contributing to it!

I am trying to start up the open-balena-admin project locally while having a running instance of openBalena running in a remote server. When starting up the admin with the command open-balena-admin/scripts/compose up at point 6, I'm receiving the error

ERROR: Network openbalena_default declared as external, but could not be found. Please create the network manually using `docker network create openbalena_default` and try again.

I guess I'm doing something wrong when editing /etc/hosts... I tried different combinations of the hosts settings, my last attempt looks like this:

127.0.0.1 my-domain.something.somewhere
127.0.0.1 api.my-domain.something.somewhere
127.0.0.1 registry.my-domain.something.somewhere
127.0.0.1 vpn.my-domain.something.somewhere
...

Would you possibly know what I am doing wrong? Thanks!

saveriogzz commented 2 years ago

I was a bit rushed in opening the issue.. sorry! I started up the project in the same server where I have my openBalena instance and it starts up; however, I'm now encountering a second issue: in the logs of the server postgrest, I get

28/Mar/2022:17:34:54 +0000: {"details":"could not translate host name \"db.openbalena.local\" to address: Name does not resolve\n","code":"","message":"Database connection error. Retrying the connection."}

I wouldn't know the reason for it.

Not sure if this are related, but should I change the DOMAIN in open-balena-admin/scripts/quickstart as being the same as the variable 'OPENBALENA_HOST_NAME' in my openBalena activate file?

dcaputo-harmoni commented 2 years ago

Hi @saveriogzz, I'm glad you are interested in the project! Regarding your issue, it looks like the postgrest container is not able to resolve the db container. Postgrest communicates with the DB internally, and the docker container that postgrest is running needs to be able to resolve the db hostname. Do you happen to know what hostname your openbalena db is running on?

The postgrest container sets the db hostname as db.${OPENBALENA_HOST_NAME} - so in your case, you must have built open-balena-admin using the (default) openbalena.local as your hostname. Is this correct? if not, you should use -d DOMAIN in the quickstart script to specify the correct domain. And if you want to test it, you can docker exec into your postgrest container and try to ping the db host. Hope this helps.

saveriogzz commented 2 years ago

It was indeed solved by using my domain in the variable OPENBALENA_HOST_NAME in the quickstart script! Now, the issue is that the admin is not fetching anything from the openBalena instance, but I'll open another issue for that :wink: :beers: