Update installation doc (#2019)
* Update installation doc * Update install scripts * Update install scripts
This commit is contained in:
@ -1,30 +1,53 @@
|
||||
---
|
||||
title: Docker Setup
|
||||
sidebar_position: 2
|
||||
description: Set up the project with Docker.
|
||||
sidebar_position: 3
|
||||
description: Set up the project with Docker
|
||||
sidebar_custom_props:
|
||||
icon: TbBrandDocker
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
This guide will walk you through provisioning the project with Docker. This comes with a few advantages:
|
||||
- It provides the exact same environment as our core developer team.
|
||||
- It includes some additional dependencies (such as `playwright`) that you might need if you wish to contribute to some advanced areas of the project.
|
||||
- It provisions a PostgreSQL database.
|
||||
|
||||
:::info
|
||||
We do not recommend setting up the project with Docker if you are a Windows (WSL) user, unless you have experience with it, as it will make troubleshooting harder.
|
||||
If you are a Windows user, we recommend using the [yarn installation](/contributor/local-setup/yarn-setup).
|
||||
:::
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Make sure you have the latest [Docker](https://docs.docker.com/get-docker/) and [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) versions installed on your computer.
|
||||
|
||||
You can run `docker --version` to verify the installation.
|
||||
|
||||
## Step #1: Git Clone
|
||||
In your terminal, run the following command:
|
||||
## Step 1: Git Clone
|
||||
|
||||
In your terminal, run the following command.
|
||||
|
||||
We recommend using SSH for this step. If you already haven't set up SSH keys, please do so first. You can learn more about it [here](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh).
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="ssh" label="SSH (Recommended)" default>
|
||||
|
||||
```bash
|
||||
git clone git@github.com:twentyhq/twenty.git
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value="https" label="HTTPS" >
|
||||
|
||||
## Step #2: Setup env variables
|
||||
```bash
|
||||
git clone https://github.com/twentyhq/twenty.git
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## Step 2: Setup env variables
|
||||
|
||||
Twenty requires a few environment variables to be set. Locally, we recommend setting them through `.env` files.
|
||||
|
||||
@ -42,7 +65,7 @@ PG_DATABASE_URL=postgres://twenty:twenty@postgres:5432/default?connection_limit=
|
||||
```
|
||||
|
||||
|
||||
## Step #3: Build
|
||||
## Step 3: Build
|
||||
|
||||
We provide an environment containerized with Docker and orchestrated with `docker-compose`.
|
||||
This installation method will also provision a PostgreSQL container.
|
||||
@ -57,7 +80,7 @@ The configuration for the build is stored in the `infra/dev` folder, but you can
|
||||
make build
|
||||
```
|
||||
|
||||
## Step #4: Migrate & seed
|
||||
## Step 4: Migrate & seed
|
||||
|
||||
Before running the project, you need to initialize the database by running the migrations and seed.
|
||||
|
||||
@ -71,7 +94,7 @@ Run database migrations, generate prisma client, and seed:
|
||||
make server-prisma-reset
|
||||
```
|
||||
|
||||
## Step #5: Start Twenty
|
||||
## Step 5: Start Twenty
|
||||
|
||||
Run the project with the following commands from the `root folder`:
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
---
|
||||
title: IDE Setup
|
||||
sidebar_position: 4
|
||||
description: Our recommended IDE set up.
|
||||
description: Get the best developer UX with VSCode
|
||||
sidebar_custom_props:
|
||||
icon: TbBrandVscode
|
||||
---
|
||||
@ -14,11 +14,11 @@ This section will help you set up your IDE for the project. If you haven't setup
|
||||
You can use any IDE you want but we recommend using Visual Studio Code as our internal team uses it and we have a lot of extensions and settings that we can share with you.
|
||||
|
||||
|
||||
### Installation
|
||||
### Step 1: Installation
|
||||
|
||||
You can download Visual Studio Code from [here](https://code.visualstudio.com/download). Depending on your operating system, you can download the appropriate version.
|
||||
|
||||
### Open Project
|
||||
### Step 2: Open Project
|
||||
|
||||
Once you have installed Visual Studio Code, you can open the project by clicking on `File > Open Folder` and selecting `twenty` project root folder.
|
||||
|
||||
@ -26,7 +26,7 @@ Once you have installed Visual Studio Code, you can open the project by clicking
|
||||
<img src="/img/contributor/ide-project-open.png" alt="Visual Studio Code: Open Twenty project" width="90%" />
|
||||
</div>
|
||||
|
||||
### Extensions
|
||||
### Step 3: Extensions
|
||||
|
||||
You can use the recommended extensions for the project. You will find them in `.vscode/extensions.json` file. VSCode should prompt you to install the recommended extensions when you open the project.
|
||||
|
||||
@ -35,7 +35,7 @@ You can use the recommended extensions for the project. You will find them in `.
|
||||
</div>
|
||||
|
||||
|
||||
### Docker Setup
|
||||
### Step 4: (Docker only) Run VSCode in container
|
||||
|
||||
If you are using a [Docker setup](/contributor/local-setup/docker-setup), you will need to run VSCode in the container. You can do that by opening the project, clicking on the `Remote Explorer` icon on the left sidebar and then clicking on `Attach in New window` on `dev-twenty-dev` container.
|
||||
|
||||
@ -49,6 +49,6 @@ VSCode will open a new window and you will be able to use it as you would normal
|
||||
<br /><br />
|
||||
If you stop your containers, you will need to restart them before opening the project in VSCode again.
|
||||
|
||||
## Conclusion
|
||||
## You are all set
|
||||
|
||||
You are all set to start contributing to the project. If you have any questions, feel free to reach out to us on [Discord](https://twenty.com/discord).
|
||||
@ -7,7 +7,7 @@ sidebar_custom_props:
|
||||
---
|
||||
|
||||
|
||||
## Windows setup eslint prettier error: `CR` line breaks found
|
||||
## CR line breaks found [Windows]
|
||||
|
||||
This is due to the linebreak characters of windows and the git configuration. Try running:
|
||||
```
|
||||
@ -16,7 +16,15 @@ git config --global core.autocrlf false
|
||||
|
||||
Then delete the repository and clone it again.
|
||||
|
||||
## Extra yarn files are created
|
||||
|
||||
## Yarn lock file changed and new files are created (`yarn.lock`, `.yarnrc.yml`, `.yarn`)
|
||||
If you have extra files created by yarn (`yarn.lock`, `.yarnrc.yml`, `.yarn`), you may have a yarn version issue.
|
||||
Try installing [yarn classic](https://classic.yarnpkg.com/lang/en/)!
|
||||
|
||||
Maybe you are using yarn 3? Try installing [yarn classic](https://classic.yarnpkg.com/lang/en/)!
|
||||
## Missing metadata schema
|
||||
|
||||
During Twenty installation, your postgres database needs to be provisionned with right schemas, extensions and users.
|
||||
We provide [different ways](/contributor/local-setup/yarn-setup#step-2-set-up-postgresql-database) to set up your postgres instance
|
||||
|
||||
If you have sucessfully run this provisionning, you should have a `default` and a `metadata` schemas in your database.
|
||||
If you don't, make sure you don't have multiple postgres instance running on your computer.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Windows WSL Setup
|
||||
sidebar_position: 3
|
||||
description: Install the project with WSL2.
|
||||
sidebar_position: 2
|
||||
description: Install the project with WSL2 (Windows)
|
||||
sidebar_custom_props:
|
||||
icon: TbBrandWindows
|
||||
---
|
||||
@ -27,7 +27,7 @@ You will be prompted to create a username and password for your Ubuntu installat
|
||||
|
||||
## Setup your developer environment
|
||||
|
||||
### Step #1: Install Git
|
||||
### Step 1: Install Git
|
||||
|
||||
```
|
||||
sudo apt-get install git
|
||||
@ -44,7 +44,7 @@ If you don't have a Github account, create one now with the corresponding email
|
||||
|
||||
:::
|
||||
|
||||
### Step #2: Install Node.js, nvm, Yarn
|
||||
### Step 2: Install Node.js, nvm, Yarn
|
||||
|
||||
```bash
|
||||
sudo apt-get install curl
|
||||
@ -54,7 +54,7 @@ curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
|
||||
Close and reopen your terminal to start using nvm.
|
||||
|
||||
### Step #3: Install Twenty
|
||||
### Step 3: Install Twenty
|
||||
|
||||
Follow our [Yarn install guide](/contributor/local-setup/yarn-setup) to install Twenty.
|
||||
We don't recommend using Docker on WSL as it adds an extra layer of complexity.
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
---
|
||||
title: Yarn Setup
|
||||
sidebar_position: 1
|
||||
description: "Set up the project with Yarn."
|
||||
description: |
|
||||
Set up the project with Yarn
|
||||
(MacOs and Linux)
|
||||
sidebar_custom_props:
|
||||
icon: TbScript
|
||||
---
|
||||
@ -11,22 +13,20 @@ import TabItem from '@theme/TabItem';
|
||||
In this document, you'll learn how to install the project using yarn. We recommend this method since it's the easiest way to get started but you can also run the project with [Docker](/contributor/local-setup/docker-setup) or [WSL2](/contributor/local-setup/wsl-setup).
|
||||
|
||||
:::info
|
||||
|
||||
`npm` currently does not support local packages satisfactorily. We strongly recommend using `yarn` instead.
|
||||
|
||||
:::
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before you can install and use Twenty, make sure you install the following on your computer:
|
||||
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
|
||||
- [Node](https://nodejs.org/en/download)
|
||||
- [yarn](https://classic.yarnpkg.com/lang/en/docs/install/)
|
||||
- [Node v18](https://nodejs.org/en/download)
|
||||
- [yarn v1](https://classic.yarnpkg.com/lang/en/docs/install/)
|
||||
- [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md)
|
||||
|
||||
---
|
||||
|
||||
## Step #1: Git Clone
|
||||
## Step 1: Git Clone
|
||||
|
||||
In your terminal, run the following command.
|
||||
|
||||
@ -39,7 +39,7 @@ We recommend using SSH for this step. If you already haven't set up SSH keys, pl
|
||||
git clone git@github.com:twentyhq/twenty.git
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value="https" label="HTTPS (Not Recommended)" >
|
||||
<TabItem value="https" label="HTTPS" >
|
||||
|
||||
```bash
|
||||
git clone https://github.com/twentyhq/twenty.git
|
||||
@ -49,69 +49,55 @@ git clone https://github.com/twentyhq/twenty.git
|
||||
</Tabs>
|
||||
|
||||
|
||||
## Step #2: Set up PostgreSQL Database
|
||||
You need to have a PostgreSQL database available to be able to use Twenty. If you already have one available, you can skip this step.
|
||||
|
||||
If you don't, you can provision one through `docker`. With docker running, use the following commands:
|
||||
## Step 2: Set up PostgreSQL Database
|
||||
You need to have a PostgreSQL instance available to be able to use Twenty.
|
||||
This database needs to be provisionned with the a `twenty` user (password: `twenty`), a `default` database and a `test` database.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="docker" label="Docker" default>
|
||||
<TabItem value="linux" label="Linux" default>
|
||||
<b>Option 1:</b> To provision your database locally:
|
||||
<br /><br />
|
||||
|
||||
```bash
|
||||
cd twenty
|
||||
make provision-postgres
|
||||
cd twenty
|
||||
sh ./infra/dev/scripts/setup-database.sh
|
||||
```
|
||||
|
||||
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
|
||||
<b>Option 2:</b> Alternatively if you have docker installed:
|
||||
<br /><br />
|
||||
|
||||
This instance contains two databases: `default` and `test`
|
||||
```bash
|
||||
cd twenty
|
||||
make provision-postgres
|
||||
```
|
||||
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
|
||||
You can access them using `twenty` postgres user (password: `twenty`)
|
||||
</TabItem>
|
||||
<TabItem value="linux-wsl" label="Linux / Windows WSL">
|
||||
|
||||
To install PostgresSQL on WSL2, use the following commands:
|
||||
<TabItem value="mac-os" label="Mac OS" default>
|
||||
|
||||
You must provision PostgresSQL using Docker. To do so, run the following command:
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install postgresql postgresql-contrib
|
||||
cd twenty
|
||||
make provision-postgres
|
||||
```
|
||||
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
|
||||
You can access them using `twenty` postgres user (password: `twenty`)
|
||||
|
||||
Start postgresql service and connect to the database using default `postgres` user:
|
||||
</TabItem>
|
||||
<TabItem value="wsl" label="Windows (WSL)">
|
||||
|
||||
We recommend to provision your database locally:
|
||||
```bash
|
||||
sudo service postgresql start
|
||||
sudo -u postgres psql
|
||||
```
|
||||
|
||||
Create two databases:
|
||||
|
||||
```sql
|
||||
CREATE DATABASE "default";
|
||||
CREATE DATABASE "test";
|
||||
```
|
||||
|
||||
Create a user `twenty` with password `twenty`:
|
||||
|
||||
```sql
|
||||
CREATE USER twenty PASSWORD 'twenty';
|
||||
ALTER USER twenty CREATEDB;
|
||||
```
|
||||
|
||||
Create `metadata` schema:
|
||||
```sql
|
||||
CREATE SCHEMA IF NOT EXISTS "metadata";
|
||||
GRANT ALL ON SCHEMA metadata TO twenty;
|
||||
```
|
||||
|
||||
Activate `uuid-ossp` extension:
|
||||
```sql
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
cd twenty
|
||||
sh ./infra/dev/scripts/setup-database.sh
|
||||
```
|
||||
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
|
||||
You can access them using `twenty` postgres user (password: `twenty`)
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
## Step #3: Setup env variables
|
||||
## Step 3: Setup env variables
|
||||
|
||||
Twenty requires a few environment variables to be set. Locally, we recommend setting them through a `.env` file.
|
||||
|
||||
@ -121,7 +107,7 @@ cp ./front/.env.example ./front/.env
|
||||
cp ./server/.env.example ./server/.env
|
||||
```
|
||||
|
||||
## Step #4: Server setup
|
||||
## Step 4: Server setup
|
||||
|
||||
:::info
|
||||
|
||||
@ -135,13 +121,14 @@ cd server
|
||||
nvm install #recommended
|
||||
nvm use #recommended
|
||||
yarn
|
||||
yarn prisma:reset
|
||||
yarn database:setup
|
||||
yarn database:reset
|
||||
yarn start:dev
|
||||
```
|
||||
|
||||
Twenty's server will be up and running at [http://localhost:3000/graphql](http://localhost:3000/graphql).
|
||||
|
||||
## Step #5: Frontend setup
|
||||
## Step 5: Frontend setup
|
||||
|
||||
:::info
|
||||
|
||||
@ -149,10 +136,10 @@ For the frontend setup, too, we recommend using `nvm` to install the right node
|
||||
|
||||
:::
|
||||
|
||||
To set up the frontend, run the following commands in your terminal:
|
||||
To set up the frontend, run the following commands in another terminal:
|
||||
|
||||
```bash
|
||||
cd ../front
|
||||
cd front
|
||||
nvm install #recommended
|
||||
nvm use #recommended
|
||||
yarn
|
||||
|
||||
901
docs/yarn.lock
901
docs/yarn.lock
File diff suppressed because it is too large
Load Diff
@ -12,43 +12,11 @@ COMMENT ON SCHEMA "public" IS '@graphql({"inflect_names": true})';
|
||||
-- Connect to the "default" database
|
||||
\c "default";
|
||||
|
||||
-- Create extension
|
||||
CREATE EXTENSION IF NOT EXISTS pg_graphql;
|
||||
|
||||
-- Create the metadata schema if it doesn't exist
|
||||
CREATE SCHEMA IF NOT EXISTS "metadata";
|
||||
GRANT ALL ON SCHEMA metadata TO twenty;
|
||||
|
||||
-- Create extension uuid-ossp
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
-- Create GraphQL Entrypoint
|
||||
create function graphql(
|
||||
"operationName" text default null,
|
||||
query text default null,
|
||||
variables jsonb default null,
|
||||
extensions jsonb default null
|
||||
)
|
||||
returns jsonb
|
||||
language sql
|
||||
as $$
|
||||
select graphql.resolve(
|
||||
query := query,
|
||||
variables := coalesce(variables, '{}'),
|
||||
"operationName" := "operationName",
|
||||
extensions := extensions
|
||||
);
|
||||
$$;
|
||||
|
||||
-- Create the tests database for e2e testing
|
||||
CREATE DATABASE "test";
|
||||
|
||||
-- Connect to the "test" database for e2e testing
|
||||
\c "test";
|
||||
|
||||
-- Create the metadata schema if it doesn't exist
|
||||
CREATE SCHEMA IF NOT EXISTS "metadata";
|
||||
GRANT ALL ON SCHEMA metadata TO twenty;
|
||||
|
||||
-- Create extension uuid-ossp
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
@ -21,7 +21,8 @@ WORKDIR /app
|
||||
COPY ../.. .
|
||||
|
||||
WORKDIR /app/server
|
||||
RUN npx prisma generate
|
||||
RUN yarn database:setup
|
||||
RUN yarn database:reset
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
@ -20,15 +20,23 @@
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "./scripts/run-integration.sh",
|
||||
|
||||
"prisma:generate-client": "npx prisma generate --generator client && yarn prisma:generate-gql-select",
|
||||
"prisma:generate-gql-select": "node scripts/generate-model-select-map.js",
|
||||
"prisma:generate-nest-graphql": "npx prisma generate --generator nestgraphql",
|
||||
"prisma:generate": "yarn prisma:generate-client && yarn prisma:generate-gql-select && yarn prisma:generate-nest-graphql",
|
||||
"prisma:migrate": "npx prisma migrate deploy && npx ts-node ./scripts/setup-db.ts && yarn typeorm migration:run -- -d ./src/metadata/metadata.datasource.ts",
|
||||
"prisma:seed": "npx prisma db seed",
|
||||
"prisma:reset": "npx prisma migrate reset && yarn prisma:generate",
|
||||
"prisma:seed": "npx prisma db seed",
|
||||
"prisma:migrate": "npx prisma migrate deploy",
|
||||
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
|
||||
"typeorm:migrate": "yarn typeorm migration:run -- -d ./src/metadata/metadata.datasource.ts"
|
||||
"typeorm:migrate": "yarn typeorm migration:run -- -d ./src/metadata/metadata.datasource.ts",
|
||||
|
||||
"database:setup": "npx ts-node ./scripts/setup-db.ts",
|
||||
"database:migrate": "yarn prisma:migrate && yarn typeorm:migrate",
|
||||
"database:generate": "yarn prisma:generate",
|
||||
"database:seed": "yarn prisma:seed",
|
||||
"database:reset": "yarn database:migrate && yarn database:generate && yarn database:seed"
|
||||
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/server": "^4.7.3",
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import console from 'console';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
@ -13,18 +15,54 @@ export const connectionSource = new DataSource({
|
||||
url: configService.get<string>('PG_DATABASE_URL'),
|
||||
});
|
||||
|
||||
const performQuery = async (query: string, consoleDescription: string) => {
|
||||
try {
|
||||
await connectionSource.query(query);
|
||||
console.log(`Performed '${consoleDescription}' successfully`);
|
||||
} catch (err) {
|
||||
console.error(`Failed to perform '${consoleDescription}':`, err);
|
||||
}
|
||||
};
|
||||
|
||||
connectionSource
|
||||
.initialize()
|
||||
.then(async () => {
|
||||
await connectionSource.query(`CREATE SCHEMA IF NOT EXISTS "metadata"`);
|
||||
const result = await connectionSource.query(`
|
||||
SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'metadata'
|
||||
`);
|
||||
if (result.length > 0) {
|
||||
console.log('Schema "metadata" created successfully');
|
||||
} else {
|
||||
console.log('Failed to create schema "metadata"');
|
||||
}
|
||||
await performQuery(
|
||||
'CREATE SCHEMA IF NOT EXISTS "metadata"',
|
||||
'create schema "metadata"',
|
||||
);
|
||||
await performQuery(
|
||||
'CREATE EXTENSION IF NOT EXISTS pg_graphql',
|
||||
'create extension pg_graphql',
|
||||
);
|
||||
|
||||
await performQuery(
|
||||
'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"',
|
||||
'create extension "uuid-ossp"',
|
||||
);
|
||||
|
||||
await performQuery(
|
||||
`
|
||||
DROP FUNCTION IF EXISTS graphql;
|
||||
CREATE FUNCTION graphql(
|
||||
"operationName" text default null,
|
||||
query text default null,
|
||||
variables jsonb default null,
|
||||
extensions jsonb default null
|
||||
)
|
||||
returns jsonb
|
||||
language sql
|
||||
as $$
|
||||
select graphql.resolve(
|
||||
query := query,
|
||||
variables := coalesce(variables, '{}'),
|
||||
"operationName" := "operationName",
|
||||
extensions := extensions
|
||||
);
|
||||
$$;
|
||||
`,
|
||||
'create function graphql',
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Error during Data Source initialization:', err);
|
||||
|
||||
Reference in New Issue
Block a user