class FPM::Package::Docker
An {FPM::Package} that loads files from a docker container diff.
Constants
- CREATED
- DELETED
- IGNORED_PATTERNS
- MODIFIED
Attributes
client[R]
keep_modified_files[R]
logger[R]
Public Class Methods
new( options = {} )
click to toggle source
@param [Hash] options @option options [Cabin::Channel] :logger Logger @option options [FPM::Fry::Client] :client Docker
client
Calls superclass method
# File lib/fpm/package/docker.rb, line 15 def initialize( options = {} ) super() @logger = options[:logger] || Cabin::Channel.get @client = options[:client] || FPM::Fry::Client.new(logger: @logger) @keep_modified_files = options[:keep_modified_files] @verbose = options[:verbose] end
Public Instance Methods
input(name)
click to toggle source
Loads all files from a docker container with the given name to the staging path.
@param [String] name docker container name
# File lib/fpm/package/docker.rb, line 27 def input(name) split( name, '**' => staging_path) end
split( name, map )
click to toggle source
Loads all files from a docker container into multiple paths defined by map param.
@param [String] name docker container name @param [Hash<String,String>] map
# File lib/fpm/package/docker.rb, line 36 def split( name, map ) changes = changes(name) changes.remove_modified_leaves!(changes_to_remove) do | kind, ml | if kind == DELETED logger.warn("Found a deleted file. You can't delete files as part of a package.", name: ml) elsif !keep_modified_files logger.warn("Found a modified file. You can't modify files in a package.", name: ml) end end fmap = {} changes.leaves.each do | change | map.each do | match, to | if File.fnmatch?(match, change) fmap[change] = File.join(to, change) break end end end directories = changes.smallest_superset directories.each do |chg| client.copy(name, chg, fmap, chown: false) end return nil end
Private Instance Methods
changes(name)
click to toggle source
# File lib/fpm/package/docker.rb, line 63 def changes(name) client_changes = client.changes(name) if @verbose names = {MODIFIED => "MOD", CREATED => "ADD", DELETED => "DEL"} client_changes.each do |change| puts [names[change["Kind"]], change["Path"]].join(" ") end end fs = Node.read(client_changes) fs.reject!(&method(:ignore?)) return fs end
changes_to_remove()
click to toggle source
# File lib/fpm/package/docker.rb, line 98 def changes_to_remove @keep_modified_files ? [DELETED] : [DELETED, MODIFIED] end
copy(name, chg, options = {})
click to toggle source
# File lib/fpm/package/docker.rb, line 76 def copy(name, chg, options = {}) client.copy(name, chg, staging_path(chg), {chown: false}.merge(options)) end
ignore?(chg)
click to toggle source
# File lib/fpm/package/docker.rb, line 84 def ignore?(chg) return true if IGNORED_PATTERNS.any?{|pattern| pattern === chg } Array(attributes[:excludes]).each do |wildcard| if File.fnmatch(wildcard, chg) || File.fnmatch(wildcard, chg[1..-1]) return true end end return false end