Class: FPM::Fry::Detector::Image

Inherits:
Struct
  • Object
show all
Defined in:
lib/fpm/fry/detector.rb

Defined Under Namespace

Classes: ImageNotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, image, factory = Container) ⇒ Image

Returns a new instance of Image.



83
84
85
# File 'lib/fpm/fry/detector.rb', line 83

def initialize(client, image, factory = Container)
  super
end

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



75
76
77
# File 'lib/fpm/fry/detector.rb', line 75

def client
  @client
end

#distributionObject (readonly)

Returns the value of attribute distribution.



80
81
82
# File 'lib/fpm/fry/detector.rb', line 80

def distribution
  @distribution
end

#factoryObject

Returns the value of attribute factory

Returns:

  • (Object)

    the current value of factory



75
76
77
# File 'lib/fpm/fry/detector.rb', line 75

def factory
  @factory
end

#imageObject

Returns the value of attribute image

Returns:

  • (Object)

    the current value of image



75
76
77
# File 'lib/fpm/fry/detector.rb', line 75

def image
  @image
end

#versionObject (readonly)

Returns the value of attribute version.



81
82
83
# File 'lib/fpm/fry/detector.rb', line 81

def version
  @version
end

Instance Method Details

#detect!Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fpm/fry/detector.rb', line 87

def detect!
  body = JSON.generate({"Image" => image, "Cmd" => "exit 0"})
  begin
    res = client.post( path: client.url('containers','create'),
                       headers: {'Content-Type' => 'application/json'},
                       body: body,
                       expects: [201]
                     )
  rescue Excon::Errors::NotFound
    raise ImageNotFound, "Image #{image.inspect} not found. Did you do a `docker pull #{image}` before?"
  end
  body = JSON.parse(res.body)
  container = body.fetch('Id')
  begin
    d = factory.new(client,container)
    if d.detect!
      @distribution = d.distribution
      @version = d.version
      return true
    else
      return false
    end
  ensure
    client.delete(path: client.url('containers',container))
  end
end