logstash/lib/pluginmanager/command.rb
Pier-Hugues Pellerin 1b812af23c Add bin/logstash-plugin prepare-offline-pack command
This new command replace the old workflow of `pack`, `unpack` and the `install --local`, and wrap all the logic into one uniform way of installing plugins.
The work is based on the flow developed for installing an x-pack inside Logstash, when you call prepare-offline-pack, the specified plugins and their dependencies will be packaged in a zip.
And this zip can be installed with the same flow as the pack.

Definition:

Source Logstash: Where you run the prepare-offline-pack.
Target Logstash: Where you install the offline package.

PROS:
- If you install a .gem in the source logstash, the .gem and his dependencies will be bundled.
- The install flow doesn't need to have access to the internet.
- Nothing special need to be setup in the target logstash environment.

CONS:
- The is one minor drawback, the plugins need to have their JARS bundled with them for this flow to work, this is currently the case for all the official plugins.
- The source Logstash need to have access to the internet when you install plugins before packaging them.

Usage examples:
bin/logstash-plugin prepare-offline-pack logstash-input-beats
bin/logstash-plugin prepare-offline-pack logstash-filter-jdbc logstash-input-beats
bin/logstash-plugin prepare-offline-pack logstash-filter-*
bin/logstash-plugin prepare-offline-pack logstash-filter-* logstash-input-beats

How to install:
bin/logstash-plugin install file:///tmp/logstash-offline-plugins-XXXX.zip

Fixes #6404
2017-01-03 13:59:51 -05:00

42 lines
1.3 KiB
Ruby

# encoding: utf-8
class LogStash::PluginManager::Command < Clamp::Command
def gemfile
@gemfile ||= LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, 'r+')).load
end
# If set in debug mode we will raise an exception and display the stacktrace
def report_exception(readable_message, exception)
if debug?
raise exception
else
signal_error("#{readable_message}, message: #{exception.message}")
end
end
def display_bundler_output(output)
if debug? && output
# Display what bundler did in the last run
$stderr.puts("Bundler output")
$stderr.puts(output)
end
end
# Each plugin install for a gemfile create a path with a unique id.
# we must clear what is not currently used in the
def remove_unused_locally_installed_gems!
used_path = gemfile.locally_installed_gems.collect { |gem| gem.options[:path] }
Dir.glob(File.join(LogStash::Environment::LOCAL_GEM_PATH, '*')) do |path|
FileUtils.rm_rf(relative_path(path)) if used_path.none? { |p| p.start_with?(relative_path(path)) }
end
end
def relative_path(path)
require "pathname"
::Pathname.new(path).relative_path_from(::Pathname.new(LogStash::Environment::LOGSTASH_HOME)).to_s
end
def debug?
ENV["DEBUG"]
end
end