fpm-fry 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ca47ad3fd38c121f59b67bbf3e90f598824306731f2a81cd01d7cb0bf051d37
4
- data.tar.gz: 0af9052af2ee47c734bd96a5b110e7039f7e1b1703a9c8a3cca9da592c22dab9
3
+ metadata.gz: 0544f44b67264b68111bb6f5a96e8132a423e8816afd6367fede81aa505bf1aa
4
+ data.tar.gz: 1e987b5493f30d69e0cf7501dcf4acec92f5190825f701c0401f9e1d72df97f3
5
5
  SHA512:
6
- metadata.gz: b3a4415764e58773095b4c72c0708e3cb4e72e157b3a379380c2a171996eb70cc63f7d81398b6af11542154adaddb892c19bbf4714d09cd993cf3aec5bc0b5b1
7
- data.tar.gz: 4bbd41fef90429ca8fdcf360ad66c60859d83afdbb58835fa86442cd5e294b4ff51b4f9804f24add0ba3991f3aaa2f083c4305945b519b53ca84c170ecf5531a
6
+ metadata.gz: b32603c869cfb37fb0062996affc6dddee51d3bd55d92c2fb6ce16560f18fb078c3399626537d8c79a8f57db72c56876bfc7fa18563cb4052505255e36caf7b0
7
+ data.tar.gz: 991eff30e175e76f634a120ee8fe14c45c7a04034f66af39bc24912c91b7d1c7e928b9de7ca272d205540432408cd1c9fc0c1033753a61020714a13204ad3db0
@@ -22,6 +22,10 @@ class FPM::Fry::Client
22
22
  include FPM::Fry::WithData
23
23
  end
24
24
 
25
+ class ContainerDeletionFailed < StandardError
26
+ include FPM::Fry::WithData
27
+ end
28
+
25
29
  # Raised when trying to read file that can't be read e.g. because it's a
26
30
  # directory.
27
31
  class NotAFile < StandardError
@@ -111,7 +115,7 @@ class FPM::Fry::Client
111
115
  )
112
116
  end
113
117
  rescue Excon::Error => e
114
- @logger.error("unexpected response when reading resource: url: #{url}, error: #{e}")
118
+ logger.error("unexpected response when reading resource: url: #{url}, error: #{e}")
115
119
  raise
116
120
  end
117
121
  if [404,500].include? res.status
@@ -165,14 +169,14 @@ class FPM::Fry::Client
165
169
  end
166
170
 
167
171
  def copy(name, resource, map, options = {})
168
- ex = FPM::Fry::Tar::Extractor.new(logger: @logger)
172
+ ex = FPM::Fry::Tar::Extractor.new(logger: logger)
169
173
  base = File.dirname(resource)
170
174
  read(name, resource) do | entry |
171
175
  file = File.join(base, entry.full_name).chomp('/')
172
176
  file = file.sub(%r"\A\./",'')
173
177
  to = map[file]
174
178
  next unless to
175
- @logger.debug("Copy",name: file, to: to)
179
+ logger.debug("Copy",name: file, to: to)
176
180
  ex.extract_entry(to, entry, options)
177
181
  end
178
182
  end
@@ -182,7 +186,7 @@ class FPM::Fry::Client
182
186
  res = agent.get(path: url, expects: [200, 204])
183
187
  return JSON.parse(res.body)
184
188
  rescue Excon::Error => e
185
- @logger.error("could not retrieve changes for: #{name}, url: #{url}, error: #{e}")
189
+ logger.error("could not retrieve changes for: #{name}, url: #{url}, error: #{e}")
186
190
  raise
187
191
  end
188
192
 
@@ -220,27 +224,35 @@ class FPM::Fry::Client
220
224
  )
221
225
  data = JSON.parse(res.body)
222
226
  if res.status != 201
223
- @logger.error(data["message"])
227
+ logger.error(data["message"])
224
228
  if res.status == 404
225
- @logger.info("execute docker pull #{image} first or specify --pull argument for fpm-fry")
229
+ logger.info("execute docker pull #{image} first or specify --pull argument for fpm-fry")
226
230
  end
227
231
  raise ContainerCreationFailed.new("could not create container from #{image}", message: data["message"])
228
232
  end
