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 <felix.malfait@gmail.com>
This commit is contained in:
Anders Borch
2023-05-03 11:34:10 +02:00
committed by GitHub
parent 27070b374e
commit f28edd405f
12 changed files with 162 additions and 14 deletions

View File

@@ -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"
}

6
.devcontainer/init.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y postgresql-client

1
.gitignore vendored
View File

@@ -1,4 +1,3 @@
.vscode/*
**/**/.env
**/**/.npmrc
.DS_Store

8
.vscode/clean.sh vendored Executable file
View File

@@ -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

6
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers",
"ms-vscode.makefile-tools"
]
}

5
.vscode/logs.sh vendored Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
cd "$(dirname "$0")/../infra/dev"
docker-compose logs -f

48
.vscode/tasks.json vendored Normal file
View File

@@ -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
}
}
]
}

34
.vscode/up.sh vendored Executable file
View File

@@ -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

5
front/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"recommendations": [
"esbenp.prettier-vscode"
]
}

View File

@@ -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

View File

@@ -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

21
twenty.code-workspace Normal file
View File

@@ -0,0 +1,21 @@
{
"folders": [
{
"path": "front"
},
{
"path": "hasura"
},
{
"path": "server"
},
{
"path": "docs"
},
{
"path": ".",
"name": "root"
}
]
}