avm-tools 0.59.0 → 0.62.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/cached_download.rb +39 -0
  3. data/lib/avm/eac_redmine_base0/core_update.rb +110 -0
  4. data/lib/avm/eac_redmine_base0/data_unit.rb +27 -0
  5. data/lib/avm/eac_redmine_base0/deploy.rb +36 -0
  6. data/lib/avm/eac_redmine_base0/instance.rb +38 -0
  7. data/lib/avm/launcher/context/instance_manager.rb +76 -0
  8. data/lib/avm/launcher/context/instance_manager/cached_instance.rb +37 -0
  9. data/lib/avm/launcher/context/instance_manager/cached_instances.rb +35 -0
  10. data/lib/avm/launcher/errors/base.rb +10 -0
  11. data/lib/avm/launcher/errors/non_project.rb +15 -0
  12. data/lib/avm/launcher/instances/base.rb +94 -0
  13. data/lib/avm/launcher/instances/base/cache.rb +43 -0
  14. data/lib/avm/local_projects/instance.rb +8 -1
  15. data/lib/avm/local_projects/jobs/update.rb +29 -0
  16. data/lib/avm/projects/stereotype.rb +17 -10
  17. data/lib/avm/projects/stereotypes/git/local_project_mixin.rb +19 -0
  18. data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +5 -4
  19. data/lib/avm/projects/stereotypes/ruby_gem/local_project_mixin.rb +19 -0
  20. data/lib/avm/projects/stereotypes/ruby_gem/update.rb +59 -0
  21. data/lib/avm/stereotypes/eac_webapp_base0/runner/deploy.rb +3 -1
  22. data/lib/avm/sync.rb +94 -0
  23. data/lib/avm/tools/runner/eac_redmine_base0.rb +2 -2
  24. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +67 -0
  25. data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +1 -1
  26. data/lib/avm/tools/runner/git/issue.rb +43 -4
  27. data/lib/avm/tools/runner/local_project.rb +1 -1
  28. data/lib/avm/tools/runner/local_project/update.rb +26 -0
  29. data/lib/avm/tools/version.rb +1 -1
  30. data/lib/eac_launcher/context.rb +2 -2
  31. data/lib/eac_launcher/context/instance_discovery.rb +2 -2
  32. data/lib/eac_launcher/git/base/dirty_files.rb +5 -14
  33. data/lib/eac_launcher/git/sub_warp_base.rb +3 -2
  34. data/lib/eac_launcher/instances.rb +2 -2
  35. data/lib/eac_launcher/instances/error.rb +7 -3
  36. data/lib/eac_launcher/paths/logical.rb +2 -2
  37. data/lib/eac_launcher/publish/base.rb +2 -2
  38. data/template/avm/{stereotypes/eac_redmine_base0 → eac_redmine_base0}/deploy/config/install.sh.template +0 -0
  39. data/template/avm/{stereotypes/eac_redmine_base0 → eac_redmine_base0}/deploy/config/secrets.yml +0 -0
  40. data/vendor/eac_git/lib/eac_git/local.rb +1 -1
  41. data/vendor/eac_git/lib/eac_git/local/dirty_files.rb +38 -0
  42. data/vendor/eac_git/lib/eac_git/version.rb +1 -1
  43. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
  44. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +2 -0
  45. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +2 -0
  46. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +2 -0
  47. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +5 -0
  48. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +8 -8
  49. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  50. metadata +25 -11
  51. data/lib/avm/stereotypes/eac_redmine_base0/data_unit.rb +0 -29
  52. data/lib/avm/stereotypes/eac_redmine_base0/deploy.rb +0 -38
  53. data/lib/avm/stereotypes/eac_redmine_base0/instance.rb +0 -40
  54. data/lib/eac_launcher/context/instance_manager.rb +0 -94
  55. data/lib/eac_launcher/instances/base.rb +0 -91
  56. data/lib/eac_launcher/instances/base/cache.rb +0 -41
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base/cache'
4
+ require 'avm/launcher/errors/non_project'
5
+
6
+ module Avm
7
+ module Launcher
8
+ module Instances
9
+ module Base
10
+ class << self
11
+ def extend_object(object)
12
+ object.extend ::EacRubyUtils::SimpleCache
13
+ object.extend ::EacRubyUtils::Console::Speaker
14
+ object.extend ::Avm::Launcher::Instances::Base::Cache
15
+ super
16
+ end
17
+
18
+ def instanciate(path, parent)
19
+ unless path.is_a?(::Avm::Launcher::Instances::Base)
20
+ raise ::Avm::Launcher::Errors::NonProject, path unless path.project?
21
+
22
+ path.extend(::Avm::Launcher::Instances::Base)
23
+ path.parent = parent
24
+ end
25
+ path
26
+ end
27
+ end
28
+
29
+ attr_accessor :parent
30
+
31
+ def name
32
+ logical
33
+ end
34
+
35
+ def stereotype?(stereotype)
36
+ stereotypes.include?(stereotype)
37
+ end
38
+
39
+ def to_parent_path
40
+ return self unless @parent
41
+
42
+ logical.gsub(/\A#{Regexp.quote(@parent.logical)}/, '')
43
+ end
44
+
45
+ def project?
46
+ stereotypes.any?
47
+ end
48
+
49
+ def publish_run
50
+ stereotypes.each do |s|
51
+ next unless publish?(s)
52
+
53
+ infov(name, "publishing #{s.label}")
54
+ s.publish_class.new(self).run
55
+ end
56
+ end
57
+
58
+ def publish_check
59
+ stereotypes.each do |s|
60
+ next unless publish?(s)
61
+
62
+ puts "#{name.to_s.cyan}|#{s.label}|" \
63
+ "#{s.publish_class.new(self).check}"
64
+ end
65
+ end
66
+
67
+ def project_name
68
+ ::File.basename(logical)
69
+ end
70
+
71
+ def included?
72
+ !::EacLauncher::Context.current.settings.excluded_projects.include?(project_name)
73
+ end
74
+
75
+ def to_h
76
+ super.to_h.merge(parent: parent ? parent.logical : nil)
77
+ end
78
+
79
+ private
80
+
81
+ def publish?(stereotype)
82
+ return false unless stereotype.publish_class
83
+
84
+ filter = ::EacLauncher::Context.current.publish_options[:stereotype]
85
+ filter.blank? ? true : filter == stereotype.name.demodulize
86
+ end
87
+
88
+ def options_uncached
89
+ ::EacLauncher::Context.current.settings.instance_settings(self)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Launcher
5
+ module Instances
6
+ module Base
7
+ module Cache
8
+ def cache_path(subpath)
9
+ File.join(cache_root, subpath)
10
+ end
11
+
12
+ def cache_key(key, &block)
13
+ v = cache_key_get(key)
14
+ return v if v.present? || block.nil?
15
+
16
+ v = yield
17
+ cache_key_write(key, v)
18
+ v
19
+ end
20
+
21
+ private
22
+
23
+ def cache_key_get(key)
24
+ File.file?(cache_key_path(key)) ? File.read(cache_key_path(key)) : nil
25
+ end
26
+
27
+ def cache_key_write(key, value)
28
+ FileUtils.mkdir_p(File.dirname(cache_key_path(key)))
29
+ File.write(cache_key_path(key), value)
30
+ end
31
+
32
+ def cache_key_path(key)
33
+ File.join(cache_root, 'keys', key.parameterize)
34
+ end
35
+
36
+ def cache_root
37
+ File.join(::EacLauncher::Context.current.cache_root, name.parameterize)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -5,11 +5,12 @@ require 'eac_ruby_utils/core_ext'
5
5
  require 'avm/projects/stereotypes'
6
6
 
7
7
  module Avm
8
- module LocalProject
8
+ module LocalProjects
9
9
  class Instance
10
10
  enable_simple_cache
11
11
  common_constructor :path do
12
12
  self.path = path.to_pathname
13
+ source_stereotypes_mixins
13
14
  end
14
15
 
15
16
  # Backward compatibility with [EacLauncher::Paths::Logical].
@@ -23,6 +24,12 @@ module Avm
23
24
  def stereotypes_uncached
24
25
  ::Avm::Projects::Stereotypes.list.select { |s| s.match?(self) }
25
26
  end
27
+
28
+ def source_stereotypes_mixins
29
+ stereotypes.each do |s|
30
+ s.local_project_mixin_module.if_present { |v| extend(v) }
31
+ end
32
+ end
26
33
  end
27
34
  end
28
35
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module LocalProjects
7
+ module Jobs
8
+ class Update
9
+ enable_console_speaker
10
+ common_constructor :instance
11
+
12
+ def run
13
+ instance.stereotypes.each { |stereotype| run_stereotype(stereotype) }
14
+ end
15
+
16
+ private
17
+
18
+ def run_stereotype(stereotype)
19
+ if stereotype.update_class.present?
20
+ puts stereotype.label + ': update class found. Running...'
21
+ stereotype.update_class.new(instance).run
22
+ else
23
+ puts stereotype.label + ': update class not found'
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -30,22 +30,29 @@ module Avm
30
30
  end
31
31
 
32
32
  def stereotype_name
33
- name.gsub(/^.*::/, '')
33
+ name.demodulize
34
34
  end
35
35
 
36
- def publish_class
37
- sub_class('Publish')
38
- end
39
-
40
- def warp_class
41
- sub_class('Warp')
36
+ {
37
+ local_project_mixin: ::Module,
38
+ publish: ::Class,
39
+ update: ::Class,
40
+ warp: ::Class
41
+ }.each do |name, is_a|
42
+ define_method "#{name}_#{is_a.name.underscore}" do
43
+ sub_constant(name.to_s.camelcase, is_a)
44
+ end
42
45
  end
43
46
 
44
47
  private
45
48
 
46
- def sub_class(sub_class_name)
47
- klass = const_get(sub_class_name)
48
- klass.is_a?(Class) ? klass : nil
49
+ def sub_constant(constant_name, is_a)
50
+ constant = const_get(constant_name)
51
+ unless is_a.if_present(true) { |v| constant.is_a?(v) }
52
+ raise("#{constant} is not a #{is_a}")
53
+ end
54
+
55
+ constant
49
56
  rescue NameError
50
57
  nil
51
58
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_git/local'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Projects
8
+ module Stereotypes
9
+ class Git
10
+ module LocalProjectMixin
11
+ # @return [EacGit::Local]
12
+ def git_repo
13
+ @git_repo ||= ::EacGit::Local.new(path)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'eac_ruby_utils/simple_cache'
4
4
  require 'eac_launcher/git/sub_warp_base'
5
- require 'eac_launcher/instances/error'
5
+ require 'avm/launcher/errors/base'
6
6
  require 'eac_launcher/paths/real'
7
7
  require 'eac_launcher/vendor/github'
8
8
 
@@ -32,8 +32,9 @@ module Avm
32
32
  return if parent_git_warped.rev_parse(subrepo_parent_hash) &&
33
33
  parent_git_warped.descendant?('HEAD', subrepo_parent_hash)
34
34
 
35
- raise EacLauncher::Instances::Error, "Subrepo parent hash \"#{subrepo_parent_hash}\""\
36
- " not found in \"#{parent_git_warped}\""
35
+ raise EacLauncher::Instances::Errors::Base,
36
+ "Subrepo parent hash \"#{subrepo_parent_hash}\"" \
37
+ " not found in \"#{parent_git_warped}\""
37
38
  end
38
39
 
39
40
  def subrepo_parent_hash
@@ -41,7 +42,7 @@ module Avm
41
42
  h = data['Pull Parent']
42
43
  return h if h.present?
43
44
 
44
- raise EacLauncher::Instances::Error, "Subrepo parent hash is blank: #{data}"
45
+ raise EacLauncher::Instances::Errors::Base, "Subrepo parent hash is blank: #{data}"
45
46
  end
46
47
 
47
48
  def init_aux
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gems_utils/gem'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Projects
8
+ module Stereotypes
9
+ class RubyGem
10
+ module LocalProjectMixin
11
+ # @return [EacRubyGemsUtils::Gem]
12
+ def ruby_gem
13
+ @ruby_gem ||= ::EacRubyGemsUtils::Gem.new(path)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Projects
7
+ module Stereotypes
8
+ class RubyGem
9
+ class Update
10
+ enable_console_speaker
11
+ common_constructor :instance
12
+
13
+ def run
14
+ gemfile_lock_checkout
15
+ bundle_update
16
+ gemfile_lock_commit
17
+ end
18
+
19
+ private
20
+
21
+ def bundle_update
22
+ infom 'Running "bundle update"...'
23
+ instance.ruby_gem.bundle('update').execute!
24
+ infom 'Running "bundle install"...'
25
+ instance.ruby_gem.bundle('install').execute!
26
+ end
27
+
28
+ def gemfile_lock_checkout
29
+ return unless instance.respond_to?(:git_repo)
30
+
31
+ infom 'Checkouting Gemfile.lock...'
32
+ instance.git_repo.command('checkout', '--',
33
+ instance.ruby_gem.gemfile_lock_path.to_path).execute!
34
+ end
35
+
36
+ def gemfile_lock_commit
37
+ return unless instance.respond_to?(:git_repo)
38
+
39
+ if gemfile_lock_changed?
40
+ infom 'Commiting Gemfile.lock...'
41
+ instance.git_repo.command('commit', '-m', gemfile_lock_commit_message, '--',
42
+ instance.ruby_gem.gemfile_lock_path).execute!
43
+ else
44
+ infom 'Gemfile.lock did not change'
45
+ end
46
+ end
47
+
48
+ def gemfile_lock_commit_message
49
+ 'Todas as gems: atualiza.'
50
+ end
51
+
52
+ def gemfile_lock_changed?
53
+ instance.git_repo.dirty_file?(instance.ruby_gem.gemfile_lock_path)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -32,7 +32,9 @@ module Avm
32
32
  end
33
33
 
34
34
  def stereotype_module
35
- "Avm::Stereotypes::#{stereotype_name}".constantize
35
+ ::Avm::Stereotypes.const_get(stereotype_name)
36
+ rescue ::NameError
37
+ ::Avm.const_get(stereotype_name)
36
38
  end
37
39
 
38
40
  def stereotype_name
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ class Sync
7
+ attr_reader :excludes, :includes
8
+
9
+ common_constructor :source_path, :target_path do
10
+ self.source_path = source_path.to_pathname
11
+ self.target_path = target_path.to_pathname
12
+ @excludes = []
13
+ @includes = []
14
+ end
15
+
16
+ def run
17
+ clear_target
18
+ copy
19
+ end
20
+
21
+ def add_exclude(exclude)
22
+ excludes << exclude
23
+
24
+ self
25
+ end
26
+
27
+ def add_excludes(*excludes)
28
+ excludes.each { |exclude| add_exclude(exclude) }
29
+
30
+ self
31
+ end
32
+
33
+ def add_include(include)
34
+ includes << include
35
+
36
+ self
37
+ end
38
+
39
+ def add_includes(*includes)
40
+ includes.each { |include| add_include(include) }
41
+
42
+ self
43
+ end
44
+
45
+ def move_mode(value)
46
+ @move_mode = value
47
+
48
+ self
49
+ end
50
+
51
+ def move_mode?
52
+ @move_mode ? true : false
53
+ end
54
+
55
+ private
56
+
57
+ def clear_target
58
+ target_remove(target_path)
59
+ target_path.children.each { |tchild| target_remove(tchild) }
60
+ end
61
+
62
+ def copy
63
+ source_path.children.each do |schild|
64
+ ::FileUtils.cp_r(schild.to_path, target_path.to_path)
65
+ schild.rmtree if move_mode?
66
+ end
67
+ end
68
+
69
+ def source_to_target_path(source_path)
70
+ source_path.relative_path_from(self.source_path).expand_path(target_path)
71
+ end
72
+
73
+ def target_remove(tpath)
74
+ return if skip_target_path?(tpath)
75
+
76
+ if tpath.directory?
77
+ tpath.children.each { |tchild| target_remove(tchild) }
78
+ tpath.rmdir if tpath.children.empty?
79
+ elsif tpath.file?
80
+ tpath.unlink
81
+ end
82
+ end
83
+
84
+ def skip_target_path?(tpath)
85
+ skip_path?(tpath.relative_path_from(target_path))
86
+ end
87
+
88
+ def skip_path?(relpath)
89
+ relpath = relpath.expand_path('/')
90
+ excludes.any? { |exclude| relpath.fnmatch?(exclude) } &&
91
+ includes.none? { |include| relpath.fnmatch?(include) }
92
+ end
93
+ end
94
+ end