Fix docker install (#2925)

* 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>
This commit is contained in:
Charles Bochet
2023-12-11 13:36:24 +01:00
committed by GitHub
parent 44ef218fa5
commit 8d53c63801
48 changed files with 1328 additions and 116 deletions

View File

@ -1,5 +1,5 @@
{
"name": "twenty-eslint-plugin",
"name": "eslint-plugin-twenty",
"version": "1.0.3",
"description": "",
"main": "dist/index.js",

View File

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

View File

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

View File

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

View File

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

View File

@ -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
```
@ -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
@ -86,12 +86,13 @@ 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
@ -99,11 +100,13 @@ make -C packages/twenty-docker dev-server-database-init
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:
@ -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

View File

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

View File

@ -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`)
@ -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`)
@ -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
```
@ -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).

View File

@ -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\"",
@ -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",
@ -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"

View File

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

View File

@ -0,0 +1,116 @@
/*
This file is auto generated by pgrx.
The ordering of items is not stable, it is driven by a dependency graph.
*/
-- src/lib.rs:26
-- pg_graphql::_internal_resolve
CREATE FUNCTION graphql."_internal_resolve"(
"query" TEXT, /* &str */
"variables" jsonb DEFAULT '{}', /* core::option::Option<pgrx::datum::json::JsonB> */
"operationName" TEXT DEFAULT null, /* core::option::Option<alloc::string::String> */
"extensions" jsonb DEFAULT null /* core::option::Option<pgrx::datum::json::JsonB> */
) RETURNS jsonb /* pgrx::datum::json::JsonB */
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'resolve_wrapper';
-- src/lib.rs:22
-- requires:
-- resolve
create or replace function graphql.resolve(
"query" text,
"variables" jsonb default '{}',
"operationName" text default null,
"extensions" jsonb default null
)
returns jsonb
language plpgsql
as $$
declare
res jsonb;
message_text text;
begin
begin
select graphql._internal_resolve("query" := "query",
"variables" := "variables",
"operationName" := "operationName",
"extensions" := "extensions") into res;
return res;
exception
when others then
get stacked diagnostics message_text = message_text;
return
jsonb_build_object('data', null,
'errors', jsonb_build_array(jsonb_build_object('message', message_text)));
end;
end;
$$;
-- src/lib.rs:20
create function graphql.comment_directive(comment_ text)
returns jsonb
language sql
immutable
as $$
/*
comment on column public.account.name is '@graphql.name: myField'
*/
select
coalesce(
(
regexp_match(
comment_,
'@graphql\((.+?)\)'
)
)[1]::jsonb,
jsonb_build_object()
)
$$;
-- src/lib.rs:21
create or replace function graphql.exception(message text)
returns text
language plpgsql
as $$
begin
raise exception using errcode='22000', message=message;
end;
$$;
-- src/lib.rs:19
-- Is updated every time the schema changes
create sequence if not exists graphql.seq_schema_version as int cycle;
create or replace function graphql.increment_schema_version()
returns event_trigger
security definer
language plpgsql
as $$
begin
perform nextval('graphql.seq_schema_version');
end;
$$;
create or replace function graphql.get_schema_version()
returns int
security definer
language sql
as $$
select last_value from graphql.seq_schema_version;
$$;
-- On DDL event, increment the schema version number
create event trigger graphql_watch_ddl
on ddl_command_end
execute procedure graphql.increment_schema_version();
create event trigger graphql_watch_drop
on sql_drop
execute procedure graphql.increment_schema_version();

View File

@ -0,0 +1,6 @@
comment = 'pg_graphql: GraphQL support'
default_version = '1.4.2'
module_pathname = '$libdir/pg_graphql'
relocatable = false
superuser = true
schema = 'graphql'

Binary file not shown.

View File

