David Munsa
David Munsa

Reputation: 893

how to install custom REST plugin on a dockerized opensearch

I am trying to install me custom REST plugin on my dockerized OpenSearch...

I am using ubuntu 20

this is my docker-compose.yml file

version: '3'
services:
  opensearch-node1:
    image: opensearchproject/opensearch:1.0.1
    container_name: opensearch-node1
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node1
      - discovery.seed_hosts=opensearch-node1,opensearch-node2
      - cluster.initial_master_nodes=opensearch-node1,opensearch-node2
      - bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems
        hard: 65536
    volumes:
      - opensearch-data1:/usr/share/opensearch/data
    ports:
      - 9200:9200
      - 9600:9600 # required for Performance Analyzer
    networks:
      - opensearch-net
  opensearch-node2:
    image: opensearchproject/opensearch:1.0.1
    container_name: opensearch-node2
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node2
      - discovery.seed_hosts=opensearch-node1,opensearch-node2
      - cluster.initial_master_nodes=opensearch-node1,opensearch-node2
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - opensearch-data2:/usr/share/opensearch/data
    networks:
      - opensearch-net
  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:1.0.1
    container_name: opensearch-dashboards
    ports:
      - 5601:5601
    expose:
      - "5601"
    environment:
      OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]' # must be a string with no spaces when specified as an environment variable
    networks:
      - opensearch-net

volumes:
  opensearch-data1:
  opensearch-data2:

networks:
  opensearch-net:

but I have no idea how to continue from here...

this is the plugin layout (which I cloned from here )

enter image description here

Upvotes: 2

Views: 1786

Answers (1)

A.Stern
A.Stern

Reputation: 103

The docker image is all ready to run, without your plugin of course:/ Therefore, you need to create a docker image with your plugin installed.

Open a new directory outside the plugin project with your packaged plugin in it. This package is called something like ->my-plugin.zip located in your plugin project under build/distributions/my-plugin.zip. If it is not there then you should assemble the plugin like so: ./gradlew assemble -Dopensearch.version=1.0.0 -Dbuild.snapshot=false

Add the following Dockerfile to the new directory:

FROM opensearchproject/opensearch:1.0.0
ADD ./my-plugin.zip /usr/
RUN /usr/share/opensearch/bin/opensearch-plugin install file:///usr/my-plugin.zip

The ADD will add the local package to the container so it can be used by the next command. The script after RUN will install the plugin into OpenSearch.

Build the docker image, adding a tag will make life easier later:

docker build --tag=opensearch-with-my-plugin .

Now you have an opensearch image built with your plugin installed on it!

Fix the YAML file you posted originally so that it uses the correct image. This means replacing the opensearchproject/opensearch:1.0.1 with the tag you gave the image you had built - opensearch-with-my-plugin. And add it to the directory with the Dockerfile (not as you have it, in the project).

I took the liberty to change the dashboards version to 1.0.0, as i'm not sure if it will work with 1.0.0 of the image. In any case, this should be a solid start!

version: '3'
services:
  opensearch-node1:
    image: opensearch-with-my-plugin
    container_name: opensearch-node1
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node1
      - discovery.seed_hosts=opensearch-node1,opensearch-node2
      - cluster.initial_master_nodes=opensearch-node1,opensearch-node2
      - bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems
        hard: 65536
    volumes:
      - opensearch-data1:/usr/share/opensearch/data
    ports:
      - 9200:9200
      - 9600:9600 # required for Performance Analyzer
    networks:
      - opensearch-net
  opensearch-node2:
    image: opensearch-with-my-plugin
    container_name: opensearch-node2
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node2
      - discovery.seed_hosts=opensearch-node1,opensearch-node2
      - cluster.initial_master_nodes=opensearch-node1,opensearch-node2
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - opensearch-data2:/usr/share/opensearch/data
    networks:
      - opensearch-net
  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:1.0.0
    container_name: opensearch-dashboards
    ports:
      - 5601:5601
    expose:
      - "5601"
    environment:
      OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]' # must be a string with no spaces when specified as an environment variable
    networks:
      - opensearch-net

volumes:
  opensearch-data1:
  opensearch-data2:

networks:
  opensearch-net:

Verify by running this in the terminal and see that your plugin is installed:)

curl -XGET https://localhost:9200/_cat/plugins -u 'admin:admin' --insecure

Also, I created a GitHub template for plugins with more info. The repo you cloned is the one I created for my blog post on writing plugins, so it is a REST plugin, but not the most generic one.

If you are still having issues getting this running please let me know in the comments, I'm glad to help.

EDIT: file locations edited a bit.

Upvotes: 3

Related Questions