Docker container to build plugins

Hi,

I'm not a Ruby/JRuby programmer and I find it quite difficult to get all the necessary build tools in place to build and test my modifications that I'm doing to some of the existing Logstash plugins.

Another user created a topic here that had no replies: Developing a Logstash plugin within Docker

So is there already like an existing docker image/Dockerfile that can be used that has all the necessary tools in place to quickly build and unit test plugins?
Getting everything to work as outlined at How to write a Logstash input plugin | Logstash Reference [7.12] | Elastic is simply way too much effort if you're not doing this kind of development on a day to day basis.

If not, then below is the Dockerfile that I have created, that is based off the official elastic Logstash 7.12.0 image:

FROM elastic/logstash:7.12.0

USER root

# Install rvm and ruby 2.7.2 directly from downloaded binary, which doesn't require rebuild
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \
 && curl -sSL https://get.rvm.io -o /tmp/rvm.sh \
 && cat /tmp/rvm.sh | bash -s stable --ruby=2.7.2

# Necessary for path to ruby 2.7.2
SHELL ["/bin/bash", "-c"]

# rvm install jruby will install openjdk
RUN source /usr/local/rvm/scripts/rvm \
 && rvm install jruby \
 && export JAVA_HOME=$(readlink -f /etc/alternatives/jre_openjdk) \
 && gem install bundler \
 && rm /tmp/rvm.sh

RUN yum -y update \
 && yum install -y git \
 && yum clean all \
 && git clone https://github.com/elastic/logstash-devutils \
 && export JAVA_HOME=$(readlink -f /etc/alternatives/jre_openjdk) \
 && source /usr/local/rvm/scripts/rvm \
 && rvm use jruby \
 && pushd logstash-devutils \
 && export LOGSTASH_PATH=/usr/share/logstash \
 && bundle install \
 && popd

Then the above Dockerfile can be built using like:
docker build . -t logstash-plugin-builder

And then the image can be used as follow, where the plugin src is in the src folder:
docker run --rm -it -v $(pwd)/src:/tmp/src logstash-plugin-builder bash

And then inside the shell of that image, run the below commands, which will build, test and make a .gem file:

export JAVA_HOME=$(readlink -f /etc/alternatives/jre_openjdk)
export LOGSTASH_PATH=/usr/share/logstash
source /usr/local/rvm/scripts/rvm
rvm use jruby
cd /tmp/src
bundle install
bundle exec rspec --seed=11325
gem build *.gemspec

I had to use ruby 2.7.2, since ruby 3.0.0 via rvm didn't manage to install.

https://github.com/cameronkerrnz/logstash-plugin-dev

There are a couple of examples in my other repositories, one a ruby plugin and another a pure Java one.

There is a little bit of coverage of this on YouTube, but I need to complete the series.

Also, if you just need something simple, you can get some good mileage from the ‘ruby’ filter if you use the ‘path’ method.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.