From 1ebc8b877dadf3a7e8eaec6d7b64a5264eecc6ee Mon Sep 17 00:00:00 2001 From: Adish M <44204658+adishM98@users.noreply.github.com> Date: Mon, 9 Jan 2023 20:35:24 +0530 Subject: [PATCH] Chore tooljetdb env (#5267) * Update digitalocean.md * Update heroku.md * Update google-cloud-run.md * Update docker.md * Update kubernetes-aks.md * Update kubernetes-gke.md * Update ecs.md * Update google-cloud-run.md * Add tooljetdb env vars for separate instance (#5273) * Update try tj docker file for tjdb env vars (#5274) Co-authored-by: Akshay --- .env.example | 4 +++ docker/try-tooljet.Dockerfile | 13 +++++---- .../version-2.0.0-beta/setup/digitalocean.md | 6 ++--- .../version-2.0.0-beta/setup/docker.md | 22 --------------- .../version-2.0.0-beta/setup/ecs.md | 17 ------------ .../setup/google-cloud-run.md | 14 +++------- .../version-2.0.0-beta/setup/heroku.md | 5 ---- .../setup/kubernetes-aks.md | 8 ------ .../setup/kubernetes-gke.md | 8 ------ server/ormconfig.ts | 8 +++--- server/scripts/database-config-utils.ts | 27 ++++++++++++++++--- 11 files changed, 46 insertions(+), 86 deletions(-) diff --git a/.env.example b/.env.example index 0c2c664d72..c7a4ea59b4 100644 --- a/.env.example +++ b/.env.example @@ -17,7 +17,11 @@ PG_HOST= PG_PASS= # TOOLJET DATABASE +ENABLE_TOOLJET_DB= TOOLJET_DB= +TOOLJET_DB_USER= +TOOLJET_DB_HOST= +TOOLJET_DB_PASS= PGRST_HOST= PGRST_JWT_SECRET= diff --git a/docker/try-tooljet.Dockerfile b/docker/try-tooljet.Dockerfile index 5eaa54736b..a4412a887e 100644 --- a/docker/try-tooljet.Dockerfile +++ b/docker/try-tooljet.Dockerfile @@ -34,15 +34,18 @@ ENV TOOLJET_HOST=http://localhost \ PORT=80 \ LOCKBOX_MASTER_KEY=replace_with_lockbox_master_key \ SECRET_KEY_BASE=replace_with_secret_key_base \ - TOOLJET_DB=tooljet_db \ - ENABLE_TOOLJET_DB=true \ - PGRST_HOST=http://localhost:3000 \ - PGRST_DB_URI=postgres://tooljet:postgres@localhost/tooljet_db \ - PGRST_JWT_SECRET=r9iMKoe5CRMgvJBBtp4HrqN7QiPpUToj \ PG_DB=tooljet_production \ PG_USER=tooljet \ PG_PASS=postgres \ PG_HOST=localhost \ + ENABLE_TOOLJET_DB=true \ + TOOLJET_DB_HOST=localhost \ + TOOLJET_DB_USER=postgres \ + TOOLJET_DB_PASS=postgres \ + TOOLJET_DB=tooljet_db \ + PGRST_HOST=http://localhost:3000 \ + PGRST_DB_URI=postgres://tooljet:postgres@localhost/tooljet_db \ + PGRST_JWT_SECRET=r9iMKoe5CRMgvJBBtp4HrqN7QiPpUToj \ ORM_LOGGING=true \ DEPLOYMENT_PLATFORM=docker:local \ TERM=xterm diff --git a/docs/versioned_docs/version-2.0.0-beta/setup/digitalocean.md b/docs/versioned_docs/version-2.0.0-beta/setup/digitalocean.md index c98e2cfaee..017eddd99a 100644 --- a/docs/versioned_docs/version-2.0.0-beta/setup/digitalocean.md +++ b/docs/versioned_docs/version-2.0.0-beta/setup/digitalocean.md @@ -49,7 +49,7 @@ You can learn more about this feature [here](/docs/tooljet-database). Follow the steps below to deploy ToolJet Database on DigitalOcean: -1. If you are using dev database within ToolJet deployment, upgrade it to managed database. +1. If you are using dev database within ToolJet deployment, upgrade it to managed database. You could also add a separate database, if you intent use a differenet database, please refer the [environment variables](/docs/setup/env-vars#tooljet-database-feature-enable--optional-) for additional env variables. 2. Create a new app for PostgREST server. You can opt for docker hub to deploy PostgREST image of version `10.1.x`. @@ -59,6 +59,6 @@ Follow the steps below to deploy ToolJet Database on DigitalOcean: ToolJet - Deploy on DigitalOcean - PostgREST environment variables -4. Add your newly created PostgREST app to the trusted sources of your managed database. +4. Add your newly created PostgREST app to the trusted sources of your managed or separate database. -5. Update your existing ToolJet application deployment with [environment variables](/docs/setup/env-vars#tooljet-database-feature-enable--optional-) required for PostgREST. +5. Update your existing ToolJet application deployment with [environment variables](/docs/setup/env-vars#tooljet-database-feature-enable--optional-) required for PostgREST. diff --git a/docs/versioned_docs/version-2.0.0-beta/setup/docker.md b/docs/versioned_docs/version-2.0.0-beta/setup/docker.md index db6deb0cac..c23a52343d 100644 --- a/docs/versioned_docs/version-2.0.0-beta/setup/docker.md +++ b/docs/versioned_docs/version-2.0.0-beta/setup/docker.md @@ -147,25 +147,3 @@ If you'd want to run postgres with persistent volume rather, curl for the altern -### Creating admin workspace and account - - ```bash - docker-compose exec server npm run db:seed:prod - ``` - - This seeds the database with a default user with the following credentials: - - email: `dev@tooljet.io` - - password: `password` - - -:::caution -Make sure that the server can receive traffic on port 80 & 443. - For example, if the server is an AWS EC2 instance and the installation should receive traffic from the internet, the inbound rules of the security group should look like this: - - | protocol | port | allowed_cidr | - | -------- | ---- | ------------ | - | TCP | 80 | 0.0.0.0/0 | - | TCP | 443 | 0.0.0.0/0 | -::: - - You're all done! ToolJet would now be served at the URL you've set in `TOOLJET_HOST`. diff --git a/docs/versioned_docs/version-2.0.0-beta/setup/ecs.md b/docs/versioned_docs/version-2.0.0-beta/setup/ecs.md index 26ce18e12b..76ffb14bad 100644 --- a/docs/versioned_docs/version-2.0.0-beta/setup/ecs.md +++ b/docs/versioned_docs/version-2.0.0-beta/setup/ecs.md @@ -75,20 +75,3 @@ Follow the steps below to deploy ToolJet on a ECS cluster. The setup above is just a template. Feel free to update the task definition and configure parameters for resources and environment variables according to your needs. ::: -5. Verify if ToolJet is running by checking by checking the status of the tasks in the created service. - -### Creating default admin workspace and account - - You can create a new revision of your existing task definition to have a one time task to seed with default admin. - - 1. Create a new revision from your existing task definition. - You can change task definition name to `tooljet-seed-task` - 2. Click on your existing container name to edit container. - 3. Change container command from `npm,run,start:prod` to `npm,run,db:seed:prod` - 4. Go back to your cluster dashboard and click on Run new task. - run new task - 5. Configure your run task with the `tooljet-seed-task` for your cluster. It should look like: - run task config - 6. Click on run task to have this task seed the database with user having following credentials: - - email: `dev@tooljet.io` - - password: `password` diff --git a/docs/versioned_docs/version-2.0.0-beta/setup/google-cloud-run.md b/docs/versioned_docs/version-2.0.0-beta/setup/google-cloud-run.md index 34303c7c73..da91602a06 100644 --- a/docs/versioned_docs/version-2.0.0-beta/setup/google-cloud-run.md +++ b/docs/versioned_docs/version-2.0.0-beta/setup/google-cloud-run.md @@ -124,22 +124,16 @@ If you intend to use this feature, you'd have to set up and deploy PostgREST ser
port-and-capacity-postgrest
+ +5. Under environmental variable please add correponding Tooljet database env variables. You can also refer [env variable](/docs/setup/env-vars#tooljet-database). - -5. Under environmental variable please add the below PostgREST variables. You can also refer env variable [**here**](/docs/setup/env-vars#tooljet-database) - -
- env-variables-postgrest -
- - -6. Please go to the connection tab. Under Cloud SQL instance please select the PostgreSQL database which you have set-up for Tooljet application. +6. Please go to connection tab. Under Cloud SQL instance please select the PostgreSQL database which you have set-up for Tooljet application or the separate PostgreSQL database created respective to Tooljet Database from the drop-down option.
Cloud-SQL-instance
- + Click on deploy once the above parameters are set. diff --git a/docs/versioned_docs/version-2.0.0-beta/setup/heroku.md b/docs/versioned_docs/version-2.0.0-beta/setup/heroku.md index d2e301e92a..143306f9ce 100644 --- a/docs/versioned_docs/version-2.0.0-beta/setup/heroku.md +++ b/docs/versioned_docs/version-2.0.0-beta/setup/heroku.md @@ -140,8 +140,3 @@ Please install Heroku CLI on your local machine. Please refer Heroku CLI install Please enter the below env variables in the Tooljet application, under the setting tab. You can also refer environment variable [**here**](/docs/setup/env-vars#tooljet-database). - -
- evn-tooljet-app -
- diff --git a/docs/versioned_docs/version-2.0.0-beta/setup/kubernetes-aks.md b/docs/versioned_docs/version-2.0.0-beta/setup/kubernetes-aks.md index f97a7e5ee6..2a373b14c7 100644 --- a/docs/versioned_docs/version-2.0.0-beta/setup/kubernetes-aks.md +++ b/docs/versioned_docs/version-2.0.0-beta/setup/kubernetes-aks.md @@ -38,15 +38,7 @@ If there are self signed HTTPS endpoints that Tooljet needs to connect to, pleas You will be able to access your ToolJet installation once the pods and services running. -If you want to seed the database with a sample user, please SSH into a pod and run: -`npm run db:seed:prod --prefix server` - -This seeds the database with a default user with the following credentials: - -**email**: `dev@tooljet.io` - -**password**: `password` ## ToolJet Database diff --git a/docs/versioned_docs/version-2.0.0-beta/setup/kubernetes-gke.md b/docs/versioned_docs/version-2.0.0-beta/setup/kubernetes-gke.md index 1c41baf387..877589d5da 100644 --- a/docs/versioned_docs/version-2.0.0-beta/setup/kubernetes-gke.md +++ b/docs/versioned_docs/version-2.0.0-beta/setup/kubernetes-gke.md @@ -63,15 +63,7 @@ It might take a few minutes to provision the managed certificates. [Managed cert You will be able to access your ToolJet installation once the pods, service and the ingress is running. -If you want to seed the database with a sample user, please SSH into a pod and run: -`npm run db:seed:prod --prefix server` - -This seeds the database with a default user with the following credentials: - -**emai**: `dev@tooljet.io` - -**password**: `password` ## ToolJet Database diff --git a/server/ormconfig.ts b/server/ormconfig.ts index c53dac1b51..c29f6b1e79 100644 --- a/server/ormconfig.ts +++ b/server/ormconfig.ts @@ -58,10 +58,10 @@ function buildConnectionOptions(data): TypeOrmModuleOptions { function buildToolJetDbConnectionOptions(data): TypeOrmModuleOptions { const connectionParams = { database: data.TOOLJET_DB, - port: +data.PG_PORT || 5432, - username: data.PG_USER, - password: data.PG_PASS, - host: data.PG_HOST, + port: +data.TOOLJET_DB_PORT || 5432, + username: data.TOOLJET_DB_USER, + password: data.TOOLJET_DB_PASS, + host: data.TOOLJET_DB_HOST, connectTimeoutMS: 5000, extra: { max: 25, diff --git a/server/scripts/database-config-utils.ts b/server/scripts/database-config-utils.ts index 4867e5300c..9706e95b5b 100644 --- a/server/scripts/database-config-utils.ts +++ b/server/scripts/database-config-utils.ts @@ -25,6 +25,7 @@ export function getEnvVars() { ...data, ...(data.DATABASE_URL && buildDbConfigFromDatabaseURL(data)), }; + return data; } @@ -51,8 +52,14 @@ function buildDbConfigFromDatabaseURL(data): any { PG_PASS: config.password, PG_USER: config.user, PG_DB: config.database, - TOOLJET_DB: data?.TOOLJET_DB, - PG_DB_OWNER: data?.PG_DB_OWNER, + PG_DB_OWNER: data.PG_DB_OWNER, + ENABLE_TOOLJET_DB: data.ENABLE_TOOLJET_DB, + TOOLJET_DB: data.TOOLJET_DB, + TOOLJET_DB_OWNER: data.TOOLJET_DB_OWNER, + TOOLJET_DB_HOST: config.host, + TOOLJET_DB_PORT: config.port, + TOOLJET_DB_PASS: config.password, + TOOLJET_DB_USER: config.user, }); if (error) { @@ -76,8 +83,15 @@ function validateDatabaseConfig(dbConfig: any): Joi.ValidationResult { PG_PASS: Joi.string().default(''), PG_USER: Joi.string().required(), PG_DB: Joi.string().default('tooljet_production'), - TOOLJET_DB: Joi.string().default('tooljet_db'), PG_DB_OWNER: Joi.string().default('true'), + ...(dbConfig.ENABLE_TOOLJET_DB === 'true' && { + TOOLJET_DB_HOST: Joi.string().default('localhost'), + TOOLJET_DB_PORT: Joi.number().positive().default(5432), + TOOLJET_DB_PASS: Joi.string().default(''), + TOOLJET_DB_USER: Joi.string().required(), + TOOLJET_DB: Joi.string().default('tooljet_db'), + TOOLJET_DB_OWNER: Joi.string().default('true'), + }), }) .unknown(); @@ -92,8 +106,13 @@ export function buildAndValidateDatabaseConfig(): Joi.ValidationResult { PG_PASS: config.PG_PASS, PG_USER: config.PG_USER, PG_DB: config.PG_DB, - TOOLJET_DB: config.TOOLJET_DB, PG_DB_OWNER: config.PG_DB_OWNER, + TOOLJET_DB: config.TOOLJET_DB, + TOOLJET_DB_HOST: config.TOOLJET_DB_HOST, + TOOLJET_DB_PORT: config.TOOLJET_DB_PORT, + TOOLJET_DB_PASS: config.TOOLJET_DB_PASS, + TOOLJET_DB_USER: config.TOOLJET_DB_USER, + TOOLJET_DB_OWNER: config.TOOLJET_DB_OWNER, }; return validateDatabaseConfig(dbConfig);