@ -0,0 +1,95 @@
#!/bin/bash
# Colors
RED=31
GREEN=32
BLUE=34
# Function to display colored output
function echo_header {
COLOR=$1
MESSAGE=$2
echo -e "\e[${COLOR}m\n=======================================================\e[0m"
echo -e "\e[${COLOR}m${MESSAGE}\e[0m"
echo -e "\e[${COLOR}m=======================================================\e[0m"
}
# Function to handle errors
function handle_error {
echo_header $RED "Error: $1"
exit 1
}
cat << "EOF"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@#*+=================@@@@@%*+=========++*%@@@@@@@
@@@@#- .+@@%=. .+@@@@@
@@@- .*@@%- .#@@@
@@= .=+++++++++++*#@@@= -++++++++++- %@@
@@. %@@@@@@@@@@@@@@@+ =%@@@@@@@@@@@@= +@@
@@. .@@@@@@@@@@@@@@+. -%@@@@@@@@@@@@@@+ +@@
@@. .@@@@@@@@@@@@*. -#@@#:=@@@@@@@@@@@= +@@
@@ @@@@@@@@@@#: :#@@#: -@@@@@@@@@@@= +@@
@@#====#@@@@@@@@#- .*@@@= -@@@@@@@@@@@= +@@
@@@@@@@@@@@@@@%- .*@@@@# -@@@@@@@@@@@= +@@
@@@@@@@@@@@@%= +@@@@@@# -@@@@@@@@@@@= +@@
@@@@@@@@@@@+ =@@@@@@@@# -@@@@@@@@@@@= +@@
@@@@@@@@@+. -%@@@@@@@@@# -@@@@@@@@@@@= +@@
@@@@@@@*. -%@@@@@@@@@@@# -@@@@@@@@@@@= +@@
@@@@@#: :#@@@@@@@@@@@@@# -@@@@@@@@@@@+ +@@
@@@#: :#@@@@@@@@@@@@@@@# :@@@@@@@@@@@= +@@
@@= :+*+++++++++++*%@@@. :+++++++++- %@@
@@ :@@@%. .#@@@
@@- :@@@@@+: .+@@@@@
@@@#+===================+%@@@@@@@%*++=======++*%@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
EOF
echo_header $BLUE " DATABASE SETUP"
PG_MAIN_VERSION=15
PG_GRAPHQL_VERSION=1.4.2
CARGO_PGRX_VERSION=0.10.2
current_directory=$(pwd)
# Install PostgresSQL
echo_header $GREEN "Step [1/4]: Installing PostgreSQL..."
brew reinstall postgresql@$PG_MAIN_VERSION
# Install pg_graphql extensions
echo_header $GREEN "Step [2/4]: Installing GraphQL for PostgreSQL..."
# Uninstall existing Rust installation if found
existing_rust_path=$(which rustc)
if [ -n "$existing_rust_path" ]; then
echo "Uninstalling existing Rust installation..."
rm -rf "$existing_rust_path"
fi
# To force a reinstall of cargo-pgrx, pass --force to the command below
curl https://sh.rustup.rs -sSf | sh
source "$HOME/.cargo/env"
cargo install --locked cargo-pgrx@$CARGO_PGRX_VERSION --force
cargo pgrx init --pg$PG_MAIN_VERSION download
# Create a temporary directory
temp_dir=$(mktemp -d)
cd "$temp_dir"
pwd
curl -LJO https://github.com/supabase/pg_graphql/archive/refs/tags/v$PG_GRAPHQL_VERSION.zip || handle_error "Failed to download pg_graphql package."
unzip pg_graphql-$PG_GRAPHQL_VERSION.zip
[[ ":$PATH:" != *":/opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin:"* ]] && PATH="/opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin:${PATH}"
cd "pg_graphql-$PG_GRAPHQL_VERSION"
cargo pgrx install --release --pg-config /opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin/pg_config
# # Clean up the temporary directory
echo "Cleaning up..."
cd "$current_directory"
echo "Build complete in $temp_dir."

View File

