Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import Schema.sql with Hasura docker-compose #12

Closed
mnlbox opened this issue Jan 23, 2019 · 11 comments
Closed

How to import Schema.sql with Hasura docker-compose #12

mnlbox opened this issue Jan 23, 2019 · 11 comments

Comments

@mnlbox
Copy link

mnlbox commented Jan 23, 2019

Hi @tirumaraiselvan,

I install Hasura with docker-compose and want to do step bu step to implement this example app.
Can you guide me how to import Schema.sql with Hasura docker-compose?
In this example guide you work with a local Postgres.

/CC: @wawhal, @surendran82

@tirumaraiselvan
Copy link
Collaborator

Hey @mnlbox

Do you have access to your Postgres db?

@mnlbox
Copy link
Author

mnlbox commented Jan 23, 2019

@tirumaraiselvan I run my Hasura instance with this guide:
https://docs.hasura.io/1.0/graphql/manual/getting-started/docker-simple.html

How we can access to this Postgres? 🤔

@tirumaraiselvan
Copy link
Collaborator

@mnlbox Ah! Seems like the Postgres container is not exposed to localhost in docker-compose manifest. We will fix it.

In the meanwhile, you can go to Hasura console -> Data tab -> Run SQL and copy paste the contents of schema.sql there. And execute.

@mnlbox
Copy link
Author

mnlbox commented Jan 23, 2019

@tirumaraiselvan Thanks man.
Maybe related: hasura/graphql-engine#1424

@tirumaraiselvan
Copy link
Collaborator

tirumaraiselvan commented Jan 23, 2019 via email

@mnlbox
Copy link
Author

mnlbox commented Jan 23, 2019

Thanks @tirumaraiselvan I think expose Postgres and pgAdmin to local can be useful for this purpose 😉
Your temp solution (run SQL in Hasura console working well).

@tirumaraiselvan
Copy link
Collaborator

Resolved

@mnlbox
Copy link
Author

mnlbox commented Feb 25, 2019

@tirumaraiselvan Can you guide a little?

@tirumaraiselvan
Copy link
Collaborator

@mnlbox You can use pgadmin like here: https://github.com/hasura/graphql-engine/blob/master/install-manifests/docker-compose-pgadmin/docker-compose.yaml

Or you can use network: host in your docker-compose.yaml and connect to psql directly on port 5432

@jordanmkoncz
Copy link

jordanmkoncz commented Aug 15, 2019

For anyone else who has the same question as @mnlbox, I found a fairly easy way to achieve this.

  1. Clone the https://github.com/hasura/3factor-example repository
  2. Add docker-compose.yaml to the repository root (see code below)
  3. Run docker-compose up -d
  4. Run docker exec -i 3factor_postgres psql -U postgres postgres < schema.sql

docker-compose.yaml:

version: '3.7'
services:
  postgres:
    image: "postgres:11.5"
    container_name: "3factor_postgres"
    ports:
    - "5432:5432"
    restart: always
    volumes:
    - db_data:/var/lib/postgresql/data
  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-beta.4
    container_name: "3factor_hasura"
    ports:
    - "8080:8080"
    depends_on:
    - "postgres"
    restart: always
    environment:
      HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:@postgres:5432/postgres
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      ## uncomment next line to set an admin secret
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
volumes:
  db_data:

With Hasura and Postgres running via this docker-compose.yaml configuration, when you want to run the Express server as part of https://github.com/jordanmkoncz/3factor-example#step-3-local-development (node localDevelopment.js), in your terminal you should first run:

export POSTGRES_CONNECTION_STRING='postgres://postgres:@localhost:5432/postgres'

Side note: if you decide to run the 3factor-example project like this, you will probably run into an issue where the event triggers fail. In the event response, I was seeing an error of ConnectionFailure Network.Socket.connect: <socket: 27>: does not exist (Connection refused). This happens because the webhooks are pointing to localhost, e.g. http://localhost:8081/validate-order, and Hasura which is running from the Docker container is not able to connect to the Express server (node localDevelopment.js) running directly on localhost (not in Docker).

The solution is to modify the event triggers so that Hasura within the Docker container can connect to the Express server on localhost, which is discussed in https://docs.hasura.io/1.0/graphql/manual/deployment/docker/index.html#network-config. On macOS, the event trigger would be updated by replacing localhost with host.docker.internal, and on Windows replacing it with docker.for.win.localhost, e.g. the new event trigger would point to http://host.docker.internal:8081/validate-order. You'll need to make this change for all event triggers.

@jordanmkoncz
Copy link

I've made a fork that includes all of the above changes (and some other fixes for this project) and submitted a pull request at #17. Feel free to use this fork if you'd prefer to use a docker-compose.yaml configuration and to run both Hasura and Postgres via Docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants