dapp 0.4.6 → 0.4.7

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
  SHA1:
3
- metadata.gz: 7bc6a29dd7b243dc8d6f5432442b085926c05ce7
4
- data.tar.gz: 771c938cc250204bc86e50ee796952bbe14d02b4
3
+ metadata.gz: ccc9bcb7c5c18e275f571a8d61bc1cab29f9000b
4
+ data.tar.gz: b222fdf8b55c8592b4c64cb6081edefb6b707d8c
5
5
  SHA512:
6
- metadata.gz: 5ce285874f213efc4f28908cf22d9f7a32c71aa0d0f5554ff89740c6308418a74ccd5c4f050f999077aaf40f7d68022712ebb00458c3d176c4595ae0c4bee35d
7
- data.tar.gz: b8f9bc10ec5e3cd36d6e80dc6fc0aceac8bc3fc0c4afaf884da4941f641f2e099e608d0aab82b40163c9c990de22ea6a9a3dc22d4592c45fef1a833cc25e05dd
6
+ metadata.gz: fcf8a7f80e2e02ae5e234940e8c600f90eb0483f93749d4b64394f6fe8b1266127c9c509b490b3f95f1e626080daba99157e7a1cc4496d527aafeed93065cb2b
7
+ data.tar.gz: f4748cee47bb3b584774028c8393218274a1886921703e859e29bc42813910d6526bec762d7765894d592b3dbf079ac96e94177bd85066ad3518ea8a89bd485e
data/config/en/common.yml CHANGED
@@ -28,6 +28,4 @@ en:
28
28
  using_cache: '[USING CACHE]'
29
29
  not_present: '[NOT PRESENT]'
30
30
  build: '[BUILD]'
31
- push: '[PUSH]'
32
- introspect:
33
- stage: "Introspect stage '%{name}'"
31
+ push: '[PUSH]'
@@ -32,8 +32,10 @@ module Dapp
32
32
  end
33
33
 
34
34
  def build!
35
- last_stage.build!
36
- last_stage.save_in_cache!
35
+ with_introspection do
36
+ last_stage.build!
37
+ last_stage.save_in_cache!
38
+ end
37
39
  ensure
38
40
  FileUtils.rm_rf(tmp_path)
39
41
  end
@@ -73,6 +75,18 @@ module Dapp
73
75
 
74
76
  protected
75
77
 
78
+ def with_introspection
79
+ yield
80
+ rescue Exception::IntrospectImage => e
81
+ data = e.net_status[:data]
82
+ cmd = "docker run -ti --rm --entrypoint /bin/bash #{data[:options]} #{data[:built_id]}"
83
+ system(cmd).tap do |res|
84
+ shellout!("docker rmi #{data[:built_id]}") if data[:rmi]
85
+ res || raise(Error::Application, code: :application_not_run)
86
+ end
87
+ exit 0
88
+ end
89
+
76
90
  attr_reader :last_stage
77
91
  end # Application
78
92
  end # Dapp
@@ -22,9 +22,7 @@ module Dapp
22
22
  return if should_be_skipped?
23
23
  prev_stage.build! if prev_stage
24
24
  image_build
25
- raise Exception::IntrospectImage,
26
- message: application.t(code: 'introspect.stage', data: { name: name }),
27
- data: { built_id: image.built_id, options: image.send(:prepared_options) } if should_be_introspected?
25
+ raise Exception::IntrospectImage, data: { built_id: image.built_id, options: image.send(:prepared_options) } if should_be_introspected?
28
26
  end
29
27
 
30
28
  def save_in_cache!
@@ -59,7 +59,7 @@ module Dapp
59
59
  '--entrypoint /bin/bash']
60
60
  commands = safe_cp(where_to_add, app.container_tmp_path(artifact_name), Process.uid, Process.gid)
61
61
  application.log_secondary_process(application.t(code: 'process.artifact_copy', data: { name: artifact_name }), short: true) do
62
- app.run(docker_options, [%{-ec '#{application.shellout_pack(commands)}'}])
62
+ app.run(docker_options, [%(-ec '#{application.shellout_pack(commands)}')])
63
63
  end
64
64
 
65
65
  commands = safe_cp(application.container_tmp_path('artifact', artifact_name), where_to_add, owner, group, cwd, paths)
