Class: FPM::Package::Docker

Inherits:
FPM::Package
  • Object
show all
Defined in:
lib/fpm/package/docker.rb

Overview

An FPM::Package that loads files from a docker container diff.

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Docker

Returns a new instance of Docker.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :logger (Cabin::Channel)

    Logger

  • :client (FPM::Fry::Client)

    Docker client



15
16
17
18
19
20
21
# 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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/fpm/package/docker.rb', line 10

def client
  @client
end

#keep_modified_filesObject (readonly)

Returns the value of attribute keep_modified_files.



10
11
12
# File 'lib/fpm/package/docker.rb', line 10

def keep_modified_files
  @keep_modified_files
end

#loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/fpm/package/docker.rb', line 10

def logger
  @logger
end

Instance Method Details

#input(name) ⇒ Object

Loads all files from a docker container with the given name to the staging path.

Parameters:

  • name (String)

    docker container name



27
28
29
# File 'lib/fpm/package/docker.rb', line 27

def input(name)
  split( name, '**' => staging_path)
end

#split(name, map) ⇒ Object

Loads all files from a docker container into multiple paths defined by map param.

Parameters:

  • name (String)

    docker container name

  • map (Hash<String,String>)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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