mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 06:08:19 -04:00
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
45 lines
1.6 KiB
Ruby
45 lines
1.6 KiB
Ruby
# encoding: utf-8
|
|
require_relative "pack_command"
|
|
|
|
class LogStash::PluginManager::Pack < LogStash::PluginManager::PackCommand
|
|
option "--tgz", :flag, "compress package as a tar.gz file", :default => !LogStash::Environment.windows?
|
|
option "--zip", :flag, "compress package as a zip file", :default => LogStash::Environment.windows?
|
|
option "--[no-]clean", :flag, "clean up the generated dump of plugins", :default => true
|
|
option "--overwrite", :flag, "Overwrite a previously generated package file", :default => false
|
|
|
|
def execute
|
|
signal_deprecation_warning_for_pack
|
|
|
|
puts("Packaging plugins for offline usage")
|
|
|
|
validate_target_file
|
|
LogStash::Bundler.invoke!({:package => true, :all => true})
|
|
archive_manager.compress(LogStash::Environment::CACHE_PATH, target_file)
|
|
FileUtils.rm_rf(LogStash::Environment::CACHE_PATH) if clean?
|
|
|
|
puts("Generated at #{target_file}")
|
|
end
|
|
|
|
private
|
|
|
|
def delete_target_file?
|
|
return true if overwrite?
|
|
puts("File #{target_file} exist, do you want to overwrite it? (Y/N)")
|
|
( "y" == STDIN.gets.strip.downcase ? true : false)
|
|
end
|
|
|
|
def validate_target_file
|
|
if File.exist?(target_file)
|
|
if delete_target_file?
|
|
File.delete(target_file)
|
|
else
|
|
signal_error("Package creation cancelled, a previously generated package exist at location: #{target_file}, move this file to safe place and run the command again")
|
|
end
|
|
end
|
|
end
|
|
|
|
def target_file
|
|
target_file = File.join(LogStash::Environment::LOGSTASH_HOME, "plugins_package")
|
|
"#{target_file}#{file_extension}"
|
|
end
|
|
end
|