From f28edd405fd8e14bb991214109c03d64de54e0d5 Mon Sep 17 00:00:00 2001 From: Anders Borch Date: Wed, 3 May 2023 11:34:10 +0200 Subject: [PATCH] I can open the project in GitHub (#92) * Ignore node_modules * Use bash-compatible dotenv format While still being compatible with dotenv, this also allows sourcing the file to export all variables in bash. * Add prettier extension to recommendations * Move to port 5001 to avoid conflict with macOS services * Add workspace * Add devcontainer This automatically starts with all environment variables available locally. It brings up services which are dependent on each other individually and verifies health before moving on to the next service. * Split init into clean, up, and logs tasks. This allows the developer to set up .env and .npmrc files before running services, and does not require starting from a clean db every time the devcontainer is restarted. * Copy .env when creating codespace * Automatically run UP command upon devcontainer creation * Fix log message --------- Co-authored-by: Felix Malfait --- .devcontainer/devcontainer.json | 16 +++++++++++ .devcontainer/init.sh | 6 +++++ .gitignore | 1 - .vscode/clean.sh | 8 ++++++ .vscode/extensions.json | 6 +++++ .vscode/logs.sh | 5 ++++ .vscode/tasks.json | 48 +++++++++++++++++++++++++++++++++ .vscode/up.sh | 34 +++++++++++++++++++++++ front/.vscode/extensions.json | 5 ++++ infra/dev/.env.example | 24 ++++++++--------- infra/dev/docker-compose.yml | 2 +- twenty.code-workspace | 21 +++++++++++++++ 12 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/init.sh create mode 100755 .vscode/clean.sh create mode 100644 .vscode/extensions.json create mode 100755 .vscode/logs.sh create mode 100644 .vscode/tasks.json create mode 100755 .vscode/up.sh create mode 100644 front/.vscode/extensions.json create mode 100644 twenty.code-workspace diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..b0b6f692b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,16 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-in-docker +{ + "name": "Twenty", + "image": "mcr.microsoft.com/devcontainers/base:bullseye", + + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "version": "20.10", + "enableNonRootDocker": "true", + "moby": "true" + } + }, + "postCreateCommand": ".devcontainer/init.sh", + "postStartCommand": ".vscode/up.sh" +} diff --git a/.devcontainer/init.sh b/.devcontainer/init.sh new file mode 100755 index 000000000..b92b5fe20 --- /dev/null +++ b/.devcontainer/init.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +DEBIAN_FRONTEND=noninteractive + +sudo apt-get update +sudo apt-get install -y postgresql-client diff --git a/.gitignore b/.gitignore index 9c7242178..d6acfd147 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.vscode/* **/**/.env **/**/.npmrc .DS_Store diff --git a/.vscode/clean.sh b/.vscode/clean.sh new file mode 100755 index 000000000..48dc8c121 --- /dev/null +++ b/.vscode/clean.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd "$(dirname "$0")/../infra/dev" + +docker-compose down +docker volume rm dev_twenty_node_modules_front +docker volume rm dev_twenty_node_modules_server +docker volume rm dev_twenty_node_modules_docs diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..be44b8bfb --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-vscode-remote.remote-containers", + "ms-vscode.makefile-tools" + ] +} \ No newline at end of file diff --git a/.vscode/logs.sh b/.vscode/logs.sh new file mode 100755 index 000000000..99350e2fa --- /dev/null +++ b/.vscode/logs.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd "$(dirname "$0")/../infra/dev" + +docker-compose logs -f diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..3f8df02b0 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,48 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "up", + "command": "${workspaceFolder}/.vscode/up.sh", + "type": "shell", + "options": { + "cwd": "${workspaceFolder}/infra/dev/" + }, + "presentation": { + "reveal": "always", + "panel": "new", + "focus": true + } + }, + { + "label": "clean", + "command": "${workspaceFolder}/.vscode/clean.sh", + "type": "shell", + "options": { + "cwd": "${workspaceFolder}/infra/dev/" + }, + "presentation": { + "reveal": "always", + "panel": "new", + "focus": true + } + }, + { + "label": "logs", + "command": "docker-compose", + "args": [ + "logs", + "-f" + ], + "type": "shell", + "options": { + "cwd": "${workspaceFolder}/infra/dev/" + }, + "presentation": { + "reveal": "always", + "panel": "new", + "focus": true + } + } + ] +} \ No newline at end of file diff --git a/.vscode/up.sh b/.vscode/up.sh new file mode 100755 index 000000000..1de7c5af3 --- /dev/null +++ b/.vscode/up.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +cd "$(dirname "$0")/../infra/dev" + +cp .env.example .env + +set -o allexport; source .env; set +o allexport + +docker-compose up -d postgres + +while ! pg_isready -h localhost > /dev/null ; do + echo "Waiting for Postgres to be ready..." + sleep 1 +done + +echo "Postgres is accepting connections!" + +docker-compose up -d twenty-hasura + +while ! curl -s http://localhost:8080/healthz > /dev/null ; do + sleep 1 + echo "Waiting for Hasura to be ready..." +done + +docker-compose up -d hasura-auth + +while ! curl -s http://localhost:4000/healthz > /dev/null ; do + sleep 1 + echo "Waiting for Hasura Auth to be ready..." +done + +docker-compose exec twenty-hasura hasura deploy + +docker-compose up -d diff --git a/front/.vscode/extensions.json b/front/.vscode/extensions.json new file mode 100644 index 000000000..3433c01b0 --- /dev/null +++ b/front/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode" + ] +} \ No newline at end of file diff --git a/infra/dev/.env.example b/infra/dev/.env.example index e6e3087b9..46473ef4c 100644 --- a/infra/dev/.env.example +++ b/infra/dev/.env.example @@ -1,20 +1,20 @@ -HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/hasura -HASURA_GRAPHQL_PG_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/default -HASURA_GRAPHQL_ADMIN_SECRET: secret -HASURA_GRAPHQL_JWT_SECRET: '{"type":"HS256", "key": "jwt-very-long-hard-to-guess-secret"}' -HASURA_EVENT_HANDLER_URL: http://twenty-server:3000/hasura/events +HASURA_GRAPHQL_METADATA_DATABASE_URL=postgres://postgres:postgrespassword@postgres:5432/hasura +HASURA_GRAPHQL_PG_DATABASE_URL=postgres://postgres:postgrespassword@postgres:5432/default +HASURA_GRAPHQL_ADMIN_SECRET=secret +HASURA_GRAPHQL_JWT_SECRET='{"type":"HS256", "key": "jwt-very-long-hard-to-guess-secret"}' +HASURA_EVENT_HANDLER_URL=http://twenty-server:3000/hasura/events -HASURA_AUTH_SERVER_URL: http://localhost:4000 -HASURA_AUTH_CLIENT_URL: http://localhost:3001/auth/callback -HASURA_AUTH_PROVIDER_GOOGLE_CLIENT_ID: REPLACE_ME -HASURA_AUTH_PROVIDER_GOOGLE_CLIENT_SECRET: REPLACE_ME -HASURA_AUTH_GRAPHQL_URL: http://twenty-hasura:8080/v1/graphql +HASURA_AUTH_SERVER_URL=http://localhost:4000 +HASURA_AUTH_CLIENT_URL=http://localhost:3001/auth/callback +HASURA_AUTH_PROVIDER_GOOGLE_CLIENT_ID=REPLACE_ME +HASURA_AUTH_PROVIDER_GOOGLE_CLIENT_SECRET=REPLACE_ME +HASURA_AUTH_GRAPHQL_URL=http://twenty-hasura:8080/v1/graphql FRONT_REACT_APP_API_URL=http://localhost:8080 FRONT_REACT_APP_AUTH_URL=http://localhost:4000 FRONT_HASURA_GRAPHQL_ENDPOINT=http://twenty-hasura:8080/v1/graphql -SERVER_HASURA_EVENT_HANDLER_SECRET_HEADER: secret -SERVER_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/default +SERVER_HASURA_EVENT_HANDLER_SECRET_HEADER=secret +SERVER_DATABASE_URL=postgres://postgres:postgrespassword@postgres:5432/default POSTGRES_PASSWORD=postgrespassword \ No newline at end of file diff --git a/infra/dev/docker-compose.yml b/infra/dev/docker-compose.yml index 8275acb64..583689b0d 100644 --- a/infra/dev/docker-compose.yml +++ b/infra/dev/docker-compose.yml @@ -92,7 +92,7 @@ services: context: ../.. dockerfile: ./infra/dev/docs/Dockerfile ports: - - "5000:3000" + - "5001:3000" volumes: - ../../docs:/app/docs - twenty_node_modules_docs:/app/docs/node_modules diff --git a/twenty.code-workspace b/twenty.code-workspace new file mode 100644 index 000000000..394d67054 --- /dev/null +++ b/twenty.code-workspace @@ -0,0 +1,21 @@ +{ + "folders": [ + { + "path": "front" + }, + { + "path": "hasura" + }, + { + "path": "server" + }, + { + "path": "docs" + }, + { + "path": ".", + "name": "root" + + } + ] +} \ No newline at end of file