tractr / directus-sync

A CLI tool for synchronizing the schema and configuration of Directus across various environments.
GNU General Public License v3.0
209 stars 8 forks source link

Using this extension with directus docker #63

Closed laportem closed 4 months ago

laportem commented 4 months ago

Both my dev and prod are run using docker-compose I am using directus version 10.10.7 on both and the underlying DB is Postgres. This extension is not yet in the Directus Marketplace. The question is, how do I get this extension to install and work with Directus running using docker. Thank you

EdouardDem commented 4 months ago

Hi @laportem Currently directus-extension-sync is not available in the marketplace but it is in the roadmap. Meanwhile, you can add the custom extensions in you Docker container manually.

Create a file extensions/package.json and declare the extensions you need. In my projects, I have the following file:

{
  "name": "directus-extensions",
  "dependencies": {
    "directus-extension-computed-interface": "^1.9.0",
    "directus-extension-editorjs": "^1.5.0",
    "directus-extension-field-actions": "^1.8.4",
    "directus-extension-masked-interface": "^1.1.0",
    "directus-extension-models": "^2.5.2",
    "directus-extension-sync": "^1.1.3"
  }
}

Create a Dockerfile file to extend the Directus Docker image:

FROM node:20-alpine as third-party-ext
RUN apk add python3 g++ make
WORKDIR /extensions
ADD extensions .
RUN npm install
# Move all extensions the starts with directus-extension-, using find, to the /extensions/directus folder
RUN mkdir -p ./directus
RUN cd node_modules && find . -maxdepth 1 -type d -name "directus-extension-*" -exec mv {} ../directus \;

FROM directus/directus:10.10.7
# Copy third party extensions
COPY --from=third-party-ext /extensions/directus ./extensions

Finally, in your docker-compose.yml use this custom image:

  directus:
    build:
      context: .
      dockerfile: Dockerfile

There is other ways to achieve this, as discussed here.

You may need to flush the directus-extensions table and restart Directus in order to force it to detect new extensions.

EdouardDem commented 4 months ago

@laportem I have updated the installations options in the readme file: https://www.npmjs.com/package/directus-extension-sync#Installation