bcc-code / directus-schema-sync

The better way to sync your Directus schema and data between environments
Apache License 2.0
90 stars 4 forks source link

Cannot export schemas because of permission denied error #7

Closed scarych closed 6 months ago

scarych commented 6 months ago

Describe the Bug

Hello. I'm tried to use your library to sync directus schemas between different databases, but got error on start.

directus-docker$ docker-compose exec directus npx directus schema-sync export Exporting 9 exporters Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/directus_roles.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/directus_roles.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/directus_folders.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/directus_folders.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/directus_permissions.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/directus_permissions.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/directus_settings.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/directus_settings.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/directus_dashboards.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/directus_dashboards.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/directus_presets.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/directus_presets.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/directus_translations.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/directus_translations.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/directus_panels.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/directus_panels.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/data/schema.json'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/data/schema.json' } Error in condensed action: [Error: EACCES: permission denied, open '/directus/schema-sync/hash.txt'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/directus/schema-sync/hash.txt' } [19:22:36.745] INFO: Loaded extensions: directus-extension-editorjs, directus-extension-schema-sync, directus-extension-sync [19:22:36.747] INFO: Exporting everything to: /directus/schema-sync/data [19:22:36.960] INFO: Done!

To Reproduce

I'm using directus via docker with local database, running on macbook.

My mounted schema-sync directory contains the files

/directus $ ls schema-sync/ -all
total 20
drwxr-xr-x    2 root     root          4096 Dec 11 19:16 .
drwxr-xr-x    1 node     node          4096 Dec 11 19:40 ..
-rw-r--r--    1 root     root          1161 Dec 11 19:15 config.js
-rw-r--r--    1 root     root          2542 Dec 11 19:15 directus_config.js

Version

1.6.1

Installed Extension Via

Docker file

u12206050 commented 6 months ago

I believe this error is to do with the way docker is mounting your windows file system folder. The docker user doesn't seem to have write access to it which would result in the EACcESs error you see.

Have you tried running the docker via the WSM terminal?

scarych commented 6 months ago

I have use the MacOS X and started the docker via docker-compose up for Dockerfile

FROM directus/directus:10.8.2

USER root
RUN corepack enable
USER node

RUN pnpm install directus-sync
RUN pnpm install directus-extension-sync
RUN pnpm install directus-extension-schema-sync
COPY ./schema-sync ./schema-sync

RUN pnpm install directus-extension-editorjs

my docker-compose.yml is

version: "3"
services:
  directus:
    container_name: directus
    build:
      context: "./"
      dockerfile: Dockerfile
    ports:
      - 8055:8055
    volumes:
      - ./directus-config:/directus/directus-config
      - ./schema-sync:/directus/extensions/schema-sync
      - ./uploads:/directus/uploads
      - ./snapshots:/directus/snapshots
    networks:
      - directus
    environment:
      - ....

directus-extension-sync wrote those files correctly to directus-config folder, your extensions don't

Natetronn commented 6 months ago

We were running into a similiar error and fixed it (in part) by changing the schema-sync volume path from:

volumes:
      - ./schema-sync:/directus/extensions/schema-sync

to the following:

volumes:
    - ./schema-sync:/directus/schema-sync

We noticed schema-sync created the configs and the data folder here, not in the extensions folder. Once changed, it worked fine for us. Although, we also had some permission issues that were fixed by chown group:user and chmod on the schema-sync folder on the docker host side.

Oh, we also had to run npx directus schema-sync install --force using a console in Portainer as root (or Docker Desktop) since we were unable to use docker-compose exec directus npx directus schema-sync install from the host side; it kept saying service "container-name" is not running.

Note: we changed the first directus to the container name, per the docs and we also tried the container ID, both without success, which is why we resorted to using a more direct access console.

@u12206050 are we correct that the path should be - ./schema-sync:/directus/schema-sync and not the one currently listed in the docs? That was the case for us, anyway, but this was our first experience, so wasn't 100% sure. With the above fixes it did work for us, however.

u12206050 commented 6 months ago

Yes it is correct that the schema-sync config folder is at the root of the Directus app and not in the extensions folder. I was unaware this was wrong in the documentation but will fix asap.

Strange that the cli command didn't work. Do other Directus cli commands work for you?

Natetronn commented 6 months ago

Yes it is correct that the schema-sync config folder is at the root of the Directus app and not in the extensions folder. I was unaware this was wrong in the documentation but will fix asap.

Thanks Gerard!

Strange that the cli command didn't work. Do other Directus cli commands work for you?

That's a good question, actually. We're using docker compose and not docker-compose, but not sure if that would matter, either way.

Okay, it would appear the command example in the docs requires the service name, not the container name (or the container id), come to find out. I'm able to run this: docker exec -it <container> <command> and that works fine, since it's targeting the container name (or id) and not the service name.

I'm also able to run docker compose exec directus ls, for example and that does indeed work, since the service name was directus in my case. I ran this from the folder that the docker-compose.yml was in.

If I run it a level up, outside of the "working directory", I get the following error:

docker compose exec directus ls
no configuration file provided: not found

So, it's working fine, but the docs could use some clarification in that it's the service name that is required, not the container name, as it states now.

Adding docker exec -it <container> <command> command as another option over the service based one could potentially be useful as well, since it can be run from anywhere, not just from with the directory with the docker-compose.yml. But I'll leave that up to you, of course.

u12206050 commented 6 months ago

Thanks for the info. I have updated the readme. Will close this then.