Skip to content

Commit

Permalink
Fix docker install (twentyhq#2925)
Browse files Browse the repository at this point in the history
* Fix docker install

* Move back twenty-eslint-plugin to eslint-plugin-twenty

* fix: add bundled yarn

* Improve makeifle structure

* Update commands and doc

* Add pg_graphql binaries

* Fix

---------

Co-authored-by: Jérémy Magrin <jeremy.magrin@gmail.com>
  • Loading branch information
charlesBochet and magrinj authored Dec 11, 2023
1 parent 44ef218 commit 8d53c63
Show file tree
Hide file tree
Showing 48 changed files with 1,328 additions and 116 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/ci-front.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:
path: front/node_modules
key: front-node_modules-${{hashFiles('front/yarn.lock')}}
restore-keys: front-node_modules-
- name: Cache twenty-eslint-plugin node modules
- name: Cache eslint-plugin-twenty node modules
uses: actions/cache@v3
with:
path: packages/twenty-eslint-plugin/node_modules
key: twenty-eslint-plugin-node_modules-${{hashFiles('packages/twenty-eslint-plugin/yarn.lock')}}
restore-keys: twenty-eslint-plugin-node_modules-
path: packages/eslint-plugin-twenty/node_modules
key: eslint-plugin-twenty-node_modules-${{hashFiles('packages/eslint-plugin-twenty/yarn.lock')}}
restore-keys: eslint-plugin-twenty-node_modules-
- name: Front / Install Dependencies
run: cd front && yarn
front-pages-sb-test:
Expand Down Expand Up @@ -58,12 +58,12 @@ jobs:
path: front/node_modules
key: front-node_modules-${{hashFiles('front/yarn.lock')}}
restore-keys: front-node_modules-
- name: Cache twenty-eslint-plugin node modules
- name: Cache eslint-plugin-twenty node modules
uses: actions/cache@v3
with:
path: packages/twenty-eslint-plugin/node_modules
key: twenty-eslint-plugin-node_modules-${{hashFiles('packages/twenty-eslint-plugin/yarn.lock')}}
restore-keys: twenty-eslint-plugin-node_modules-
path: packages/eslint-plugin-twenty/node_modules
key: eslint-plugin-twenty-node_modules-${{hashFiles('packages/eslint-plugin-twenty/yarn.lock')}}
restore-keys: eslint-plugin-twenty-node_modules-
- name: Install dependencies
run: yarn
- name: Install Playwright
Expand Down Expand Up @@ -100,12 +100,12 @@ jobs:
path: front/node_modules
key: front-node_modules-${{hashFiles('front/yarn.lock')}}
restore-keys: front-node_modules-
- name: Cache twenty-eslint-plugin node modules
- name: Cache eslint-plugin-twenty node modules
uses: actions/cache@v3
with:
path: packages/twenty-eslint-plugin/node_modules
key: twenty-eslint-plugin-node_modules-${{hashFiles('packages/twenty-eslint-plugin/yarn.lock')}}
restore-keys: twenty-eslint-plugin-node_modules-
path: packages/eslint-plugin-twenty/node_modules
key: eslint-plugin-twenty-node_modules-${{hashFiles('packages/eslint-plugin-twenty/yarn.lock')}}
restore-keys: eslint-plugin-twenty-node_modules-
- name: Install Playwright
run: cd front && npx playwright install
- name: Build Storybook
Expand Down Expand Up @@ -136,12 +136,12 @@ jobs:
path: front/node_modules
key: front-node_modules-${{hashFiles('front/yarn.lock')}}
restore-keys: front-node_modules-
- name: Cache twenty-eslint-plugin node modules
- name: Cache eslint-plugin-twenty node modules
uses: actions/cache@v3
with:
path: packages/twenty-eslint-plugin/node_modules
key: twenty-eslint-plugin-node_modules-${{hashFiles('packages/twenty-eslint-plugin/yarn.lock')}}
restore-keys: twenty-eslint-plugin-node_modules-
path: packages/eslint-plugin-twenty/node_modules
key: eslint-plugin-twenty-node_modules-${{hashFiles('packages/eslint-plugin-twenty/yarn.lock')}}
restore-keys: eslint-plugin-twenty-node_modules-
- name: Front / Install Dependencies
run: cd front && yarn
- name: Front / Run linter
Expand All @@ -167,11 +167,11 @@ jobs:
path: front/node_modules
key: front-node_modules-${{hashFiles('front/yarn.lock')}}
restore-keys: front-node_modules-
- name: Cache twenty-eslint-plugin node modules
- name: Cache eslint-plugin-twenty node modules
uses: actions/cache@v3
with:
path: packages/twenty-eslint-plugin/node_modules
key: twenty-eslint-plugin-node_modules-${{hashFiles('packages/twenty-eslint-plugin/yarn.lock')}}
restore-keys: twenty-eslint-plugin-node_modules-
path: packages/eslint-plugin-twenty/node_modules
key: eslint-plugin-twenty-node_modules-${{hashFiles('packages/eslint-plugin-twenty/yarn.lock')}}
restore-keys: eslint-plugin-twenty-node_modules-
- name: Front / Run jest
run: cd front && yarn test
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
enableInlineHunks: true

nodeLinker: node-modules
enableInlineHunks: true

yarnPath: .yarn/releases/yarn-4.0.2.cjs
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
docker-dev-build:
make -C packages/twenty-docker dev-build

docker-dev-up:
make -C packages/twenty-docker dev-up

docker-dev-down:
make -C packages/twenty-docker dev-down

docker-dev-sh:
make -C packages/twenty-docker dev-sh

postgres-provision-on-docker:
make -C packages/twenty-docker dev-postgres-build

postgres-provision-on-macos-arm:
make -C packages/twenty-postgres provision-on-macos-arm

postgres-provision-on-macos-intel:
make -C packages/twenty-postgres provision-on-macos-intel

postgres-provision-on-linux:
make -C packages/twenty-postgres provision-on-linux
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "AGPL-3.0",
"workspaces": {
"packages": [
"packages/twenty-eslint-plugin",
"packages/eslint-plugin-twenty",
"packages/twenty-front",
"packages/twenty-docs",
"packages/twenty-server"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "twenty-eslint-plugin",
"name": "eslint-plugin-twenty",
"version": "1.0.3",
"description": "",
"main": "dist/index.js",
Expand Down
File renamed without changes.
11 changes: 1 addition & 10 deletions packages/twenty-docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ dev-down:
dev-sh:
@docker compose -f dev/docker-compose.yml exec twenty-dev sh

dev-front-start:
@docker compose -f dev/docker-compose.yml exec twenty-dev sh -c "cd /app/packages/twenty-front && yarn run start"

dev-server-start:
@docker compose -f dev/docker-compose.yml exec twenty-dev sh -c "yarn nx run twenty-server:start:dev"

dev-server-database-init:
@docker compose -f dev/docker-compose.yml exec twenty-dev sh -c "yarn nx run twenty-server:database:init"

dev-build-postgres:
dev-postgres-build:
@docker stop twenty_postgres || true
@docker rm twenty_postgres || true
@docker volume rm twenty_db_data || true
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-docker/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
volumes:
- ../../../packages/twenty-front:/app/packages/twenty-front
- ../../../packages/twenty-server:/app/packages/twenty-server
- ../../../packages/twenty-eslint-plugin:/app/packages/twenty-eslint-plugin
- ../../../packages/eslint-plugin-twenty:/app/packages/eslint-plugin-twenty
- twenty_dev_node_modules_root:/app/node_modules
- twenty_dev_node_modules_yarn:/app/.yarn
- twenty_dev_node_modules_front:/app/packages/twenty-front/node_modules
Expand Down
6 changes: 3 additions & 3 deletions packages/twenty-docker/dev/twenty-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ WORKDIR /app
COPY ../../../../package.json .
COPY ../../../../yarn.lock .
COPY ../../../../.yarnrc.yml .
COPY ../../../../.yarn/releases /app/.yarn/releases
COPY ../../../packages/twenty-front/package.json /app/packages/twenty-front/package.json
COPY ../../../packages/twenty-server/package.json /app/packages/twenty-server/package.json
COPY ../../../packages/twenty-eslint-plugin/package.json /app/packages/twenty-eslint-plugin/package.json
COPY ../../../packages/twenty-server/patches /app/packages/twenty-server/patches
COPY ../../../packages/eslint-plugin-twenty/package.json /app/packages/eslint-plugin-twenty/package.json

RUN corepack enable
RUN yarn set version 4.0.2
RUN yarn

RUN npx playwright install-deps
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-docker/dev/twenty-docs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ WORKDIR /app
COPY ../../../../package.json .
COPY ../../../../yarn.lock .
COPY ../../../../.yarnrc.yml .
COPY ../../../../.yarn/releases /app/.yarn/releases
COPY ../../../packages/twenty-docs/package.json /app/packages/twenty-docs/package.json

RUN yarn set version 4.0.2
RUN yarn

WORKDIR /app/packages/twenty-docs
Expand Down
27 changes: 9 additions & 18 deletions packages/twenty-docs/docs/contributor/local-setup/docker-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The default values should work out of the box, except for the postgres URL, whic
Open `./packages/twenty-server/.env` and change to the following:

```bash
PG_DATABASE_URL=postgres://twenty:twenty@postgres:5432/default?connection_limit=1
PG_DATABASE_URL=postgres://twenty:twenty@postgres:5432/default
```


Expand All @@ -77,7 +77,7 @@ This installation method will also provision a PostgreSQL container.


```bash
make -C packages/twenty-docker dev-build
make docker-dev-build
```

## Step 4: Migrate & seed
Expand All @@ -86,24 +86,27 @@ Before running the project, you need to initialize the database by running the m

Start the containers:
```bash
make -C packages/twenty-docker dev-up
make docker-dev-up
```

Setup database, run migrations, and seed:
```bash
make -C packages/twenty-docker dev-server-database-init
make docker-dev-sh
yarn nx database:init twenty-server
```

## Step 5: Start Twenty

Run the project with the following commands from the `root` folder:

```bash
make -C packages/twenty-docker dev-server-start
make docker-dev-sh
yarn nx start:dev twenty-server
```

```bash
make -C packages/twenty-docker dev-front-start
make docker-dev-sh
yarn nx start twenty-front
```

You should now have:
Expand All @@ -113,18 +116,6 @@ You should now have:

Sign in using a seeded demo account `tim@apple.dev` (password: `Applecar2025`) to start using Twenty.

### Optional

If you don't want to use the `make` command and work directly from the container, you can also ssh directly into the container:

```bash
make -C packages/twenty-docker dev-sh
```
Then run commands through yarn and nx:
```bash
yarn nx run twenty-server:database:init
```


### Troubleshooting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ twenty
└───twenty-front // contains the frontend code for the application
└───twenty-server // contains the backend code for the application
└───twenty-docker // contains docker configurations for development and production build
└───many other packages your are invited to discover such as twenty-docs, twenty-ui, twenty-eslint-plugin, twenty-zapier...
└───many other packages your are invited to discover such as twenty-docs, twenty-ui, eslint-plugin-twenty, twenty-zapier...
```

## IDE Setup
Expand Down
21 changes: 9 additions & 12 deletions packages/twenty-docs/docs/contributor/local-setup/yarn-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ You need to provision this database with a `twenty` user (password: `twenty`), a
<br /><br />

```bash
make provision-postgres-linux
make postgres-provision-on-linux
```

<b>Option 2:</b> If you have docker installed:
<br /><br />

```bash
make provision-postgres-docker
make postgres-provision-on-docker
```
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
You can access this using `twenty` postgres user (password: `twenty`)
Expand All @@ -136,15 +136,15 @@ You can access this using `twenty` postgres user (password: `twenty`)
<br /><br />

```bash
make provision-postgres-macos-intel #for intel architecture
make provision-postgres-macos-arm #for M1/M2/M3 architecture
make postgres-provision-on-macos-intel #for intel architecture
make postgres-provision-on-macos-arm #for M1/M2/M3 architecture
```

<b>Option 2:</b> If you have docker installed:
<br /><br />

```bash
make provision-postgres-docker
make postgres-provision-on-docker
```
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
You can access this using `twenty` postgres user (password: `twenty`)
Expand Down Expand Up @@ -183,9 +183,7 @@ Use `nvm` to install the correct `node` version. The `.nvmrc` ensures all contri
To build Twenty server and seed some data into your database, run the following commands:
```bash
nvm install #recommended
nvm use #recommended
corepack enable #to enable yarn if you haven't done it yet
yarn set version stable #to set the yarn version to yarn version 4
nvm use #recommended

yarn
```
Expand All @@ -194,14 +192,13 @@ yarn

Setup your database with the following command:
```bash
yarn nx run twenty-server:database:init
yarn nx database:init twenty-server
```

Start the server and the frontend:
```bash
yarn nx run twenty-server:database:init
yarn nx run twenty-server:start:dev
yarn nx run twenty-front:dev
yarn nx start:dev twenty-server
yarn nx start twenty-front
```

Twenty's server will be up and running at [http://localhost:3000/graphql](http://localhost:3000/graphql).
Expand Down
4 changes: 2 additions & 2 deletions packages/twenty-front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "tsc && vite build && yarn build:inject-runtime-env",
"build:inject-runtime-env": "./scripts/inject-runtime-env.sh",
"preview": "vite preview",
"eslint-plugin:setup": "cd ../packages/twenty-eslint-plugin/ && yarn && yarn build && cd ../../front/ && yarn upgrade twenty-eslint-plugin",
"eslint-plugin:setup": "cd ../packages/eslint-plugin-twenty/ && yarn && yarn build && cd ../../front/ && yarn upgrade eslint-plugin-twenty",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"fmt:fix": "prettier --cache --write \"src/**/*.ts\" \"src/**/*.tsx\"",
"fmt": "prettier --check \"src/**/*.ts\" \"src/**/*.tsx\"",
Expand Down Expand Up @@ -140,6 +140,7 @@
"eslint-plugin-react-refresh": "^0.4.4",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-storybook": "^0.6.15",
"eslint-plugin-twenty": "file:../eslint-plugin-twenty",
"eslint-plugin-unused-imports": "^3.0.0",
"http-server": "^14.1.1",
"jest": "29.7.0",
Expand All @@ -150,7 +151,6 @@
"storybook": "^7.6.3",
"storybook-addon-cookie": "^3.1.0",
"storybook-addon-pseudo-states": "^2.1.2",
"twenty-eslint-plugin": "file:../twenty-eslint-plugin",
"typescript": "^5.2.2",
"vite": "^5.0.0",
"vite-plugin-svgr": "^4.2.0"
Expand Down
18 changes: 12 additions & 6 deletions packages/twenty-postgres/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
provision-postgres-macos-arm:
sh ./scripts/setup-postgres-macos-arm.sh
provision-on-macos-arm:
sh ./provision/setup-postgres-macos-arm.sh

provision-postgres-macos-intel:
sh ./scripts/setup-postgres-macos-intel.sh
provision-on-macos-intel:
sh ./provision/setup-postgres-macos-intel.sh

provision-postgres-linux:
sh ./scripts/setup-postgres-linux.sh
provision-on-linux:
sh ./provision/setup-postgres-linux.sh

build-pg_graphql-macos-arm:
sh ./build/pg_graphql/build-pg_graphql-macos-arm.sh

build-pg_graphql-macos-intel:
sh ./build/pg_graphql/build-pg_graphql-macos-intel.sh
Loading

0 comments on commit 8d53c63

Please sign in to comment.