From 5a0216d9c2f326dc2dce896ca4310f359a3cc1cd Mon Sep 17 00:00:00 2001 From: Stefan Kaes Date: Sun, 5 Jun 2016 08:58:15 +0200 Subject: [PATCH 1/2] fix that multiple chunks of JSON are sent by Docker for Mac --- lib/fpm/fry/build_output_parser.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/fpm/fry/build_output_parser.rb b/lib/fpm/fry/build_output_parser.rb index cec15a0..dc83ebb 100644 --- a/lib/fpm/fry/build_output_parser.rb +++ b/lib/fpm/fry/build_output_parser.rb @@ -10,12 +10,17 @@ def initialize(*_) end def call(chunk, *_) - json = JSON.parse(chunk) - stream = json['stream'] - if /\ASuccessfully built (\w+)\Z/.match(stream) - images << $1 + # new docker for Mac results in data like this: + # "{'stream':' ---\\u003e 3bc51d6a4c46\\n'}\r\n{'stream':'Step 2 : WORKDIR /tmp/build\\n'}\r\n" + # this isn't valid JSON, of course, so we process each part individually + chunk.split("\r\n").each do |sub_chunk| + json = JSON.parse(sub_chunk) + stream = json['stream'] + if /\ASuccessfully built (\w+)\Z/.match(stream) + images << $1 + end + out << stream end - out << stream end end From 2726308172d260a94b677d9e65ac1316bc1955ae Mon Sep 17 00:00:00 2001 From: Stefan Kaes Date: Tue, 21 Jun 2016 14:10:27 +0200 Subject: [PATCH 2/2] stop using deprecated file copy API endpoint for API versions >= 1.20 --- lib/fpm/fry/client.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/fpm/fry/client.rb b/lib/fpm/fry/client.rb index e6f3e37..842d951 100644 --- a/lib/fpm/fry/client.rb +++ b/lib/fpm/fry/client.rb @@ -70,14 +70,22 @@ def url(*path) def read(name, resource) return to_enum(:read, name, resource) unless block_given? - body = JSON.generate({'Resource' => resource}) - res = agent.post( - path: url('containers',name,'copy'), - headers: { 'Content-Type' => 'application/json' }, - body: body, - expects: [200,500] - ) - if res.status == 500 + res = if (server_version['ApiVersion'] < "1.20") + agent.post( + path: url('containers', name, 'copy'), + headers: { 'Content-Type' => 'application/json' }, + body: JSON.generate({'Resource' => resource}), + expects: [200,404,500] + ) + else + agent.get( + path: url('containers', name, 'archive'), + headers: { 'Content-Type' => 'application/json' }, + query: {:path => resource}, + expects: [200,404,500] + ) + end + if res.status == 500 || res.status == 404 raise FileNotFound, "File #{resource.inspect} not found: #{res.body}" end sio = StringIO.new(res.body)