dimitrov-adrian / directus-extension-searchsync

Simple Directus 9 extension that sync content with remote search engine.
MIT License
116 stars 27 forks source link

docker installation #29

Closed hodanli closed 1 year ago

hodanli commented 1 year ago

how can i install this extension to directus docker container?

Lukas-Sachse commented 1 year ago

Hi @hodanli, these are my steps for working with docker:

Demo with a step-by-step-tutorial

What we are doing

Instead of using the official directus-image directly, we will build our own custom image that's extending the official image.

Required

Own repository with Dockerfile, docker-compose.yml and a valid searchsync-config-file. Take a look at my demo

Example: searchsync.config.cjs

module.exports = {
  server: {
    type: 'meilisearch',
    host: 'http://host.docker.internal:7700',
    key: '<your-api-key>',
  },
  reindexOnStart: true,
  collections: {
    test_collection: {
      fields: ['title', 'description'],
    },
  },
}

Build custom image with Dockerfile:


FROM directus/directus:9.23.1

# Install git 
# We need this part becaus "npm install" will fail without the git package.
# Installing apk packages needs permissions, so we need to switch to root user.
USER root  
RUN apk add git --no-cache 

# SearchSync extension
# First we copy the config file, then we install the extension.
COPY searchsync.config.cjs ./ 
RUN npm install dimitrov-adrian/directus-extension-searchsync

# Start command for our image
CMD npx directus bootstrap && \
  npx directus database migrate:latest && \
  npx directus start 

Snippet from docker-compose.yml


[...]

services:
 [...]
  custom-directus:
    container_name: custom-directus
    # build the image from the Dockerfile in the current directory
    # ---
    build: 
      context: ./
      dockerfile: Dockerfile
     # ---
 [...]
hodanli commented 1 year ago

considering npm install is not recommended for production. i was expecting much simpler solution. but thanks, i will try this.

Lukas-Sachse commented 1 year ago

considering npm install is not recommended for production.

Ok, didn't know that so far. Why is that the case?

What's the difference between:

  1. adding a package by running "npm install" in a Dockerfile
  2. defining a package in a package.json

In any way, you have to install your packages first, before you can run/build your software. Am I missing something?

hodanli commented 1 year ago

it says at the top of this documentation page:

https://docs.directus.io/self-hosted/docker-guide.html