229
233
  data['Id']
230
234
  rescue Excon::Error => e
231
- @logger.error("could not create container from #{image}, url: #{url}, error: #{e}")
235
+ logger.error("could not create container from #{image}, url: #{url}, error: #{e}")
232
236
  raise
233
237
  end
234
238
 
235
239
  def destroy(container)
236
240
  return unless container
241
+
237
242
  url = self.url('containers', container)
238
- agent.delete(
243
+ res = agent.delete(
239
244
  path: url,
240
- expects: [204]
245
+ expects: [204, 409]
241
246
  )
247
+ return unless res.status == 409
248
+ data = JSON.parse(res.body) rescue ({"message" => "could not parse response body: '#{res.body}'"})
249
+ if data["message"] =~ /removal of container .* is already in progress/
250
+ logger.info(data["message"])
251
+ else
252
+ raise ContainerDeletionFailed.new("could not destroy container #{container}", data)
253
+ end
242
254
  rescue Excon::Error => e
243
- @logger.error("could not destroy container: #{container}, url: #{url}, error: #{e}")
255
+ logger.error("could not destroy container: #{container}, url: #{url}, error: #{e}")
244
256
  raise
245
257
  end
246
258
 
@@ -2,6 +2,10 @@ require 'fpm/fry/command'
2
2
  module FPM; module Fry
3
3
  class Command::Cook < Command
4
4
 
5
+ class BuildFailed < StandardError
6
+ include FPM::Fry::WithData
7
+ end
8
+
5
9
  option '--keep', :flag, 'Keep the container after build'
6
10
  option '--overwrite', :flag, 'Overwrite package', default: true
7
11
  option '--verbose', :flag, 'Verbose output', default: false
@@ -212,79 +216,81 @@ module FPM; module Fry
212
216
  end
213
217
 
214
218
  def build!
215
- body = begin
216
- url = client.url('containers','create')
217
- args = {
218
- headers: {
219
- 'Content-Type' => 'application/json'
220
- },
221
- path: url,
222
- expects: [201],
223
- body: JSON.generate({"Image" => build_image})
224
- }
225
- args[:query] = { platform: platform } if platform
226
- res = client.post(args)
227
- JSON.parse(res.body)
228
- rescue Excon::Error
229
- logger.error "could not create #{build_image}, url: #{url}"
230
- raise
231
- end
232
- container = body['Id']
233
- begin
234
- begin
235
- url = client.url('containers',container,'start')
236
- client.post(
237
- headers: {
238
- 'Content-Type' => 'application/json'
239
- },
240
- path: url,
241
- expects: [204],
242
- body: JSON.generate({})
243
- )
244
- rescue Excon::Error
245
- logger.error "could not start container #{container}, url: #{url}"
246
- raise
247
- end
219
+ container = create_build_container
220
+ start_build_container(container)
221
+ attach_to_build_container_and_stream_logs(container)
222
+ wait_for_build_container_to_shut_down(container)
223
+ yield container
224
+ ensure
225
+ unless keep?
226
+ client.destroy(container) if container
227
+ end
228
+ end
248
229
 
249
- begin
250
- url = client.url('containers',container,'attach?stderr=1&stdout=1&stream=1&logs=1')
251
- client.post(
252
- path: url,
253
- body: '',
254
- expects: [200],
255
- middlewares: [
256
- StreamParser.new(out,err),
257
- Excon::Middleware::Expects,
258
- Excon::Middleware::Instrumentor,
259
- Excon::Middleware::Mock
260
- ]
261
- )
262
- rescue Excon::Error
263
- logger.error "could not attach to container #{container}, url: #{url}"
264
- raise
265
- end
230
+ def create_build_container
231
+ url = client.url('containers','create')
232
+ args = {
233
+ headers: {
234
+ 'Content-Type' => 'application/json'
235
+ },
236
+ path: url,
237
+ expects: [201],
238
+ body: JSON.generate({"Image" => build_image})
239
+ }
240
+ args[:query] = { platform: platform } if platform
241
+ res = client.post(args)
242
+ JSON.parse(res.body)['Id']
243
+ rescue Excon::Error
244
+ logger.error "could not create #{build_image}, url: #{url}"
245
+ raise
246
+ end
266
247
 
267
- begin
268
- res = client.post(
269
- path: client.url('containers',container,'wait'),
270
- expects: [200],
271
- body: ''
272
- )
273
- json = JSON.parse(res.body)
274
- if json["StatusCode"] != 0
275
- raise Fry::WithData("Build failed", exit_code: json["StatusCode"])
276
- end
277
- rescue Excon::Error
278
- logger.error "could not wait successfully for container #{container}, url: #{url}"
279
- raise
280
- end
248
+ def start_build_container(container)
249
+ url = client.url('containers',container,'start')
250
+ client.post(
251
+ headers: {
252
+ 'Content-Type' => 'application/json'
253
+ },
254
+ path: url,
255
+ expects: [204],
256
+ body: JSON.generate({})
257
+ )
258
+ rescue Excon::Error
259
+ logger.error "could not start container #{container}, url: #{url}"
260
+ raise
261
+ end
281
262
 
282
- yield container
283
- ensure
284
- unless keep?
285
- client.destroy(container)
286
- end
263
+ def attach_to_build_container_and_stream_logs(container)
264
+ url = client.url('containers',container,'attach?stderr=1&stdout=1&stream=1&logs=1')
265
+ client.post(
266
+ path: url,
267
+ body: '',
268
+ expects: [200],
269
+ middlewares: [
270
+ StreamParser.new(out,err),
271
+ Excon::Middleware::Expects,
272
+ Excon::Middleware::Instrumentor,
273
+ Excon::Middleware::Mock
274
+ ]
275
+ )
276
+ rescue Excon::Error
277
+ logger.error "could not attach to container #{container}, url: #{url}"
278
+ raise
279
+ end
280
+
281
+ def wait_for_build_container_to_shut_down(container)
282
+ res = client.post(
283
+ path: client.url('containers',container,'wait'),
284
+ expects: [200],
285
+ body: ''
286
+ )
287
+ json = JSON.parse(res.body)
288
+ if json["StatusCode"] != 0
289
+ raise BuildFailed.new("Build script failed with non zero exit code", json)
287
290
  end
291
+ rescue Excon::Error
292
+ logger.error "could not wait successfully for container #{container}, url: #{url}"
293
+ raise
288
294
  end
289
295
 
290
296
  def input_package(container)
@@ -292,7 +298,7 @@ module FPM; module Fry
292
298
  logger: logger,
293
299
  client: client,
294
300
  keep_modified_files: builder.keep_modified_files,
295
- verbose: verbose,
301
+ verbose: verbose?,
296
302
  )
