dapp 0.5.13 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dapp +3 -0
  3. data/config/en/common.yml +35 -6
  4. data/config/en/net_status.yml +20 -6
  5. data/lib/dapp.rb +53 -27
  6. data/lib/dapp/application.rb +48 -27
  7. data/lib/dapp/application/git_artifact.rb +1 -1
  8. data/lib/dapp/application/path.rb +2 -18
  9. data/lib/dapp/application/tags.rb +5 -5
  10. data/lib/dapp/build/stage/artifact.rb +8 -3
  11. data/lib/dapp/build/stage/base.rb +43 -30
  12. data/lib/dapp/build/stage/{infra_install.rb → before_install.rb} +6 -6
  13. data/lib/dapp/build/stage/before_setup.rb +27 -0
  14. data/lib/dapp/build/stage/docker_instructions.rb +12 -1
  15. data/lib/dapp/build/stage/from.rb +4 -3
  16. data/lib/dapp/build/stage/{source_1_archive.rb → ga_archive.rb} +7 -7
  17. data/lib/dapp/build/stage/{source_1_archive_dependencies.rb → ga_archive_dependencies.rb} +4 -4
  18. data/lib/dapp/build/stage/{source_base.rb → ga_base.rb} +31 -7
  19. data/lib/dapp/build/stage/{source_dependencies_base.rb → ga_dependencies_base.rb} +5 -6
  20. data/lib/dapp/build/stage/{source_5.rb → ga_latest_patch.rb} +6 -6
  21. data/lib/dapp/build/stage/install/ga_post_install_patch.rb +21 -0
  22. data/lib/dapp/build/stage/install/ga_post_install_patch_dependencies.rb +21 -0
  23. data/lib/dapp/build/stage/install/ga_pre_install_patch.rb +21 -0
  24. data/lib/dapp/build/stage/install/ga_pre_install_patch_dependencies.rb +31 -0
  25. data/lib/dapp/build/stage/install/install.rb +31 -0
  26. data/lib/dapp/build/stage/mod/artifact.rb +9 -19
  27. data/lib/dapp/build/stage/mod/group.rb +42 -0
  28. data/lib/dapp/build/stage/mod/logging.rb +62 -26
  29. data/lib/dapp/build/stage/setup/chef_cookbooks.rb +37 -0
  30. data/lib/dapp/build/stage/setup/ga_post_setup_patch.rb +25 -0
  31. data/lib/dapp/build/stage/setup/ga_post_setup_patch_dependencies.rb +31 -0
  32. data/lib/dapp/build/stage/setup/ga_pre_setup_patch.rb +25 -0
  33. data/lib/dapp/build/stage/setup/ga_pre_setup_patch_dependencies.rb +27 -0
  34. data/lib/dapp/build/stage/setup/setup.rb +31 -0
  35. data/lib/dapp/builder/base.rb +9 -6
  36. data/lib/dapp/builder/chef.rb +128 -107
  37. data/lib/dapp/builder/chef/berksfile.rb +3 -0
  38. data/lib/dapp/builder/shell.rb +4 -3
  39. data/lib/dapp/cli.rb +8 -6
  40. data/lib/dapp/cli/base.rb +6 -1
  41. data/lib/dapp/cli/bp.rb +41 -0
  42. data/lib/dapp/cli/build.rb +17 -4
  43. data/lib/dapp/cli/cleanup.rb +24 -0
  44. data/lib/dapp/cli/list.rb +2 -2
  45. data/lib/dapp/cli/push.rb +8 -9
  46. data/lib/dapp/cli/run.rb +3 -4
  47. data/lib/dapp/cli/spush.rb +20 -0
  48. data/lib/dapp/cli/stages.rb +2 -0
  49. data/lib/dapp/cli/stages/cleanup.rb +7 -3
  50. data/lib/dapp/cli/stages/flush.rb +6 -3
  51. data/lib/dapp/config/application.rb +17 -11
  52. data/lib/dapp/config/chef.rb +4 -0
  53. data/lib/dapp/config/docker.rb +3 -2
  54. data/lib/dapp/config/git_artifact.rb +1 -2
  55. data/lib/dapp/config/main.rb +5 -2
  56. data/lib/dapp/config/shell.rb +20 -16
  57. data/lib/dapp/docker_registry.rb +32 -0
  58. data/lib/dapp/docker_registry/base.rb +47 -0
  59. data/lib/dapp/docker_registry/default.rb +18 -0
  60. data/lib/dapp/docker_registry/mod/authorization.rb +62 -0
  61. data/lib/dapp/docker_registry/mod/request.rb +44 -0
  62. data/lib/dapp/error/image.rb +6 -0
  63. data/lib/dapp/error/project.rb +6 -0
  64. data/lib/dapp/error/registry.rb +6 -0
  65. data/lib/dapp/exception/registry.rb +6 -0
  66. data/lib/dapp/git_artifact.rb +6 -7
  67. data/lib/dapp/git_repo/base.rb +1 -1
  68. data/lib/dapp/git_repo/remote.rb +6 -38
  69. data/lib/dapp/helper/sha256.rb +3 -3
  70. data/lib/dapp/helper/shellout.rb +25 -7
  71. data/lib/dapp/helper/streaming.rb +1 -3
  72. data/lib/dapp/image/argument.rb +31 -18
  73. data/lib/dapp/image/docker.rb +15 -8
  74. data/lib/dapp/image/stage.rb +10 -12
  75. data/lib/dapp/lock/base.rb +44 -0
  76. data/lib/dapp/lock/error.rb +14 -0
  77. data/lib/dapp/lock/file.rb +33 -0
  78. data/lib/dapp/prctl.rb +22 -0
  79. data/lib/dapp/project.rb +75 -0
  80. data/lib/dapp/project/command/bp.rb +24 -0
  81. data/lib/dapp/project/command/build.rb +21 -0
  82. data/lib/dapp/project/command/cleanup.rb +24 -0
  83. data/lib/dapp/project/command/common.rb +51 -0
  84. data/lib/dapp/project/command/list.rb +14 -0
  85. data/lib/dapp/project/command/push.rb +21 -0
  86. data/lib/dapp/project/command/run.rb +15 -0
  87. data/lib/dapp/project/command/spush.rb +17 -0
  88. data/lib/dapp/project/command/stages_cleanup.rb +70 -0
  89. data/lib/dapp/project/command/stages_flush.rb +18 -0
  90. data/lib/dapp/project/dappfile.rb +70 -0
  91. data/lib/dapp/project/lock.rb +27 -0
  92. data/lib/dapp/project/logging/base.rb +107 -0
  93. data/lib/dapp/project/logging/process.rb +104 -0
  94. data/lib/dapp/project/paint.rb +16 -0
  95. data/lib/dapp/project/ssh_agent.rb +77 -0
  96. data/lib/dapp/version.rb +1 -1
  97. metadata +74 -27
  98. data/lib/dapp/application/deps/gitartifact.rb +0 -39
  99. data/lib/dapp/application/logging.rb +0 -120
  100. data/lib/dapp/application/system_shellout.rb +0 -63
  101. data/lib/dapp/build/stage/chef_cookbooks.rb +0 -33
  102. data/lib/dapp/build/stage/infra_setup.rb +0 -27
  103. data/lib/dapp/build/stage/install.rb +0 -27
  104. data/lib/dapp/build/stage/setup.rb +0 -27
  105. data/lib/dapp/build/stage/source_1.rb +0 -21
  106. data/lib/dapp/build/stage/source_1_dependencies.rb +0 -27
  107. data/lib/dapp/build/stage/source_2.rb +0 -17
  108. data/lib/dapp/build/stage/source_2_dependencies.rb +0 -17
  109. data/lib/dapp/build/stage/source_3.rb +0 -17
  110. data/lib/dapp/build/stage/source_3_dependencies.rb +0 -23
  111. data/lib/dapp/build/stage/source_4.rb +0 -21
  112. data/lib/dapp/build/stage/source_4_dependencies.rb +0 -27
  113. data/lib/dapp/cli/smartpush.rb +0 -19
  114. data/lib/dapp/controller.rb +0 -119
  115. data/lib/dapp/error/controller.rb +0 -6
  116. data/lib/dapp/helper/log.rb +0 -73