@@ -44,9 +44,7 @@ module Dapp
44
44
  private
45
45
 
46
46
  def enabled_modules
47
- application.config._chef._modules.map do |mod|
48
- mod.start_with?('mdapp-') ? mod.split('mdapp-')[1] : mod
49
- end
47
+ application.config._chef._modules
50
48
  end
51
49
 
52
50
  def enabled_recipes
@@ -83,13 +81,13 @@ module Dapp
83
81
 
84
82
  def local_cookbook_paths_for_checksum
85
83
  @local_cookbook_paths_for_checksum ||= berksfile
86
- .local_cookbooks
87
- .values
88
- .map { |cookbook| cookbook[:path] }
89
- .product(LOCAL_COOKBOOK_CHECKSUM_PATTERNS)
90
- .map { |cb, dir| Dir[cb.join(dir)] }
91
- .flatten
92
- .map(&Pathname.method(:new))
84
+ .local_cookbooks
85
+ .values
86
+ .map { |cookbook| cookbook[:path] }
87
+ .product(LOCAL_COOKBOOK_CHECKSUM_PATTERNS)
88
+ .map { |cb, dir| Dir[cb.join(dir)] }
89
+ .flatten
90
+ .map(&Pathname.method(:new))
93
91
  end
94
92
 
95
93
  def stage_cookbooks_paths_for_checksum(stage)
@@ -214,47 +212,45 @@ module Dapp
214
212
  @install_stage_cookbooks[stage] ||= true.tap do
215
213
  common_paths = proc do |cookbook_path|
216
214
  [['metadata.json', 'metadata.json'],
217
- ["attributes/common", 'attributes'],
215
+ ['attributes/common', 'attributes'],
218
216
  ["attributes/#{stage}", 'attributes'],
219
217
  ["files/#{stage}", 'files/default'],
220
- ["templates/#{stage}", 'templates/default']
221
- ].select { |from, _| cookbook_path.join(from).exist? }
218
+ ["templates/#{stage}", 'templates/default']].select { |from, _| cookbook_path.join(from).exist? }
222
219
  end
223
220
 
224
221
  install_paths = Dir[cookbooks_vendor_path('*')]
225
- .map(&Pathname.method(:new))
226
- .map do |cookbook_path|
227
- cookbook_name = File.basename cookbook_path
228
- is_project = (cookbook_name == project_name)
229
- is_mdapp = cookbook_name.start_with? 'mdapp-'
230
- mdapp_name = (is_mdapp ? cookbook_name.split('mdapp-')[1] : nil)
231
- mdapp_enabled = is_mdapp && enabled_modules.include?(mdapp_name)
232
-
233
- paths = if is_project
234
- recipe_paths = enabled_recipes
235
- .map { |recipe| ["recipes/#{stage}/#{recipe}.rb", "recipes/#{recipe}.rb"] }
236
- .select { |from, _| cookbook_path.join(from).exist? }
237
-
238
- if recipe_paths.any?
239
- [*recipe_paths, *common_paths[cookbook_path]]
240
- else
241
- [nil, *common_paths[cookbook_path]]
242
- end
243
- elsif is_mdapp && mdapp_enabled
244
- recipe_path = "recipes/#{stage}.rb"
245
-
246
- if cookbook_path.join(recipe_path).exist?
247
- [[recipe_path, recipe_path], *common_paths[cookbook_path]]
248
- else
249
- [nil, *common_paths[cookbook_path]]
250
- end
251
- else
252
- [['.', '.']]
253
- end
222
+ .map(&Pathname.method(:new))
223
+ .map do |cookbook_path|
224
+ cookbook_name = File.basename cookbook_path
225
+ is_project = (cookbook_name == project_name)
226
+ is_mdapp = cookbook_name.start_with? 'mdapp-'
227
+ mdapp_name = (is_mdapp ? cookbook_name.split('mdapp-')[1] : nil)
228
+ mdapp_enabled = is_mdapp && enabled_modules.include?(mdapp_name)
229
+
230
+ paths = if is_project
231
+ recipe_paths = enabled_recipes
232
+ .map { |recipe| ["recipes/#{stage}/#{recipe}.rb", "recipes/#{recipe}.rb"] }
233
+ .select { |from, _| cookbook_path.join(from).exist? }
234
+
235
+ if recipe_paths.any?
236
+ [*recipe_paths, *common_paths[cookbook_path]]
237
+ else
238
+ [nil, *common_paths[cookbook_path]]
239
+ end
240
+ elsif is_mdapp && mdapp_enabled
241
+ recipe_path = "recipes/#{stage}.rb"
242
+
243
+ if cookbook_path.join(recipe_path).exist?
244
+ [[recipe_path, recipe_path], *common_paths[cookbook_path]]
245
+ else
246
+ [nil, *common_paths[cookbook_path]]
247
+ end
248
+ else
249
+ [['.', '.']]
250
+ end
254
251
 
