From 34543b7fea0f95bca75e1e9e47580a689ab28fb6 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Thu, 25 May 2023 15:56:28 +0200 Subject: [PATCH] Simplify local dev (#137) --- .devcontainer/devcontainer.json | 20 +++----- .devcontainer/init.sh | 5 +- .gitignore | 4 +- .vscode/clean.sh | 8 ---- .vscode/logs.sh | 5 -- .vscode/tasks.json | 48 ------------------- .vscode/up.sh | 18 ------- .../dev-docs/getting-started/local-setup.mdx | 2 +- front/package.json | 2 +- infra/dev/Makefile | 47 ++++++++++-------- infra/dev/docker-compose.yml | 18 ++----- infra/dev/server/Dockerfile | 19 -------- infra/dev/{front => twenty-dev}/Dockerfile | 13 ++++- infra/dev/{docs => twenty-docs}/Dockerfile | 0 .prettierignore => server/.prettierignore | 0 server/package.json | 3 +- twenty.code-workspace | 18 ------- 17 files changed, 59 insertions(+), 171 deletions(-) delete mode 100755 .vscode/clean.sh delete mode 100755 .vscode/logs.sh delete mode 100644 .vscode/tasks.json delete mode 100755 .vscode/up.sh delete mode 100644 infra/dev/server/Dockerfile rename infra/dev/{front => twenty-dev}/Dockerfile (62%) rename infra/dev/{docs => twenty-docs}/Dockerfile (100%) rename .prettierignore => server/.prettierignore (100%) delete mode 100644 twenty.code-workspace diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b0b6f692b4..a4bc87dc5a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,10 @@ -// 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", +{ + "name": "Twenty Codespace", + "image": "node:18.16.0", "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": { - "version": "20.10", - "enableNonRootDocker": "true", - "moby": "true" - } + "ghcr.io/devcontainers-contrib/features/jshint:2": {} }, - "postCreateCommand": ".devcontainer/init.sh", - "postStartCommand": ".vscode/up.sh" -} + "forwardPorts": [3000, 3001, 5432], + "postCreateCommand": "cd front && npm install && cd ../server && npm install" + } \ No newline at end of file diff --git a/.devcontainer/init.sh b/.devcontainer/init.sh index b92b5fe20a..4be95e0f65 100755 --- a/.devcontainer/init.sh +++ b/.devcontainer/init.sh @@ -2,5 +2,6 @@ DEBIAN_FRONTEND=noninteractive -sudo apt-get update -sudo apt-get install -y postgresql-client +cd infra/dev +make build +make up \ No newline at end of file diff --git a/.gitignore b/.gitignore index d6acfd147f..581c1f8782 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ **/**/.env -**/**/.npmrc -.DS_Store -node_modules \ No newline at end of file +.DS_Store \ No newline at end of file diff --git a/.vscode/clean.sh b/.vscode/clean.sh deleted file mode 100755 index 48dc8c121b..0000000000 --- a/.vscode/clean.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/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/logs.sh b/.vscode/logs.sh deleted file mode 100755 index 99350e2faa..0000000000 --- a/.vscode/logs.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -cd "$(dirname "$0")/../infra/dev" - -docker-compose logs -f diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 3f8df02b09..0000000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "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 deleted file mode 100755 index 35559d2bbf..0000000000 --- a/.vscode/up.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/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 diff --git a/docs/docs/dev-docs/getting-started/local-setup.mdx b/docs/docs/dev-docs/getting-started/local-setup.mdx index 679d0c6864..e1fac4074f 100644 --- a/docs/docs/dev-docs/getting-started/local-setup.mdx +++ b/docs/docs/dev-docs/getting-started/local-setup.mdx @@ -15,7 +15,7 @@ Twenty development stack is composed of 3 different layers - server: our backend that contain endpoint, crm logic, scripts, jobs... - storages: postgres -## Setup env variables and npmrc variables +## Setup env variables `cp ./infra/dev/.env.example ./infra/dev/.env` and fill with values diff --git a/front/package.json b/front/package.json index 4723abf383..1bf27103ac 100644 --- a/front/package.json +++ b/front/package.json @@ -32,7 +32,7 @@ "build-storybook": "storybook build -s public", "coverage": "react-scripts test --coverage --watchAll", "coverage-ci": "react-scripts test --coverage --watchAll=false", - "graphql-codegen": "REACT_APP_GRAPHQL_ADMIN_SECRET=$REACT_APP_GRAPHQL_ADMIN_SECRET graphql-codegen --config codegen.js" + "graphql:generate": "REACT_APP_GRAPHQL_ADMIN_SECRET=$REACT_APP_GRAPHQL_ADMIN_SECRET graphql-codegen --config codegen.js" }, "eslintConfig": { "extends": [ diff --git a/infra/dev/Makefile b/infra/dev/Makefile index 2e78a99143..2388c0f731 100644 --- a/infra/dev/Makefile +++ b/infra/dev/Makefile @@ -1,32 +1,39 @@ -build: ## +build: @docker-compose down - docker volume rm dev_twenty_node_modules_front || true - docker volume rm dev_twenty_node_modules_server || true - docker volume rm dev_twenty_node_modules_docs || true - docker-compose build + @docker volume rm dev_twenty_node_modules_front > /dev/null 2>&1 || true + @docker volume rm dev_twenty_node_modules_server > /dev/null 2>&1 || true + @docker volume rm dev_twenty_node_modules_docs > /dev/null 2>&1 || true + @docker-compose build -up: ## +up: @docker-compose up -d -down: ## +down: @docker-compose down -## Front +sh: + @docker-compose exec twenty-dev sh -front-logs: ## - @docker-compose logs twenty-front -f +front-start: + @docker-compose exec twenty-dev sh -c "cd /app/front && npm run start" -front-sh: ## - @docker-compose exec twenty-front sh +front-test: + @docker-compose exec twenty-dev sh -c "cd /app/front && npm run test" -front-test: ## - @docker-compose exec twenty-front sh -c "npm run test" +front-graphql-generate: + @docker-compose exec twenty-dev sh -c "cd /app/server && npm run " -front-coverage: ## - @docker-compose exec twenty-front sh -c "npm run coverage" +front-storybook: + @docker-compose exec twenty-dev sh -c "cd /app/front && npm run storybook" -front-storybook: ## - @docker-compose exec twenty-front sh -c "npm run storybook" +server-start: + @docker-compose exec twenty-dev sh -c "cd /app/server && npm run start" -front-graphql-generate: ## - @docker-compose exec twenty-front sh -c "npm run graphql-generate" +server-prisma-generate: + @docker-compose exec twenty-dev sh -c "cd /app/server && npm run prisma:generate" + +server-prisma-migrate: + @docker-compose exec twenty-dev sh -c "cd /app/server && npm run prisma:migrate" + +server-prisma-seed: + @docker-compose exec twenty-dev sh -c "cd /app/server && npm run prisma:seed" diff --git a/infra/dev/docker-compose.yml b/infra/dev/docker-compose.yml index 8c98f91099..e8b25c70b0 100644 --- a/infra/dev/docker-compose.yml +++ b/infra/dev/docker-compose.yml @@ -1,32 +1,24 @@ version: "3.9" services: - twenty-front: + twenty-dev: build: context: ../.. - dockerfile: ./infra/dev/front/Dockerfile + dockerfile: ./infra/dev/twenty-dev/Dockerfile ports: + - "3000:3000" - "3001:3001" - "6006:6006" volumes: - ../../front:/app/front - - twenty_node_modules_front:/app/front/node_modules - depends_on: - - postgres - twenty-server: - build: - context: ../.. - dockerfile: ./infra/dev/server/Dockerfile - ports: - - "3000:3000" - volumes: - ../../server:/app/server + - twenty_node_modules_front:/app/front/node_modules - twenty_node_modules_server:/app/server/node_modules depends_on: - postgres twenty-docs: build: context: ../.. - dockerfile: ./infra/dev/docs/Dockerfile + dockerfile: ./infra/dev/twenty-docs/Dockerfile ports: - "5001:3000" volumes: diff --git a/infra/dev/server/Dockerfile b/infra/dev/server/Dockerfile deleted file mode 100644 index 139d879b7d..0000000000 --- a/infra/dev/server/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM node:18.16.0-alpine as server - -RUN apk update && apk upgrade && \ - apk add --no-cache bash git openssh && \ - apk add libc6-compat - -WORKDIR /app/server - -COPY ../../server/package.json . -COPY ../../server/package-lock.json . -RUN npm install - -COPY ../../server/src/database/schema.prisma ./src/database/schema.prisma -RUN npx prisma generate - -COPY ../../server . - - -CMD ["npm", "run", "start:dev"] \ No newline at end of file diff --git a/infra/dev/front/Dockerfile b/infra/dev/twenty-dev/Dockerfile similarity index 62% rename from infra/dev/front/Dockerfile rename to infra/dev/twenty-dev/Dockerfile index 34fa76c3dd..e03f1abf37 100644 --- a/infra/dev/front/Dockerfile +++ b/infra/dev/twenty-dev/Dockerfile @@ -15,4 +15,15 @@ RUN npm install COPY ../../front . -CMD ["npm", "run", "start"] +WORKDIR /app/server + +COPY ../../server/package.json . +COPY ../../server/package-lock.json . +RUN npm install + +COPY ../../server . +RUN npx prisma generate + +WORKDIR /app + +CMD ["tail", "-f", "/dev/null"] diff --git a/infra/dev/docs/Dockerfile b/infra/dev/twenty-docs/Dockerfile similarity index 100% rename from infra/dev/docs/Dockerfile rename to infra/dev/twenty-docs/Dockerfile diff --git a/.prettierignore b/server/.prettierignore similarity index 100% rename from .prettierignore rename to server/.prettierignore diff --git a/server/package.json b/server/package.json index 5adeae917f..8c76ffc449 100644 --- a/server/package.json +++ b/server/package.json @@ -20,7 +20,8 @@ "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json", "prisma:generate": "npx prisma generate", - "prisma:migrate": "npx prisma migrate deploy" + "prisma:migrate": "npx prisma migrate deploy", + "prisma:seed": "npx prisma db seed" }, "dependencies": { "@nestjs/apollo": "^10.0.5", diff --git a/twenty.code-workspace b/twenty.code-workspace deleted file mode 100644 index 50d313970d..0000000000 --- a/twenty.code-workspace +++ /dev/null @@ -1,18 +0,0 @@ -{ - "folders": [ - { - "path": "front" - }, - { - "path": "server" - }, - { - "path": "docs" - }, - { - "path": ".", - "name": "root" - - } - ] -} \ No newline at end of file