From 39ffb0f90bcd1cd6d74fee4637a56d6fbc79ca36 Mon Sep 17 00:00:00 2001 From: Anders Borch Date: Wed, 19 Apr 2023 13:04:21 +0200 Subject: [PATCH 1/2] Setup Hasura-auth locally --- hasura/metadata/databases/databases.yaml | 4 ++-- .../tables/public_workspaces.yaml | 0 .../{twenty => default}/tables/tables.yaml | 0 .../down.sql | 0 .../up.sql | 0 infra/dev/docker-compose.yml | 18 ++++++++++++++++++ infra/dev/hasura/Dockerfile | 6 +++++- infra/dev/hasura/entrypoint.sh | 11 +++++++++++ infra/dev/postgres/Dockerfile | 4 +++- infra/dev/postgres/init.sql | 17 ++++++++++++++++- 10 files changed, 55 insertions(+), 5 deletions(-) rename hasura/metadata/databases/{twenty => default}/tables/public_workspaces.yaml (100%) rename hasura/metadata/databases/{twenty => default}/tables/tables.yaml (100%) rename hasura/migrations/{twenty => default}/1681407878182_create_table_public_workspaces/down.sql (100%) rename hasura/migrations/{twenty => default}/1681407878182_create_table_public_workspaces/up.sql (100%) create mode 100755 infra/dev/hasura/entrypoint.sh diff --git a/hasura/metadata/databases/databases.yaml b/hasura/metadata/databases/databases.yaml index 52ba870eb..264a9908f 100644 --- a/hasura/metadata/databases/databases.yaml +++ b/hasura/metadata/databases/databases.yaml @@ -1,4 +1,4 @@ -- name: twenty +- name: default kind: postgres configuration: connection_info: @@ -6,4 +6,4 @@ from_env: HASURA_GRAPHQL_PG_DATABASE_URL isolation_level: read-committed use_prepared_statements: false - tables: "!include twenty/tables/tables.yaml" + tables: "!include default/tables/tables.yaml" diff --git a/hasura/metadata/databases/twenty/tables/public_workspaces.yaml b/hasura/metadata/databases/default/tables/public_workspaces.yaml similarity index 100% rename from hasura/metadata/databases/twenty/tables/public_workspaces.yaml rename to hasura/metadata/databases/default/tables/public_workspaces.yaml diff --git a/hasura/metadata/databases/twenty/tables/tables.yaml b/hasura/metadata/databases/default/tables/tables.yaml similarity index 100% rename from hasura/metadata/databases/twenty/tables/tables.yaml rename to hasura/metadata/databases/default/tables/tables.yaml diff --git a/hasura/migrations/twenty/1681407878182_create_table_public_workspaces/down.sql b/hasura/migrations/default/1681407878182_create_table_public_workspaces/down.sql similarity index 100% rename from hasura/migrations/twenty/1681407878182_create_table_public_workspaces/down.sql rename to hasura/migrations/default/1681407878182_create_table_public_workspaces/down.sql diff --git a/hasura/migrations/twenty/1681407878182_create_table_public_workspaces/up.sql b/hasura/migrations/default/1681407878182_create_table_public_workspaces/up.sql similarity index 100% rename from hasura/migrations/twenty/1681407878182_create_table_public_workspaces/up.sql rename to hasura/migrations/default/1681407878182_create_table_public_workspaces/up.sql diff --git a/infra/dev/docker-compose.yml b/infra/dev/docker-compose.yml index 70ac45478..027786768 100644 --- a/infra/dev/docker-compose.yml +++ b/infra/dev/docker-compose.yml @@ -20,6 +20,7 @@ services: - "9693:9693" volumes: - ../../hasura:/hasura + - /hasura/entrypoints depends_on: - "postgres" restart: always @@ -29,6 +30,23 @@ services: HASURA_GRAPHQL_ENABLE_CONSOLE: "false" HASURA_GRAPHQL_DEV_MODE: "true" HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log + HASURA_GRAPHQL_ADMIN_SECRET: secret + HASURA_GRAPHQL_JWT_SECRET: '{"type":"HS256", "key": "jwt-very-long-hard-to-guess-secret"}' + hasura-auth: + image: nhost/hasura-auth:0.19.1 + ports: + - "4000:4000" + environment: + HASURA_GRAPHQL_JWT_SECRET: '{"type":"HS256", "key": "jwt-very-long-hard-to-guess-secret"}' + HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/twenty + HASURA_GRAPHQL_GRAPHQL_URL: http://twenty-hasura:8080/v1/graphql + HASURA_GRAPHQL_ADMIN_SECRET: secret + npm_package_version: '0' + AUTH_SMTP_HOST: mailhog + AUTH_SMTP_PORT: 1025 + depends_on: + - "twenty-hasura" + - "postgres" twenty-server: build: context: ../.. diff --git a/infra/dev/hasura/Dockerfile b/infra/dev/hasura/Dockerfile index bc86e41b7..d7523df67 100644 --- a/infra/dev/hasura/Dockerfile +++ b/infra/dev/hasura/Dockerfile @@ -8,4 +8,8 @@ RUN curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bas WORKDIR /hasura -CMD ["sh", "-c", "graphql-engine serve"] +RUN mkdir entrypoints +COPY ./entrypoint.sh ./entrypoints/entrypoint.sh + +ENTRYPOINT ["entrypoints/entrypoint.sh"] + diff --git a/infra/dev/hasura/entrypoint.sh b/infra/dev/hasura/entrypoint.sh new file mode 100755 index 000000000..3b4503acd --- /dev/null +++ b/infra/dev/hasura/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +graphql-engine serve & + +while ! curl -s http://localhost:8080/healthz > /dev/null ; do + sleep 1 +done + +hasura deploy + +wait \ No newline at end of file diff --git a/infra/dev/postgres/Dockerfile b/infra/dev/postgres/Dockerfile index 0a2f10315..75ddc042d 100644 --- a/infra/dev/postgres/Dockerfile +++ b/infra/dev/postgres/Dockerfile @@ -1,3 +1,5 @@ FROM postgres:13.7 as postgres -COPY init.sql /docker-entrypoint-initdb.d/ \ No newline at end of file +RUN apt update && apt install -y curl + +COPY init.sql /docker-entrypoint-initdb.d/ diff --git a/infra/dev/postgres/init.sql b/infra/dev/postgres/init.sql index 30a091e62..b53c8220a 100644 --- a/infra/dev/postgres/init.sql +++ b/infra/dev/postgres/init.sql @@ -1,2 +1,17 @@ CREATE DATABASE twenty; -CREATE DATABASE hasura; \ No newline at end of file +CREATE DATABASE hasura; + +-- From: https://raw.githubusercontent.com/nhost/hasura-auth/main/docker/initdb.d/0001-create-schema.sql +\c twenty; +-- auth schema +CREATE SCHEMA IF NOT EXISTS auth; +-- https://github.com/hasura/graphql-engine/issues/3657 +CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public; +CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public; +CREATE OR REPLACE FUNCTION public.set_current_timestamp_updated_at() RETURNS trigger LANGUAGE plpgsql AS $$ +declare _new record; +begin _new := new; +_new."updated_at" = now(); +return _new; +end; +$$; \ No newline at end of file From 3cea61d9ed88f8d908201081e705d9664192ea97 Mon Sep 17 00:00:00 2001 From: Anders Borch Date: Wed, 19 Apr 2023 17:51:15 +0200 Subject: [PATCH 2/2] Add mailhog for local smtp --- infra/dev/docker-compose.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/infra/dev/docker-compose.yml b/infra/dev/docker-compose.yml index 027786768..f6d8fe0fc 100644 --- a/infra/dev/docker-compose.yml +++ b/infra/dev/docker-compose.yml @@ -47,6 +47,19 @@ services: depends_on: - "twenty-hasura" - "postgres" + - "mailhog" + mailhog: + image: jcalonso/mailhog + environment: + SMTP_HOST: mailhog + SMTP_PORT: 1025 + SMTP_PASS: smtp-secret + SMTP_USER: smtp-user + SMTP_SECURE: "false" + SMTP_SENDER: auth@localhost + ports: + - "1025:1025" + - "8025:8025" twenty-server: build: context: ../..