Closed16

mysql+hasura+nextjs with Dockerの組み合わせを試す

Happa8Happa8

mysql、hasura、nextjsをそれぞれDockerコンテナで管理しつつ入門してみる

Happa8Happa8

上記のQiitaの方の記事を参考に、次のように書いてみた

version: '3.9'
services:
  mysql:
    build: ./mysql
    volumes:
      - ./mysql/DB:/docker-entrypoint-initdb.d
    image: mysql_test
    container_name: mysql-container
    platform: linux/amd64
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: demo
      TZ: "Asia/Tokyo"
#使うDockerイメージ
FROM mysql

# ポート開放
EXPOSE 3306

# MySQLの設定ファイルをイメージ内にコピー
ADD ./my.cnf /etc/mysql/conf.d/my.cnf

# docker run時に実行
CMD [ "mysqld" ]

他は同じ

Happa8Happa8

Quickstartに従って落としてきたdocker-composeを読むと、どうやらpostgresqlが前提っぽい?
mysqlでやりたい

Happa8Happa8

と思ったけど、普通にposrgresのdb設定をさっき作ったmysqlのに変えればいいだけか
ついでに、docker-composeのversionを3.6にダウン(なんかhasuraのdocker-composeが3.6だから念のため)

Happa8Happa8

いや、なにか勘違いをしているようだ
hasuraのdocker-composeと一緒にやってきたpostgresqlは、hasura自体のデータを管理するためのDBであって、hasuraに接続したいDBとは別物らしい
ややこしいな

Happa8Happa8

結局こうなった

version: '3.6'
services:
  mysql:
    build: ./mysql
    volumes:
      - ./mysql/DB:/docker-entrypoint-initdb.d
    image: mysql_test
    container_name: mysql-container
    platform: linux/amd64
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: demo
      TZ: "Asia/Tokyo"
  postgres:
    image: postgres:15
    restart: always
    volumes:
      - db_data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: postgrespassword
  graphql-engine:
    image: hasura/graphql-engine:v2.36.0
    ports:
      - "8080:8080"
    restart: always
    environment:
      ## postgres database to store Hasura metadata
      HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
      ## this env var can be used to add the above postgres database to Hasura as a data source. this can be removed/updated based on your needs
      PG_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
      ## enable the console served by server
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
      ## enable debugging mode. It is recommended to disable this in production
      HASURA_GRAPHQL_DEV_MODE: "true"
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      ## uncomment next line to run console offline (i.e load console assets from server instead of CDN)
      # HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets
      ## uncomment next line to set an admin secret
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
      HASURA_GRAPHQL_METADATA_DEFAULTS: '{"backend_configs":{"dataconnector":{"athena":{"uri":"http://data-connector-agent:8081/api/v1/athena"},"mariadb":{"uri":"http://data-connector-agent:8081/api/v1/mariadb"},"mysql8":{"uri":"http://data-connector-agent:8081/api/v1/mysql"},"oracle":{"uri":"http://data-connector-agent:8081/api/v1/oracle"},"snowflake":{"uri":"http://data-connector-agent:8081/api/v1/snowflake"}}}}'
    depends_on:
      data-connector-agent:
        condition: service_healthy
  data-connector-agent:
    image: hasura/graphql-data-connector:v2.36.0
    restart: always
    ports:
      - 8081:8081
    environment:
      QUARKUS_LOG_LEVEL: ERROR # FATAL, ERROR, WARN, INFO, DEBUG, TRACE
      ## https://quarkus.io/guides/opentelemetry#configuration-reference
      QUARKUS_OPENTELEMETRY_ENABLED: "false"
      ## QUARKUS_OPENTELEMETRY_TRACER_EXPORTER_OTLP_ENDPOINT: http://jaeger:4317
    healthcheck:
      test:
        [
          "CMD",
          "curl",
          "-f",
          "http://localhost:8081/api/v1/athena/health"
        ]
      interval: 5s
      timeout: 10s
      retries: 5
      start_period: 5s
volumes:
  db_data:
このスクラップは2024/01/26にクローズされました