Class: FPM::Fry::Detector::Image
- Inherits:
-
Struct
- Object
- Struct
- FPM::Fry::Detector::Image
- Defined in:
- lib/fpm/fry/detector.rb
Defined Under Namespace
Classes: ImageNotFound
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#distribution ⇒ Object
readonly
Returns the value of attribute distribution.
-
#factory ⇒ Object
Returns the value of attribute factory.
-
#image ⇒ Object
Returns the value of attribute image.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #detect! ⇒ Object
-
#initialize(client, image, factory = Container) ⇒ Image
constructor
A new instance of Image.
Constructor Details
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
75 76 77 |
# File 'lib/fpm/fry/detector.rb', line 75 def client @client end |
#distribution ⇒ Object (readonly)
Returns the value of attribute distribution.
80 81 82 |
# File 'lib/fpm/fry/detector.rb', line 80 def distribution @distribution end |
#factory ⇒ Object
Returns the value of attribute factory
75 76 77 |
# File 'lib/fpm/fry/detector.rb', line 75 def factory @factory end |
#image ⇒ Object
Returns the value of attribute image
75 76 77 |
# File 'lib/fpm/fry/detector.rb', line 75 def image @image end |
#version ⇒ Object (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 |