fpm-fry 0.7.0 → 0.7.2

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: 40cca764e11751a11f15254d74ab7324d02adf9b6d2852822baaeb668600c5e2
4
- data.tar.gz: d017698f4fae8e13f33eb99ddbd7bef77d8e6cdd9e3b0d57b1bb4082b5d21164
3
+ metadata.gz: 9ca47ad3fd38c121f59b67bbf3e90f598824306731f2a81cd01d7cb0bf051d37
4
+ data.tar.gz: 0af9052af2ee47c734bd96a5b110e7039f7e1b1703a9c8a3cca9da592c22dab9
5
5
  SHA512:
6
- metadata.gz: 250eac98d2fce4db0ea393a4eaea6108df9b05dd40f1770acd56e74cd5456b615ceffc34a6097b1d9d607fe59508586f17e2f24f44e88893203b16c8d4d9d1fc
7
- data.tar.gz: ca3d321f4ec3fd487cff204530a7831ec92641d726ce68a1a304e13a402cd8534cb6f9bcd3eff6cf9da2f2c8850898237797e007153c0a1125de6b9d53d381a2
6
+ metadata.gz: b3a4415764e58773095b4c72c0708e3cb4e72e157b3a379380c2a171996eb70cc63f7d81398b6af11542154adaddb892c19bbf4714d09cd993cf3aec5bc0b5b1
7
+ data.tar.gz: 4bbd41fef90429ca8fdcf360ad66c60859d83afdbb58835fa86442cd5e294b4ff51b4f9804f24add0ba3991f3aaa2f083c4305945b519b53ca84c170ecf5531a
@@ -18,6 +18,10 @@ class FPM::Fry::Client
18
18
  include FPM::Fry::WithData
19
19
  end
20
20
 
21
+ class ContainerCreationFailed < StandardError
22
+ include FPM::Fry::WithData
23
+ end
24
+
21
25
  # Raised when trying to read file that can't be read e.g. because it's a
22
26
  # directory.
23
27
  class NotAFile < StandardError
@@ -183,7 +187,28 @@ class FPM::Fry::Client
183
187
  end
184
188
 
185
189
  def pull(image)
186
- agent.post(path: url('images','create'), query: {'fromImage' => image})
190
+ last_status = ""
191
+ streamer = lambda do |chunk, remaining_bytes, total_bytes|
192
+ chunk.each_line do |line|
193
+ begin
194
+ msg = JSON.parse(line)
195
+ status, progress, id = *msg.values_at("status", "progress", "id")
196
+ id += ": " if id
197
+ status += " " if progress
198
+ move_up_one_line = $stdout.tty? && status =~ /Downloading|Extracting/ && last_status =~ /Downloading|Extracting/
199
+ last_status = status
200
+ cursor_move = move_up_one_line ? "\e[1A" : ""
201
+ puts [cursor_move, id, status, progress].join("")
202
+ rescue JSON::ParserError => e
203
+ $stderr.puts "Could not parse JSON response from docker: #{e}"
204
+ end
205
+ end
206
+ end
207
+ agent.post(path: url('images','create'), query: {'fromImage' => image}, :response_block => streamer)
208
+ end
209
+
210
+ def delete(image)
211
+ agent.delete(path: url('images',image), expects: [200, 404])
187
212
  end
188
213
 
189
214
  def create(image)
@@ -191,11 +216,19 @@ class FPM::Fry::Client
191
216
  res = agent.post(
192
217
  headers: { 'Content-Type' => 'application/json' },
193
218
  path: url,
194
- body: JSON.generate('Image' => image)
219
+ body: JSON.generate('Image' => image),
195
220
  )
196
- return JSON.parse(res.body)['Id']
221
+ data = JSON.parse(res.body)
222
+ if res.status != 201
223
+ @logger.error(data["message"])
224
+ if res.status == 404
225
+ @logger.info("execute docker pull #{image} first or specify --pull argument for fpm-fry")
226
+ end
227
+ raise ContainerCreationFailed.new("could not create container from #{image}", message: data["message"])
228
+ end
229
+ data['Id']
197
230
  rescue Excon::Error => e
198
- @logger.error("could not create image: #{image}, url: #{url}, error: #{e}")
231
+ @logger.error("could not create container from #{image}, url: #{url}, error: #{e}")
199
232
  raise
200
233
  end
201
234
 
@@ -4,8 +4,9 @@ module FPM; module Fry
4
4
 
5
5
  option '--keep', :flag, 'Keep the container after build'
6
6
  option '--overwrite', :flag, 'Overwrite package', default: true
7
- option '--verbose', :fag, 'Verbose output', default: false
7
+ option '--verbose', :flag, 'Verbose output', default: false
8
8
  option '--platform', 'PLATFORM', default: nil
9
+ option '--pull', :flag, 'Pull base image', default: false
9
10
 
10
11
  UPDATE_VALUES = ['auto','never','always']
11
12
  option '--update',"<#{UPDATE_VALUES.join('|')}>", 'Update image before installing packages ( only apt currently )', attribute_name: 'update', default: 'auto' do |value|
@@ -58,6 +59,7 @@ module FPM; module Fry
58
59
  b = nil
59
60
  Inspector.for_image(client, image) do |inspector|
60
61
  variables = Detector.detect(inspector)
62
+ variables[:architecture] = platform
61
63
  logger.debug("Loading recipe",variables: variables, recipe: recipe)
62
64
  b = Recipe::Builder.new(variables, logger: ui.logger, inspector: inspector)
63
65
  b.load_file( recipe )
@@ -202,6 +204,13 @@ module FPM; module Fry
202
204
  end
203
205
  end
204
206
 
207
+ def pull_base_image!
208
+ client.pull(image)
209
+ rescue Excon::Error
210
+ logger.error "could not pull base image #{image}"
211
+ raise
212
+ end
213
+
205
214
  def build!
206
215
  body = begin
207
216
  url = client.url('containers','create')
@@ -406,6 +415,8 @@ module FPM; module Fry
406
415
  public
407
416
 
408
417
  def execute
418
+ pull_base_image! if pull?
419
+
409
420
  # force some eager loading
410
421
  lint_recipe_file!
411
422
  builder
@@ -140,7 +140,7 @@ module FPM; module Fry
140
140
  if options[:update]
141
141
  update = 'apt-get update && '
142
142
  end
143
- df[:dependencies] << "ENV DEBIAN_FRONTEND=noninteractive"
143
+ df[:dependencies] << "ARG DEBIAN_FRONTEND=noninteractive"
144
144
  df[:dependencies] << "RUN #{update}apt-get install --yes #{Shellwords.join(build_dependencies)}"
145
145
  when 'redhat'
146
146
  df[:dependencies] << "RUN yum -y install #{Shellwords.join(build_dependencies)}"
@@ -55,6 +55,10 @@ module FPM::Fry
55
55
  variables[:codename]
56
56
  end
57
57
 
58
+ def architecture
59
+ variables[:architecture]
60
+ end
61
+
58
62
  def iteration(value = Not)
59
63
  get_or_set('@iteration',value)
60
64
  end
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.0
4
+ version: 0.7.2
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: 2023-06-13 00:00:00.000000000 Z
16
+ date: 2024-02-09 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: excon
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  - !ruby/object:Gem::Version
198
198
  version: '0'
199
199
  requirements: []
200
- rubygems_version: 3.4.10
200
+ rubygems_version: 3.4.19
201
201
  signing_key:
202
202
  specification_version: 4
203
203
  summary: FPM Fry