0

I'm using Hasura's 'one-click' deploy to Digital Ocean. The postgres instance works great, but I'm using NextAuth.js to authenticate users. The postgres instance isn't accessible via Nextauth.

This is my docker-compose file:

version: '3.6'
services:
  postgres:
    image: postgres:12
    restart: always
    ports:
    - "5432:5432"
    volumes:
    - db_data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: postgrespassword
  graphql-engine:
    image: hasura/graphql-engine:v1.3.3
    depends_on:
    - "postgres"
    restart: always
    environment:
      # database url to connect
      HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
      ## enable the console served by server
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set "false" to disable console
      ## enable debugging mode. It is recommended to disable this in production
      HASURA_GRAPHQL_DEV_MODE: "true"
      ## uncomment next line to set an admin secret
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
    command:
    - graphql-engine
    - serve
  caddy:
    image: caddy/caddy
    depends_on:
    - "graphql-engine"
    restart: always
    ports:
    - "80:80"
    - "443:443"
    volumes:
    - ./Caddyfile:/etc/caddy/Caddyfile
    - caddy_certs:/root/.caddy
volumes:
  db_data:
  caddy_certs:

And this is what running docker-compose ps shows in the terminal:

         Name                        Command               State                         Ports                       
---------------------------------------------------------------------------------------------------------------------
hasura_caddy_1            caddy run --config /etc/ca ...   Up      2019/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
hasura_graphql-engine_1   graphql-engine serve             Up                                                        
hasura_postgres_1         docker-entrypoint.sh postgres    Up      5432/tcp                

As you can see from the docker-compose file, I've tried mapping the ports. I've also tried going into /var/lib/docker/containers/<container_hash> and editing the hostconfig.json to bind ports, with no success. Further, I've tried editing the postgresql.conf to accept all IPs with no success.

This is what I pass in the database value to NextAuth:

"postgres://postgres:postgrespassword@<DROPLET'S_IP>:5432/postgres"

There's no errors visible, but the user isn't generated in the DB, thus my guess that there's no connection. NextAuth doesn't log any errors to the console.

And if I try to connect using psql from the command line using the following, the connection times out.

psql -h <DROPLET_IP> -p 5432 -d postgres -U postgres

I've also found that Hasura's droplet comes with ufw as a firewall and blocks traffic on all ports except 80 and 22, but even after adding in port 5432, there's no improvement.

Clearly, I know nothing about Docker or containers. I'm looking forward to someone telling me what simple, obvious mistake I've made.

Thanks!

robdominguez
  • 118
  • 7
  • Is there a DO firewall setting? – Abraham Labkovsky Jan 28 '21 at 14:47
  • Have you made any modifications to the Caddyfile to attempt and expose Postgres through the proxy that it manages? – Jesse Carter Jan 28 '21 at 19:54
  • @AbrahamLabkovsky, there was ufw on the droplet itself, but I saw no DO-specific settings. – robdominguez Jan 29 '21 at 00:59
  • @JesseCarter, Docker is way out of my wheelhouse; what modifications would I be making? I attempted to use the `-expose` option on the `docker-compose` file, but that didn't appear to do anything. FWIW, I did a parallel deployment via Heroku, so this isn't pressing. But, I'm sure _someone_ will run into similar issues with DO. – robdominguez Jan 29 '21 at 01:01
  • Caddy's configuration is managed in a file on your Droplet called Caddyfile you can see it referenced in the volumes section of docker compose. /etc/caddy/Caddyfile. Please share the contents of this file – Jesse Carter Jan 29 '21 at 03:49

0 Answers0