@@ -0,0 +1,104 @@
1
+ module Dapp
2
+ # Project
3
+ class Project
4
+ # Logging
5
+ module Logging
6
+ # Process
7
+ module Process
8
+ DEFAULT_STYLE = {
9
+ message: :step,
10
+ process: :secondary,
11
+ status: :secondary,
12
+ success: :success,
13
+ failed: :warning,
14
+ time: :default
15
+ }.freeze
16
+
17
+ def log_state(message, state:, styles: {})
18
+ styles[:message] ||= DEFAULT_STYLE[:message]
19
+ styles[:status] ||= DEFAULT_STYLE[:status]
20
+
21
+ message = slice(message)
22
+ state = rjust(state, message)
23
+ formatted_message = paint_string(message, styles[:message])
24
+ formatted_status = paint_string(state, styles[:status])
25
+
26
+ log "#{formatted_message}#{formatted_status}"
27
+ end
28
+
29
+ def log_process(message, process: nil, short: false, style: {}, &blk)
30
+ style[:message] ||= DEFAULT_STYLE[:message]
31
+ style[:process] ||= DEFAULT_STYLE[:process]
32
+ style[:failed] ||= DEFAULT_STYLE[:failed]
33
+ style[:success] ||= DEFAULT_STYLE[:success]
34
+
35
+ if log_verbose? && !short
36
+ process ||= t(code: 'status.process.default')
37
+ log_process_verbose(message, process: process, style: style, &blk)
38
+ else
39
+ log_process_short(message, style: style, &blk)
40
+ end
41
+ end
42
+
43
+ def log_secondary_process(message, **kwargs, &blk)
44
+ log_process(message, **kwargs.merge(style: { message: :secondary, success: :secondary }), &blk)
45
+ end
46
+
47
+ protected
48
+
49
+ def log_process_verbose(message, process:, style: {}, &blk)
50
+ process = paint_string(rjust(process, message), style[:process])
51
+ info = paint_string(message, style[:message]) + process
52
+ success_message = paint_string(slice(message), style[:message]) +
53
+ paint_string(rjust(t(code: 'status.success.default'), message), style[:success])
54
+ failed_message = paint_string(slice(message) + rjust(t(code: 'status.failed.default'), message), style[:failed])
55
+ log_process_default(info, success_message, failed_message, &blk)
56
+ end
57
+
58
+ def log_process_short(message, style: {}, &blk)
59
+ info = "#{paint_string(slice(message), style[:message])} ... "
60
+ success_message = paint_string(rjust(t(code: 'status.success.default'), info), style[:success])
61
+ failed_message = paint_string(rjust(t(code: 'status.failed.default'), info), style[:failed])
62
+ log_process_default(info, success_message, failed_message, inline: true, &blk)
63
+ end
64
+
65
+ def log_process_default(info, success_message, failed_message, inline: false)
66
+ log info, inline: inline
67
+ message = success_message
68
+ start = Time.now
69
+ yield
70
+ rescue Exception::Base, Error::Base, SignalException, StandardError => _e
71
+ message = failed_message
72
+ raise
73
+ ensure
74
+ time = paint_string("#{(Time.now - start).round(2)} sec", DEFAULT_STYLE[:time])
75
+ log "#{message} #{time}", indent: !inline, time: !inline
76
+ end
77
+
78
+ def rjust(str, start_string)
79
+ str.rjust(free_space(start_string))
80
+ end
81
+
82
+ def slice(str)
83
+ if (index = free_space(t(code: 'state.using_cache'))) >= 0 # free space by longest status
84
+ str.slice(0..index)
85
+ else
86
+ str.slice(0)
87
+ end
88
+ end
89
+
90
+ def free_space(str)
91
+ base_time = log_time? ? log_time.length : 0
92
+ indent = log_indent.length
93
+ str = ::Paint.unpaint(str.to_s).length
94
+ time = 15
95
+ terminal_width - base_time - str - indent - time
96
+ end
97
+
98
+ def terminal_width
99
+ @terminal_width ||= `tput cols`.strip.to_i
100
+ end
101
+ end
102
+ end # Logging
103
+ end # Project
104
+ end # Dapp
@@ -0,0 +1,16 @@
1
+ module Dapp
2
+ # Project
3
+ class Project
4
+ # Paint
5
+ module Paint
6
+ def paint_initialize
7
+ ::Paint.mode = case cli_options[:log_color]
8
+ when 'auto' then STDOUT.tty? ? 8 : 0
9
+ when 'on' then 8
10
+ when 'off' then 0
11
+ else raise
12
+ end
13
+ end
14
+ end # Paint
15
+ end # Project
16
+ end # Dapp
@@ -0,0 +1,77 @@
1
+ module Dapp
2
+ # Project
3
+ class Project
4
+ # SshAgent
5
+ module SshAgent
6
+ class << self
7
+ def included(_base)
8
+ ::Dapp::Helper::Shellout.default_env_keys << 'SSH_AUTH_SOCK'
9
+ end
10
+ end # << self
11
+
12
+ def run_ssh_agent
13
+ sock_name = "dapp-ssh-#{SecureRandom.uuid}"
14
+
15
+ "/tmp/#{sock_name}".tap do |sock_path|
16
+ Process.fork do
17
+ Prctl.call(Prctl::PR_SET_PDEATHSIG, Signal.list['TERM'], 0, 0, 0)
18
+
19
+ Process.setproctitle sock_name
20
+
21
+ @ssh_agent_pid = nil
22
+
23
+ Signal.trap('INT') { }
24
+ Signal.trap('TERM') { Process.kill('TERM', @ssh_agent_pid) if @ssh_agent_pid }
25
+
26
+ @ssh_agent_pid = Process.fork do
27
+ STDOUT.reopen '/dev/null', 'a'
28
+ STDERR.reopen '/dev/null', 'a'
29
+ exec 'ssh-agent', '-d', '-a', sock_path
30
+ end
31
+
32
+ Process.wait @ssh_agent_pid
33
+ end
34
+
35
+ begin
36
+ ::Timeout.timeout(10) do
37
+ until File.exist? sock_path
38
+ sleep 0.001
39
+ end
40
+ end
41
+ rescue ::Timeout::Error
42
+ raise ::Dapp::Error::Project, code: :cannot_run_ssh_agent
43
+ end
44
+ end # sock_path
45
+ end
46
+
47
+ def add_ssh_key(ssh_key_path)
48
+ shellout! "ssh-add #{ssh_key_path}", env: {SSH_AUTH_SOCK: ssh_auth_sock(force_run_agent: true)}
49
+ end
50
+
51
+ def ssh_auth_sock(force_run_agent: false)
52
+ @ssh_auth_sock ||= begin
53
+ system_ssh_auth_sock = nil
54
+ system_ssh_auth_sock = File.expand_path(ENV['SSH_AUTH_SOCK']) if ENV['SSH_AUTH_SOCK'] && File.exist?(ENV['SSH_AUTH_SOCK'])
55
+
56
+ if force_run_agent
57
+ run_ssh_agent.tap { |ssh_auth_sock| ENV['SSH_AUTH_SOCK'] = ssh_auth_sock }
58
+ else
59
+ system_ssh_auth_sock
60
+ end
61
+ end
62
+ end
63
+
64
+ def setup_ssh_agent
65
+ return unless cli_options[:ssh_key]
66
+
67
+ cli_options[:ssh_key].each do |ssh_key|
68
+ raise ::Dapp::Error::Project, code: :ssh_key_not_found,
69
+ data: { path: ssh_key } unless File.exist? ssh_key
70
+
71
+ File.chmod 0600, ssh_key
72
+ add_ssh_key ssh_key
73
+ end
74
+ end
75
+ end # SshAgent
76
+ end # Project
77
+ end # Dapp
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  module Dapp
3
- VERSION = '0.5.13'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
  BUILD_CACHE_VERSION = 3
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-14 00:00:00.000000000 Z
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -314,6 +314,26 @@ dependencies:
314
314
  - - ">="