@ -0,0 +1,95 @@
#!/bin/bash
# Colors
RED=31
GREEN=32
BLUE=34
# Function to display colored output
function echo_header {
COLOR=$1
MESSAGE=$2
echo -e "\e[${COLOR}m\n=======================================================\e[0m"
echo -e "\e[${COLOR}m${MESSAGE}\e[0m"
echo -e "\e[${COLOR}m=======================================================\e[0m"
}
# Function to handle errors
function handle_error {
echo_header $RED "Error: $1"
exit 1
}
cat << "EOF"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@#*+=================@@@@@%*+=========++*%@@@@@@@
@@@@#- .+@@%=. .+@@@@@
@@@- .*@@%- .#@@@
@@= .=+++++++++++*#@@@= -++++++++++- %@@
@@. %@@@@@@@@@@@@@@@+ =%@@@@@@@@@@@@= +@@
@@. .@@@@@@@@@@@@@@+. -%@@@@@@@@@@@@@@+ +@@
@@. .@@@@@@@@@@@@*. -#@@#:=@@@@@@@@@@@= +@@
@@ @@@@@@@@@@#: :#@@#: -@@@@@@@@@@@= +@@
@@#====#@@@@@@@@#- .*@@@= -@@@@@@@@@@@= +@@
@@@@@@@@@@@@@@%- .*@@@@# -@@@@@@@@@@@= +@@
@@@@@@@@@@@@%= +@@@@@@# -@@@@@@@@@@@= +@@
@@@@@@@@@@@+ =@@@@@@@@# -@@@@@@@@@@@= +@@
@@@@@@@@@+. -%@@@@@@@@@# -@@@@@@@@@@@= +@@
@@@@@@@*. -%@@@@@@@@@@@# -@@@@@@@@@@@= +@@
@@@@@#: :#@@@@@@@@@@@@@# -@@@@@@@@@@@+ +@@
@@@#: :#@@@@@@@@@@@@@@@# :@@@@@@@@@@@= +@@
@@= :+*+++++++++++*%@@@. :+++++++++- %@@
@@ :@@@%. .#@@@
@@- :@@@@@+: .+@@@@@
@@@#+===================+%@@@@@@@%*++=======++*%@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
EOF
echo_header $BLUE " DATABASE SETUP"
PG_MAIN_VERSION=15
PG_GRAPHQL_VERSION=1.4.2
CARGO_PGRX_VERSION=0.9.8
current_directory=$(pwd)
# Install PostgresSQL
echo_header $GREEN "Step [1/4]: Installing PostgreSQL..."
brew reinstall postgresql@$PG_MAIN_VERSION
# Install pg_graphql extensions
echo_header $GREEN "Step [2/4]: Installing GraphQL for PostgreSQL..."
# Uninstall existing Rust installation if found
existing_rust_path=$(which rustc)
if [ -n "$existing_rust_path" ]; then
echo "Uninstalling existing Rust installation..."
rm -rf "$existing_rust_path"
fi
# To force a reinstall of cargo-pgrx, pass --force to the command below
curl https://sh.rustup.rs -sSf | sh
source "$HOME/.cargo/env"
cargo install --locked cargo-pgrx@$CARGO_PGRX_VERSION --force
cargo pgrx init --pg$PG_MAIN_VERSION download
# Create a temporary directory
temp_dir=$(mktemp -d)
cd "$temp_dir"
pwd
curl -LJO https://github.com/supabase/pg_graphql/archive/refs/tags/v$PG_GRAPHQL_VERSION.zip || handle_error "Failed to download pg_graphql package."
unzip pg_graphql-$PG_GRAPHQL_VERSION.zip
[[ ":$PATH:" != *":/usr/local/opt/postgresql@$PG_MAIN_VERSION/bin:"* ]] && PATH="/usr/local/opt/postgresql@$PG_MAIN_VERSION/bin:${PATH}"
cd "pg_graphql-$PG_GRAPHQL_VERSION"
cargo pgrx install --release --pg-config /usr/local/opt/postgresql@$PG_MAIN_VERSION/bin/pg_config
# # Clean up the temporary directory
echo "Cleaning up..."
cd "$current_directory"
echo "Build complete."

View File

@ -1,7 +1,7 @@
# Use this for local setup
PG_DATABASE_URL=postgres://twenty:twenty@localhost:5432/default
# Use this for docker setup
# PG_DATABASE_URL=postgres://twenty:twenty@postgres:5432/default?connection_limit=1
# PG_DATABASE_URL=postgres://twenty:twenty@postgres:5432/default
FRONT_BASE_URL=http://localhost:3001
ACCESS_TOKEN_SECRET=replace_me_with_a_random_string_access

View File

@ -1,4 +0,0 @@
{
"javascript.preferences.importModuleSpecifier": "non-relative",
"typescript.preferences.importModuleSpecifier": "non-relative"
}