255
- [cookbook_path, paths] if paths && paths.any?
256
- end
257
- .compact
252
+ [cookbook_path, paths] if paths && paths.any?
253
+ end.compact
258
254
 
259
255
  stage_cookbooks_path(stage).mkpath
260
256
  install_paths.each do |cookbook_path, paths|
@@ -277,8 +273,7 @@ module Dapp
277
273
  data: { stage: stage,
278
274
  cookbook: cookbook,
279
275
  from: from_subpath.relative_path_from(cookbook_path),
280
- to: to_subpath.relative_path_from(stage_cookbooks_path(stage, cookbook)),
281
- } if to_subpath.exist?
276
+ to: to_subpath.relative_path_from(stage_cookbooks_path(stage, cookbook)) } if to_subpath.exist?
282
277
 
283
278
  to_subpath.parent.mkpath
284
279
  FileUtils.cp_r from_subpath, to_subpath
@@ -1,6 +1,7 @@
1
1
  module Dapp
2
2
  module Builder
3
3
  class Chef < Base
4
+ # Error
4
5
  class Error < ::Dapp::Error::Base
5
6
  def initialize(**net_status)
6
7
  super(context: :chef, **net_status)
@@ -43,17 +43,6 @@ BANNER
43
43
  proc: proc { |v| v.to_sym },
44
44
  in: [nil, :from, :infra_install, :source_1_archive, :source_1, :install, :source_2,
45
45
  :infra_setup, :source_3, :chef_cookbooks, :setup, :source_4, :source_5]
46
-
47
- def run(*args)
48
- super
49
- rescue Exception::IntrospectImage => e
50
- $stderr.puts(e.net_status[:message])
51
- data = e.net_status[:data]
52
- system("docker run -ti --rm --entrypoint /bin/bash #{data[:options]} #{data[:built_id]}").tap do |res|
53
- shellout("docker rmi #{data[:built_id]}") if data[:rmi]
54
- res || raise(Dapp::Error::Application, code: :application_not_run)
55
- end
56
- end
57
46
  end
58
47
  end
59
48
  end
@@ -3,7 +3,7 @@ module Dapp
3
3
  # Base
4
4
  class Base < NetStatus::Exception
5
5
  def initialize(net_status = {})
6
- super({context: self.class.to_s.split('::').last.downcase}.merge(net_status))
6
+ super({ context: self.class.to_s.split('::').last.downcase }.merge(net_status))
7
7
  end
8
8
  end
9
9
  end
@@ -49,11 +49,10 @@ module Dapp
49
49
  raise Error::Build, code: :built_id_not_defined if from.built_id.nil?
50
50
  shellout!("docker run #{prepared_options} --entrypoint /bin/bash --name=#{container_name} #{from.built_id} -ec '#{prepared_bash_command}'",
51
51
  log_verbose: log_verbose, log_time: log_time)
52
- rescue Error::Shellout => e
52
+ rescue Error::Shellout => _e
53
53
  raise unless introspect_error || introspect_before_error
54
54
  built_id = introspect_error ? commit! : from.built_id
55
- raise Exception::IntrospectImage, message: Dapp::Helper::NetStatus.message(e),
56
- data: { built_id: built_id, options: prepared_options, rmi: introspect_error }
55
+ raise Exception::IntrospectImage, data: { built_id: built_id, options: prepared_options, rmi: introspect_error }
57
56
  end
58
57
 
59
58
  def commit!
data/lib/dapp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  module Dapp
3
- VERSION = '0.4.6'.freeze
3
+ VERSION = '0.4.7'.freeze
4
4
  BUILD_CACHE_VERSION = 1
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov