Configure @db and @port
Closed this issue · 6 comments
Hello,
Is it possible to make the connectionString configurable with environnement variable to specify db address and db port if we want to use an existing postgres database ?
Regards
you can provide a full psql connection uri to override the defaults now
Can't seem to get this to work with the docker container using a custom host/port.
In .env
(loaded by compose):
PSQL_CONNECTION="postgresql://expanse:PASSWORD@postgres:5432/expanse"
The error:
expanse_1 | > RUN=prod PORT=1301 node ./controller/server.mjs
expanse_1 |
expanse_1 | node:internal/process/esm_loader:97
expanse_1 | internalBinding('errors').triggerUncaughtException(
expanse_1 | ^
expanse_1 |
expanse_1 | Error: connect ECONNREFUSED 127.0.0.1:5432
expanse_1 | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16) {
expanse_1 | errno: -111,
expanse_1 | code: 'ECONNREFUSED',
expanse_1 | syscall: 'connect',
expanse_1 | address: '127.0.0.1',
expanse_1 | port: 5432
expanse_1 | }
just tested it with a remote db (having a custom hostspec), it does work. likely not an issue with expanse.
in the past when i encountered the ECONNREFUSED error it was because the db specified by the connection uri could not be reached. please double check that the uri is defined correctly, and/or attempt to connect to your db manually (outside of expanse) to confirm that it is reachable.
In
.env
(loaded by compose):
and the env file must be named .env_prod
, not .env
. not sure if you were just being brief there or you actually named it .env
!
@jc9108
Thanks for taking a look, sorry for the delay.
I'm not using quite the same compose configuration.
Basically I have a bunch of services that use the same postgres container.
Expanse compose configuration:
expanse:
depends_on:
- postgres
image: ghcr.io/jc9108/expanse:latest
working_dir: /app/
networks:
- expanse
labels:
- host=expanse
- traefik.http.routers.expanse.tls=true
- traefik.http.services.expanse.loadbalancer.server.port=1301
environment:
- VERSION=1.0.3
env_file:
- .env.expanse
entrypoint: []
command: sh -c "wait-for-it postgres:5432 -t 0 && cd ./backend/ && npm run prod"
restart: on-failure
Which loads .env.expanse
:
# you can change these if you want
PSQL_CONNECTION="postgresql://expanse:[redacted]@postgres:5432/expanse" # optional psql connection uri. if you provide this, expanse will use it instead of the above vars
# go to https://www.reddit.com/prefs/apps ➔ "create another app..." ➔ name: "expanse", type: "web app", redirect uri: "http://localhost:1301/callback". then fill in these values
REDDIT_USERNAME="[redacted]" # your reddit username
REDDIT_APP_ID="[redacted]" # after you create the app, you will see it's id right under "web app"
REDDIT_APP_SECRET="[redacted]" # after you create the app, you will see this value
REDDIT_APP_REDIRECT="[redacted]" # use this default value for LAN usage. if you are serving the app publicly, change it to "https://{your_public_domain}/callback"
# fill in username(s) (case-sensitive) separated by ", " (a comma AND a space) in the quotes. use "*" to allow or deny all, except usernames in the other list
ALLOWED_USERS="*"
DENIED_USERS="*"
# fill each of these with a 30+ character secure string. e.g., you can generate it using `pwgen -scn 30 1`
SESSION_SECRET="[redacted]"
ENCRYPTION_KEY="[redacted]"
Which when started returns:
expanse_1 | > prod
expanse_1 | > RUN=prod PORT=1301 node ./controller/server.mjs
expanse_1 |
expanse_1 | node:internal/process/esm_loader:97
expanse_1 | internalBinding('errors').triggerUncaughtException(
expanse_1 | ^
expanse_1 |
expanse_1 | Error: connect ECONNREFUSED 127.0.0.1:5432
expanse_1 | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16) {
expanse_1 | errno: -111,
expanse_1 | code: 'ECONNREFUSED',
expanse_1 | syscall: 'connect',
expanse_1 | address: '127.0.0.1',
expanse_1 | port: 5432
expanse_1 | }
Yet, installing psql
inside the expanse container and connecting with the connection string works fine
The error suggests it's incorrectly trying to connect to localhost instead of postgres
(which resolves to a docker IP).
well, apparently it is resolving to localhost, not a docker ip then. expanse just uses the provided connection string exactly as it is given, you can see here::
https://github.com/jc9108/expanse/blob/54637636f4f564806fbff0328d6da983c299e70e/backend/model/sql.mjs#L4
as for why, im not sure. i was going to say your postgres container and expanse container might not be connected to the same network, but you manually tested the connection already. all i can say is it works with the default compose config, so prob something with your setup. i cant tell what it is from the info so far, sorry