运行 Hasura 控制台无法从 docker 运行

时间:2021-04-10 19:08:17

标签: docker graphql hasura

我有一个通过 docker-compose up 运行的 ruby​​ on rails 应用程序。我是 graphql 和 hasura 的完全菜鸟,我尝试了不同的方法来配置我的 docker,但我无法让它工作。

我的 docker-compose.yml:

    version: '3.6'

    services:
      postgres:
        image: postgis/postgis:latest
        restart: always
        ports:
        - "5434:5432"
        volumes:
        - ./init.sql:/docker-entrypoint-initdb.d/init.sql
        environment:
          PG_HOST_AUTH_METHOD: "trust"
          
      graphql-engine:
        image: hasura/graphql-engine:v1.2.2.cli-migrations-v2
        restart: always
        ports:
        - "8081:8080"
        volumes:
          - ./metadata:/hasura-metadata
        environment:
          HSR_GQL_DB_URL: "postgres://postgres@postgres/db-dev-name"
          HSR_GQL_ADMIN_SECRET: secret
        env_file:
          - .env
          
      server:
        build: .
        depends_on:
        - "postgres"
        command: bundle exec rails server -p 8081 -b 0.0.0.0
        ports:
          - "8080:8081"
        volumes:
          - ./:/server
          - gem_cache:/usr/local/bundle/gems
          - node_modules:/server/node_modules
        env_file:
          - .env
          
    volumes:
      gem_cache:
      node_modules:

config.yml:

    version: 2
    endpoint: http://localhost:8080
    metadata_directory: metadata
    actions:
      kind: synchronous
      handler_webhook_baseurl: http://localhost:8080

Docker 日志服务器显示:

Listening on tcp://0.0.0.0:8081

我可以在 http://localhost:8080/server/ docker-compose up 后访问应用程序

检查数据库连接,它也可以在数据库管理器 GUI 中的端口 :5434 上访问。

但是当我尝试执行 hasura console --admin-secret secret 时,浏览器上的 hasura 控制台没有显示。我只是在不同的日志上收到此错误:

  • docker 日志服务器:
    Started POST "//v1/query" for 172.25.0.1 at 2021-04-10 17:53:08 +0000
          
    ActionController::RoutingError (No route matches [POST] "/v1/query")
  • docker 记录 postgresql:
17:27:33.453 UTC [1] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
17:27:33.453 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
17:27:33.453 UTC [1] LOG:  listening on IPv6 address "::", port 5432
17:27:33.459 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
17:27:33.467 UTC [103] LOG:  database system was shut down at 2021-04-10 17:27:33 UTC
17:27:33.473 UTC [1] LOG:  database system is ready to accept connections
17:27:41.250 UTC [111] ERROR:  duplicate key value violates unique constraint "pg_extension_name_index"
17:27:41.250 UTC [111] DETAIL:  Key (extname)=(postgis) already exists.
17:27:41.250 UTC [111] STATEMENT:  CREATE EXTENSION IF NOT EXISTS postgis
17:27:47.565 UTC [116] ERROR:  duplicate key value violates unique constraint "pg_extension_name_index"
17:27:47.565 UTC [116] DETAIL:  Key (extname)=(pgcrypto) already exists.
17:27:47.565 UTC [116] STATEMENT:  CREATE EXTENSION IF NOT EXISTS "pgcrypto"
17:28:01.619 UTC [128] ERROR:  duplicate key value violates unique constraint "acct_status_pkey"
17:28:01.619 UTC [128] DETAIL:  Key (status)=(new) already exists.
17:28:01.619 UTC [128] STATEMENT:  INSERT INTO "acct_status" ("status") VALUES ($1) RETURNING "status"
  • docker 记录 graphql-engine:最后几行。
{"kind":"event_triggers","info":"preparing data"}}
{"type":"startup","timestamp":"2021-04-10T17:28:15.576+0000","level":"info","detail":{"kind":"event_triggers","info":"starting workers"}}
{"type":"startup","timestamp":"2021-04-10T17:28:15.576+0000","level":"info","detail":{"kind":"telemetry","info":"Help us improve Hasura! The graphql-engine server collects anonymized usage stats which allows us to keep improving Hasura at warp speed. To read more or opt-out, visit https://hasura.io/docs/1.0/graphql/manual/guides/telemetry.html"}}
{"type":"startup","timestamp":"2021-04-10T17:28:15.576+0000","level":"info","detail":{"kind":"server","info":{"time_taken":2.384872458,"message":"starting API server"}}}

我尝试通过浏览器访问http://localhost:8081//console/api-explorer,似乎graphql容器收到了请求,但仍然无法显示hasura控制台

{
    "type": "http-log",
    "timestamp": "2021-04-12T03:24:24.399+0000",
    "level": "error",
    "detail": {
        "operation": {
            "error": {
                "path": "$",
                "error": "resource does not exist",
                "code": "not-found"
            },
            "request_id": "6d1e5f04-f7d4-48d6-932e-4cf81bdf9795",
            "response_size": 65,
            "raw_query": ""
        },
        "http_info": {
            "status": 404,
            "http_version": "HTTP/1.1",
            "url": "/console/api-explorer",
            "ip": "192.168.0.1",
            "method": "GET",
            "content_encoding": null
        }
    }

我已经尝试将 HSR_GQL_DB_URL 设置为 postgres / localhost:5432 以及 postgis:// 而不是 postgres://。 我也尝试将 config.yml 端点字段更改为 http://localhost:8080/server/ 但这些也不起作用。

1 个答案:

答案 0 :(得分:0)

也许有点晚了,但无论如何:

根据 GraphQL engine server config reference -> Command config 下的文档,您需要设置 HASURA_GRAPHQL_ENABLE_CONSOLE 环境变量以启用在 /console 处提供的控制台。或者,对于 hasura serve 命令,将 --enable-console 选项设置为 true

<块引用>
<头>
旗帜 环境变量 说明
... ... ...
--enable-console <true|false> HASURA_GRAPHQL_ENABLE_CONSOLE 启用 Hasura 控制台(由 //console 上的服务器提供服务)(默认值:false)
... ... ...

对于您的docker-compose.yml

...
      graphql-engine:
        image: hasura/graphql-engine:v1.2.2.cli-migrations-v2
        restart: always
        ports:
        - "8081:8080"
        volumes:
          - ./metadata:/hasura-metadata
        environment:
          HSR_GQL_DB_URL: "postgres://postgres@postgres/db-dev-name"
          HSR_GQL_ADMIN_SECRET: secret
          HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # add this
        env_file:
          - .env
...

我还在某处阅读以确保在 Docker 相关情况下使用环境变量时引用 truefalse 值。这对我有用,所以我会坚持下去。试试看。

相关问题