Skip to content

Commit

Permalink
update to latest directus; replace rbac sync with schema-sync ++
Browse files Browse the repository at this point in the history
  • Loading branch information
adelinn committed Jan 25, 2024
1 parent d298790 commit a4a4da5
Show file tree
Hide file tree
Showing 65 changed files with 21,045 additions and 24,583 deletions.
20 changes: 11 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# IP or host the API listens on ["0.0.0.0"]
HOST="0.0.0.0"

# The port Directus will run on [8080]
PORT=8080
# The port Directus will run on [8055]
PORT=8055

# The URL where your API can be reached on the web. It is also used for things like OAuth redirects,
# forgot-password emails, and logos that needs to be publicly available on the internet. ["/"]
PUBLIC_URL="http://localhost:8080"
PUBLIC_URL="http://localhost:8055"

# What level of detail to log. [info]
# "fatal", "error", "warn", "info", "debug", "trace", "silent"
Expand All @@ -46,8 +46,10 @@ LOG_LEVEL="debug"
ADMIN_EMAIL="[email protected]"
ADMIN_PASSWORD="admin"

# RBAC Sync setting can either be "FULL | EXPORT | IMPORT | NONE"
RBAC_SYNC_MODE=FULL
# SCHEMA Sync setting can either be "BOTH | EXPORT | IMPORT | NONE"
SCHEMA_SYNC=BOTH
# Additional config file for SCHEMA Sync
#SCHEMA_SYNC_CONFIG=custom_config.js

####################################################################################################
### Database
Expand All @@ -57,11 +59,11 @@ RBAC_SYNC_MODE=FULL
# you need to pass to the database instance.

DB_CLIENT="pg"
DB_HOST="postgres-db"
DB_HOST="localhost"
DB_PORT="5432"
DB_DATABASE="directus-app"
DB_USER="postgres-admin"
DB_PASSWORD="password"
DB_DATABASE="directus"
DB_USER="postgres"
DB_PASSWORD="postgrespw"
DB_SSL="false"

# These match the databases defined in the docker-compose file in the root of this repo
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ node_modules/
.idea/

#PostgreSQL local files
data/
/data/

# SQLite local files
*.db
Expand Down
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

11 changes: 7 additions & 4 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM node:slim as base
FROM node:lts as base
WORKDIR /home/node/app

COPY ./shared ./shared
COPY ./src ./src
COPY ./extensions ./extensions
COPY ./schema-sync ./schema-sync

COPY *.json ./
COPY start.js ./

RUN npm i

Expand All @@ -20,7 +22,8 @@ WORKDIR /home/node/app

CMD npm run build


FROM build as production
FROM node:lts-slim as production
WORKDIR /home/node/app
COPY --from=build /home/node/app .
ENV NODE_PATH=./
CMD npx nodemon node_modules/directus/dist/start.js
CMD node start.js
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

A boilerplate for using Directus with best practices inside BCC.

## Setup locally (useing docker)
## Setup locally (using docker)

1. Clone the repo
2. Create `.env` file. You can copy example by `cp env.example .env`
3. Install dependencies by `npm install`
4. Need to prepare shared to be used by docker `cd shared && npm run build`
5. Run services by `docker compose up -d`
6. When you run application for the first time, run `npm run dk-init`.
2. (optional) Create a 1Password Vault or get access to one that contains the secrets you need to run this app locally.
3. Adjust `local.env` file if needed. You can get inspiration from `.env.example`. Add secrets in form of 1Password references.
4. Install dependencies by `npm install`
5. Need to prepare `shared` to be used by Directus `cd shared && npm install && npm run build`
6. Start database with `docker compose up -d`
7. When you run application for the first time, run `npm run init`.
8. Run `npm run local` to run locally

Initial admin user is: `[email protected] | admin`
Initial admin user is: `[email protected] | 12345678`.

## Documentation

Expand All @@ -36,16 +38,21 @@ There is a problem with `@Query` annotation when query is an object. In that cas

### Seeding data to database

Command: `npm run seed`
The command `npm run init` will import test data prefixed with `testdata__` from `schema-sync/data` folder.

Look at example under `database/seeds/src/index.ts`.
Look at configuration file in `schema-sync/local_config.js`.

Using knex to seed database.
It syncs `directus_users` table, but only the admin user. This is needed in order to get a Directus instance with an admin user available.
It syncs `todo_lists` and `todo_items` test tables. These can be removed and replaced with whatever tables are needed.

### RBAC sync
Documentation for schema-sync extension can be found here <https://github.com/bcc-code/directus-schema-sync>

In the `.env` file, set the RBAC synchronization mode before database initialization to: `RBAC_SYNC_MODE=EXPORT`
### Testing the Docker container locally

If the database is already initialized, you can set it to: `RBAC_SYNC_MODE=FULL`
Run `docker build -t test-directus -f Dockerfile.prod .` to build the test image.

Otherwise, you may run into problems initializing the app.
Copy `.env.example` to `dockertest.env` and change `DB_HOST` to `host.docker.internal`.

Run `docker run -v "%cd%/dockertest.env:/home/node/app/.env" --name directustest -dp 127.0.0.1:8055:8055 test-directus` to run the image.

To cleanup run `docker stop directustest && docker rm directustest && docker image rm test-directus`
3 changes: 0 additions & 3 deletions authenticate/.gitignore

This file was deleted.

Loading

0 comments on commit a4a4da5

Please sign in to comment.