315
315
  - !ruby/object:Gem::Version
316
316
  version: 1.0.1
317
+ - !ruby/object:Gem::Dependency
318
+ name: ruby-prof
319
+ requirement: !ruby/object:Gem::Requirement
320
+ requirements:
321
+ - - ">="
322
+ - !ruby/object:Gem::Version
323
+ version: 0.15.9
324
+ - - "<"
325
+ - !ruby/object:Gem::Version
326
+ version: '1.0'
327
+ type: :development
328
+ prerelease: false
329
+ version_requirements: !ruby/object:Gem::Requirement
330
+ requirements:
331
+ - - ">="
332
+ - !ruby/object:Gem::Version
333
+ version: 0.15.9
334
+ - - "<"
335
+ - !ruby/object:Gem::Version
336
+ version: '1.0'
317
337
  description: Build docker packaged apps using chef or shell
318
338
  email:
319
339
  - dmitry.stolyarov@flant.com
@@ -327,36 +347,34 @@ files:
327
347
  - config/en/net_status.yml
328
348
  - lib/dapp.rb
329
349
  - lib/dapp/application.rb
330
- - lib/dapp/application/deps/gitartifact.rb
331
350
  - lib/dapp/application/git_artifact.rb
332
- - lib/dapp/application/logging.rb
333
351
  - lib/dapp/application/path.rb
334
- - lib/dapp/application/system_shellout.rb
335
352
  - lib/dapp/application/tags.rb
336
353
  - lib/dapp/build/stage/artifact.rb
337
354
  - lib/dapp/build/stage/base.rb
338
- - lib/dapp/build/stage/chef_cookbooks.rb
355
+ - lib/dapp/build/stage/before_install.rb
356
+ - lib/dapp/build/stage/before_setup.rb
339
357
  - lib/dapp/build/stage/docker_instructions.rb
340
358
  - lib/dapp/build/stage/from.rb
341
- - lib/dapp/build/stage/infra_install.rb
342
- - lib/dapp/build/stage/infra_setup.rb
343
- - lib/dapp/build/stage/install.rb
359
+ - lib/dapp/build/stage/ga_archive.rb
360
+ - lib/dapp/build/stage/ga_archive_dependencies.rb
361
+ - lib/dapp/build/stage/ga_base.rb
362
+ - lib/dapp/build/stage/ga_dependencies_base.rb
363
+ - lib/dapp/build/stage/ga_latest_patch.rb
364
+ - lib/dapp/build/stage/install/ga_post_install_patch.rb
365
+ - lib/dapp/build/stage/install/ga_post_install_patch_dependencies.rb
366
+ - lib/dapp/build/stage/install/ga_pre_install_patch.rb
367
+ - lib/dapp/build/stage/install/ga_pre_install_patch_dependencies.rb
368
+ - lib/dapp/build/stage/install/install.rb
344
369
  - lib/dapp/build/stage/mod/artifact.rb
370
+ - lib/dapp/build/stage/mod/group.rb
345
371
  - lib/dapp/build/stage/mod/logging.rb
346
- - lib/dapp/build/stage/setup.rb
347
- - lib/dapp/build/stage/source_1.rb
348
- - lib/dapp/build/stage/source_1_archive.rb
349
- - lib/dapp/build/stage/source_1_archive_dependencies.rb
350
- - lib/dapp/build/stage/source_1_dependencies.rb
351
- - lib/dapp/build/stage/source_2.rb
352
- - lib/dapp/build/stage/source_2_dependencies.rb
353
- - lib/dapp/build/stage/source_3.rb
354
- - lib/dapp/build/stage/source_3_dependencies.rb
355
- - lib/dapp/build/stage/source_4.rb
356
- - lib/dapp/build/stage/source_4_dependencies.rb
357
- - lib/dapp/build/stage/source_5.rb
358
- - lib/dapp/build/stage/source_base.rb
359
- - lib/dapp/build/stage/source_dependencies_base.rb
372
+ - lib/dapp/build/stage/setup/chef_cookbooks.rb
373
+ - lib/dapp/build/stage/setup/ga_post_setup_patch.rb
374
+ - lib/dapp/build/stage/setup/ga_post_setup_patch_dependencies.rb
375
+ - lib/dapp/build/stage/setup/ga_pre_setup_patch.rb
376
+ - lib/dapp/build/stage/setup/ga_pre_setup_patch_dependencies.rb
377
+ - lib/dapp/build/stage/setup/setup.rb
360
378
  - lib/dapp/builder/base.rb
361
379
  - lib/dapp/builder/chef.rb
362
380
  - lib/dapp/builder/chef/berksfile.rb
@@ -365,11 +383,13 @@ files:
365
383
  - lib/dapp/builder/shell.rb
366
384
  - lib/dapp/cli.rb
367
385
  - lib/dapp/cli/base.rb
386
+ - lib/dapp/cli/bp.rb
368
387
  - lib/dapp/cli/build.rb
388
+ - lib/dapp/cli/cleanup.rb
369
389
  - lib/dapp/cli/list.rb
370
390
  - lib/dapp/cli/push.rb
371
391
  - lib/dapp/cli/run.rb
372
- - lib/dapp/cli/smartpush.rb
392
+ - lib/dapp/cli/spush.rb
373
393
  - lib/dapp/cli/stages.rb
374
394
  - lib/dapp/cli/stages/cleanup.rb
375
395
  - lib/dapp/cli/stages/flush.rb
@@ -380,16 +400,23 @@ files:
380
400
  - lib/dapp/config/git_artifact.rb
381
401
  - lib/dapp/config/main.rb
382
402
  - lib/dapp/config/shell.rb
383
- - lib/dapp/controller.rb
403
+ - lib/dapp/docker_registry.rb
404
+ - lib/dapp/docker_registry/base.rb
405
+ - lib/dapp/docker_registry/default.rb
406
+ - lib/dapp/docker_registry/mod/authorization.rb
407
+ - lib/dapp/docker_registry/mod/request.rb
384
408
  - lib/dapp/error/application.rb
385
409
  - lib/dapp/error/base.rb
386
410
  - lib/dapp/error/build.rb
387
411
  - lib/dapp/error/config.rb
388
- - lib/dapp/error/controller.rb
389
412
  - lib/dapp/error/dappfile.rb
413
+ - lib/dapp/error/image.rb
414
+ - lib/dapp/error/project.rb
415
+ - lib/dapp/error/registry.rb
390
416
  - lib/dapp/error/shellout.rb
391
417
  - lib/dapp/exception/base.rb
392
418
  - lib/dapp/exception/introspect_image.rb
419
+ - lib/dapp/exception/registry.rb
393
420
  - lib/dapp/filelock.rb
394
421
  - lib/dapp/git_artifact.rb
395
422
  - lib/dapp/git_repo/base.rb
@@ -397,7 +424,6 @@ files:
397
424
  - lib/dapp/git_repo/remote.rb
398
425
  - lib/dapp/helper/cli.rb
399
426
  - lib/dapp/helper/i18n.rb
400
- - lib/dapp/helper/log.rb
401
427
  - lib/dapp/helper/net_status.rb
402
428
  - lib/dapp/helper/paint.rb
403
429
  - lib/dapp/helper/sha256.rb
@@ -407,6 +433,27 @@ files:
407
433
  - lib/dapp/image/argument.rb
408
434
  - lib/dapp/image/docker.rb
409
435
  - lib/dapp/image/stage.rb
436
+ - lib/dapp/lock/base.rb
437
+ - lib/dapp/lock/error.rb
438
+ - lib/dapp/lock/file.rb
439
+ - lib/dapp/prctl.rb
440
+ - lib/dapp/project.rb
441
+ - lib/dapp/project/command/bp.rb
442
+ - lib/dapp/project/command/build.rb
443
+ - lib/dapp/project/command/cleanup.rb
444
+ - lib/dapp/project/command/common.rb
445
+ - lib/dapp/project/command/list.rb
446
+ - lib/dapp/project/command/push.rb
447
+ - lib/dapp/project/command/run.rb
448
+ - lib/dapp/project/command/spush.rb
449
+ - lib/dapp/project/command/stages_cleanup.rb
450
+ - lib/dapp/project/command/stages_flush.rb
451
+ - lib/dapp/project/dappfile.rb
452
+ - lib/dapp/project/lock.rb
453
+ - lib/dapp/project/logging/base.rb
454
+ - lib/dapp/project/logging/process.rb
455
+ - lib/dapp/project/paint.rb
456
+ - lib/dapp/project/ssh_agent.rb
410
457
  - lib/dapp/version.rb
411
458
  homepage: https://github.com/flant/dapp
412
459
  licenses:
@@ -1,39 +0,0 @@
1
- module Dapp
2
- # Application
3
- class Application
4
- # Deps
5
- module Deps
6
- # Gitartifact
7
- module Gitartifact
8
- GITARTIFACT_IMAGE = 'dappdeps/gitartifact:0.1.5'.freeze
9
-
10
- def gitartifact_container_name # FIXME: hashsum(image) or dockersafe()
11
- GITARTIFACT_IMAGE.tr('/', '_').tr(':', '_')
12
- end
13
-
14
- def gitartifact_container
15
- @gitartifact_container ||= begin
16
- if shellout("docker inspect #{gitartifact_container_name}").exitstatus.nonzero?
17
- log_secondary_process(t(code: 'process.gitartifact_container_loading'), short: true) do
18
- shellout ['docker run',
19
- '--restart=no',
20
- "--name #{gitartifact_container_name}",
21
- "--volume /.dapp/deps/gitartifact #{GITARTIFACT_IMAGE}",
22
- '2>/dev/null'].join(' ')
23
- end
24
- end
25
- gitartifact_container_name
26
- end
27
- end
28
-
29
- def git_path
30
- '/.dapp/deps/gitartifact/bin/git'
31
- end
32
-
33
- def sudo_path
34
- '/.dapp/deps/gitartifact/bin/sudo'
35
- end
36
- end # Gitartifact
37
- end # Deps
38
- end # Application
39
- end # Dapp
@@ -1,120 +0,0 @@
1
- module Dapp
2
- # Application
3
- class Application
4
- # Logging
5
- module Logging
6
- def log?
7
- !log_quiet?
8
- end
9
-
10
- def log_quiet?
11
- cli_options[:log_quiet]
12
- end
13
-
14
- def log_verbose?
15
- cli_options[:log_verbose]
16
- end
17
-
18
- def log_time?
19
- cli_options[:log_time]
20
- end
21
-
22
- def dry_run?
23
- cli_options[:dry_run]
24
- end
25
-
26
- DEFAULT_STYLE = {
27
- message: :step,
28
- process: :secondary,
29
- status: :secondary,
30
- success: :success,
31
- failed: :warning,
32
- time: :default
33
- }.freeze
34
-
35
- def log_state(message, state:, styles: {})
36
- styles[:message] ||= DEFAULT_STYLE[:message]
37
- styles[:status] ||= DEFAULT_STYLE[:status]
38
-
39
- message = slice(message)
40
- state = rjust(state, message)
41
- formatted_message = paint_string(message, styles[:message])
42
- formatted_status = paint_string(state, styles[:status])
43
-
44
- log "#{formatted_message}#{formatted_status}"
45
- end
46
-
47
- def log_process(message, process: nil, short: false, style: {}, &blk)
48
- style[:message] ||= DEFAULT_STYLE[:message]
49
- style[:process] ||= DEFAULT_STYLE[:process]
50
- style[:failed] ||= DEFAULT_STYLE[:failed]
51
- style[:success] ||= DEFAULT_STYLE[:success]
52
-
53
- if log_verbose? && !short
54
- process ||= t(code: 'status.process.default')
55
- log_process_verbose(message, process: process, style: style, &blk)
56
- else
57
- log_process_short(message, style: style, &blk)
58
- end
59
- end
60
-
61
- def log_secondary_process(message, **kwargs, &blk)
62
- log_process(message, **kwargs.merge(style: { message: :secondary, success: :secondary }), &blk)
63
- end
64
-
65
- def log_process_verbose(message, process:, style: {}, &blk)
66
- process = paint_string(rjust(process, message), style[:process])
67
- info = paint_string(message, style[:message]) + process
68
- success_message = paint_string(slice(message), style[:message]) +
69
- paint_string(rjust(t(code: 'status.success.default'), message), style[:success])
70
- failed_message = paint_string(slice(message) +
71
- rjust(t(code: 'status.failed.default'), message), style[:failed])
72
- log_process_default(info, success_message, failed_message, &blk)
73
- end
74
-
75
- def log_process_short(message, style: {}, &blk)
76
- info = "#{paint_string(slice(message), style[:message])} ... "
77
- success_message = paint_string(rjust(t(code: 'status.success.default'), info), style[:success])
78
- failed_message = paint_string(rjust(t(code: 'status.failed.default'), info), style[:failed])
79
- log_process_default(info, success_message, failed_message, inline: true, &blk)
80
- end
81
-
82
- def log_process_default(info, success_message, failed_message, inline: false)
83
- log info, inline: inline
84
- message = success_message
85
- start = Time.now
86
- yield
87
- rescue Exception::Base, Error::Base, SignalException, StandardError => _e
88
- message = failed_message
89
- raise
90
- ensure
91
- time = paint_string("#{(Time.now - start).round(2)} sec", DEFAULT_STYLE[:time])
92
- log "#{message} #{time}", indent: !inline, time: !inline
93
- end
94
-
95
- def rjust(str, start_string)
96
- str.rjust(free_space(start_string))
97
- end
98
-
99
- def slice(str)
100
- if (index = free_space(t(code: 'state.using_cache'))) >= 0 # free space by longest status
101
- str.slice(0..index)
102
- else
103
- str.slice(0)
104
- end
105
- end
106
-
107
- def free_space(str)
108
- base_time = log_time? ? log_time.length : 0
109
- indent = log_indent.length
110
- str = Paint.unpaint(str.to_s).length
111
- time = 15
112
- terminal_width - base_time - str - indent - time
113
- end
114
-
115
- def terminal_width
116
- @terminal_width ||= `tput cols`.strip.to_i
117
- end
118
- end # Logging
119
- end # Application
120
- end # Dapp