297
303
  builder.recipe.apply_input(input)
298
304
  begin
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fpm-fry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Lagresle
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2024-02-09 00:00:00.000000000 Z
16
+ date: 2024-03-06 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: excon
@@ -43,82 +43,6 @@ dependencies:
43
43
  - - "~>"
44
44
  - !ruby/object:Gem::Version
45
45
  version: '1.13'
46
- - !ruby/object:Gem::Dependency
47
- name: rake
48
- requirement: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '12.0'
53
- type: :development
54
- prerelease: false
55
- version_requirements: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '12.0'
60
- - !ruby/object:Gem::Dependency
61
- name: rspec
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '3.0'
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 3.0.0
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '3.0'
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: 3.0.0
80
- - !ruby/object:Gem::Dependency
81
- name: webmock
82
- requirement: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - "~>"
85
- - !ruby/object:Gem::Version
86
- version: '3.0'
87
- type: :development
88
- prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- requirements:
91
- - - "~>"
92
- - !ruby/object:Gem::Version
93
- version: '3.0'
94
- - !ruby/object:Gem::Dependency
95
- name: coveralls
96
- requirement: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: 0.8.23
101
- type: :development
102
- prerelease: false
103
- version_requirements: !ruby/object:Gem::Requirement
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- version: 0.8.23
108
- - !ruby/object:Gem::Dependency
109
- name: simplecov
110
- requirement: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: '0'
115
- type: :development
116
- prerelease: false
117
- version_requirements: !ruby/object:Gem::Requirement
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- version: '0'
122
46
  description: deep-fried package builder
123
47
  email: dennis.konert@new-work.se
124
48
  executables: