avm-tools 0.71.0 → 0.75.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/{stereotypes/eac_rails_base0.rb → eac_rails_base0.rb} +1 -3
  3. data/lib/avm/eac_rails_base0/instance.rb +2 -5
  4. data/lib/avm/{rails/runners.rb → eac_rails_base1.rb} +2 -4
  5. data/lib/avm/{rails → eac_rails_base1}/instance.rb +8 -3
  6. data/lib/avm/eac_rails_base1/runner.rb +12 -0
  7. data/lib/avm/eac_rails_base1/runner/bundle.rb +28 -0
  8. data/lib/avm/eac_rails_base1/runner/code_runner.rb +28 -0
  9. data/lib/avm/eac_rails_base1/runner_with/bundle.rb +57 -0
  10. data/lib/avm/{stereotypes/rails.rb → eac_redmine_base0.rb} +2 -4
  11. data/lib/avm/eac_redmine_base0/instance.rb +2 -4
  12. data/lib/avm/{stereotypes/eac_ubuntu_base0.rb → eac_ubuntu_base0.rb} +1 -3
  13. data/lib/avm/{stereotypes/eac_webapp_base0.rb → eac_webapp_base0.rb} +1 -3
  14. data/lib/avm/eac_webapp_base0/deploy.rb +17 -40
  15. data/lib/avm/eac_webapp_base0/deploy/build.rb +48 -0
  16. data/lib/avm/eac_webapp_base0/deploy/git_info.rb +13 -0
  17. data/lib/avm/eac_webapp_base0/deploy/version.rb +4 -0
  18. data/lib/avm/eac_webapp_base0/deploy/write_on_target.rb +18 -0
  19. data/lib/avm/eac_webapp_base0/instance.rb +2 -2
  20. data/lib/avm/eac_webapp_base0/runner.rb +12 -0
  21. data/lib/avm/eac_webapp_base0/runner/apache_host.rb +2 -3
  22. data/lib/avm/eac_webapp_base0/runner/data.rb +1 -1
  23. data/lib/avm/eac_webapp_base0/runner/data/dump.rb +1 -1
  24. data/lib/avm/eac_webapp_base0/runner/data/load.rb +1 -1
  25. data/lib/avm/eac_webapp_base0/runner/deploy.rb +3 -16
  26. data/lib/avm/eac_wordpress_base0.rb +9 -0
  27. data/lib/avm/eac_wordpress_base0/apache_host.rb +25 -0
  28. data/lib/avm/eac_wordpress_base0/deploy.rb +10 -0
  29. data/lib/avm/eac_wordpress_base0/instance.rb +24 -0
  30. data/lib/avm/eac_writings_base0.rb +9 -0
  31. data/lib/avm/eac_writings_base0/apache_host.rb +17 -0
  32. data/lib/avm/eac_writings_base0/commons.rb +12 -0
  33. data/lib/avm/eac_writings_base0/deploy.rb +36 -0
  34. data/lib/avm/eac_writings_base0/file_build.rb +45 -0
  35. data/lib/avm/eac_writings_base0/file_build/base_stereotype.rb +19 -0
  36. data/lib/avm/eac_writings_base0/file_build/chapter_index.rb +23 -0
  37. data/lib/avm/eac_writings_base0/file_build/tex_source.rb +33 -0
  38. data/lib/avm/eac_writings_base0/instance.rb +11 -0
  39. data/lib/avm/eac_writings_base0/project.rb +33 -0
  40. data/lib/avm/eac_writings_base0/project_build.rb +117 -0
  41. data/lib/avm/eac_writings_base0/project_build/chapters_content.rb +47 -0
  42. data/lib/avm/eac_writings_base0/project_build/copy_files.rb +42 -0
  43. data/lib/avm/executables.rb +1 -1
  44. data/lib/avm/files/appendable.rb +55 -0
  45. data/lib/avm/files/appendable/file_content.rb +24 -0
  46. data/lib/avm/files/appendable/plain_directory.rb +25 -0
  47. data/lib/avm/files/appendable/resource_base.rb +13 -0
  48. data/lib/avm/files/appendable/tar_output_command.rb +26 -0
  49. data/lib/avm/files/appendable/templatized_directory.rb +28 -0
  50. data/lib/avm/files/appender.rb +11 -0
  51. data/lib/avm/files/deploy.rb +72 -0
  52. data/lib/avm/git/commit/deploy.rb +8 -61
  53. data/lib/avm/instances/application.rb +4 -0
  54. data/lib/avm/instances/base.rb +2 -1
  55. data/lib/avm/instances/base/auto_values.rb +2 -1
  56. data/lib/avm/instances/base/auto_values/access.rb +5 -4
  57. data/lib/avm/instances/base/auto_values/admin.rb +2 -2
  58. data/lib/avm/instances/base/auto_values/database.rb +1 -1
  59. data/lib/avm/instances/base/auto_values/filesystem.rb +6 -2
  60. data/lib/avm/instances/base/auto_values/mailer.rb +34 -0
  61. data/lib/avm/instances/base/auto_values/ruby.rb +1 -1
  62. data/lib/avm/instances/base/auto_values/system.rb +2 -2
  63. data/lib/avm/instances/entry.rb +7 -1
  64. data/lib/avm/instances/entry_keys.rb +42 -7
  65. data/lib/avm/instances/runner.rb +40 -0
  66. data/lib/avm/{stereotypes/postgresql.rb → postgresql.rb} +1 -3
  67. data/lib/avm/postgresql/instance.rb +63 -0
  68. data/lib/avm/postgresql/instance/data_unit.rb +39 -0
  69. data/lib/avm/postgresql/instance_with.rb +18 -0
  70. data/lib/avm/projects/stereotypes/git_subtree/publish.rb +2 -0
  71. data/lib/avm/projects/stereotypes/git_subtree/warp.rb +3 -0
  72. data/lib/avm/tools/runner.rb +3 -3
  73. data/lib/avm/tools/runner/eac_rails_base0.rb +5 -18
  74. data/lib/avm/tools/runner/eac_rails_base0/apache_path.rb +1 -1
  75. data/lib/avm/tools/runner/eac_rails_base0/bundle.rb +3 -3
  76. data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +7 -12
  77. data/lib/avm/tools/runner/eac_rails_base0/runner.rb +3 -3
  78. data/lib/avm/tools/runner/eac_redmine_base0.rb +5 -23
  79. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +1 -1
  80. data/lib/avm/tools/runner/eac_redmine_base0/docker.rb +1 -1
  81. data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +3 -3
  82. data/lib/avm/tools/runner/eac_wordpress_base0.rb +5 -24
  83. data/lib/avm/tools/runner/{eac_rails_base0/data.rb → eac_writings_base0.rb} +4 -4
  84. data/lib/avm/tools/runner/git/deploy.rb +1 -1
  85. data/lib/avm/tools/runner/instance.rb +28 -0
  86. data/lib/avm/tools/runner/instance/info.rb +44 -0
  87. data/lib/avm/tools/runner/local_project/eac_writings_base0.rb +35 -0
  88. data/lib/avm/tools/runner/local_project/eac_writings_base0/build_chapters.rb +48 -0
  89. data/lib/avm/tools/runner/local_project/eac_writings_base0/build_single.rb +37 -0
  90. data/lib/avm/tools/runner/local_project/eac_writings_base0/info.rb +36 -0
  91. data/lib/avm/tools/version.rb +1 -1
  92. data/template/avm/eac_rails_base0/deploy/config/envvars.d/email.yml.template +11 -0
  93. data/template/avm/{stereotypes/eac_ubuntu_base0 → eac_ubuntu_base0}/docker_image/Dockerfile +0 -0
  94. data/template/avm/{stereotypes/eac_wordpress_base0 → eac_wordpress_base0}/deploy/wp-config.php.template +0 -0
  95. data/template/avm/eac_writings_base0/commons/all.tex +5 -0
  96. data/template/avm/eac_writings_base0/commons/ebook.tex +11 -0
  97. data/template/avm/eac_writings_base0/commons/images.tex +11 -0
  98. data/template/avm/eac_writings_base0/commons/links.tex +2 -0
  99. data/template/avm/eac_writings_base0/commons/portuguese.tex +8 -0
  100. data/template/avm/eac_writings_base0/commons/source_code.tex +21 -0
  101. data/template/avm/eac_writings_base0/commons/source_code/java.tex +15 -0
  102. data/template/avm/eac_writings_base0/commons/utils.tex +6 -0
  103. data/template/avm/eac_writings_base0/deploy/index.html.template +9 -0
  104. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +12 -0
  105. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  106. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  107. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  108. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  109. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -1
  110. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  111. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  112. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  113. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  114. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  115. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +4 -0
  116. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  117. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  118. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  119. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  120. metadata +72 -35
  121. data/lib/avm/git/commit/deploy/appended.rb +0 -37
  122. data/lib/avm/git/commit/deploy/appended/base.rb +0 -17
  123. data/lib/avm/git/commit/deploy/appended/directory.rb +0 -32
  124. data/lib/avm/git/commit/deploy/appended/file_content.rb +0 -28
  125. data/lib/avm/rails/runners/bundle.rb +0 -35
  126. data/lib/avm/rails/runners/runner.rb +0 -48
  127. data/lib/avm/stereotypes/eac_redmine_base0.rb +0 -11
  128. data/lib/avm/stereotypes/eac_wordpress_base0/apache_host.rb +0 -27
  129. data/lib/avm/stereotypes/eac_wordpress_base0/deploy.rb +0 -12
  130. data/lib/avm/stereotypes/eac_wordpress_base0/instance.rb +0 -26
  131. data/lib/avm/stereotypes/postgresql/instance.rb +0 -65
  132. data/lib/avm/stereotypes/postgresql/instance/data_unit.rb +0 -41
  133. data/lib/avm/stereotypes/postgresql/instance_with.rb +0 -20
  134. data/lib/avm/tools/runner/eac_rails_base0/apache_host.rb +0 -16
  135. data/lib/avm/tools/runner/eac_rails_base0/deploy.rb +0 -15
  136. data/lib/avm/tools/runner/eac_redmine_base0/bundle.rb +0 -14
  137. data/lib/avm/tools/runner/eac_redmine_base0/data.rb +0 -27
  138. data/lib/avm/tools/runner/eac_redmine_base0/data/dump.rb +0 -16
  139. data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +0 -15
  140. data/lib/avm/tools/runner/eac_redmine_base0/runner.rb +0 -14
  141. data/lib/avm/tools/runner/eac_wordpress_base0/apache_host.rb +0 -17
  142. data/lib/avm/tools/runner/eac_wordpress_base0/data.rb +0 -15
  143. data/lib/avm/tools/runner/eac_wordpress_base0/deploy.rb +0 -15
@@ -2,90 +2,37 @@
2
2
 
3
3
  require 'addressable'
4
4
  require 'eac_ruby_utils/core_ext'
5
+ require 'avm/files/appendable'
6
+ require 'avm/files/deploy'
5
7
  require 'avm/patches/object/template'
6
8
 
7
9
  module Avm
8
10
  module Git
9
11
  class Commit
10
12
  class Deploy
11
- require_sub __FILE__, include_modules: true
13
+ include ::Avm::Files::Appendable
12
14
  enable_simple_cache
13
15
 
14
- attr_reader :build_dir, :commit, :target_env, :target_path, :variables_source
16
+ attr_reader :build_dir, :commit, :target_env, :target_path
15
17
 
16
18
  def initialize(commit, target_env, target_path)
17
19
  @commit = commit
18
20
  @target_env = target_env
19
21
  @target_path = target_path
20
- @variables_source = nil
21
- end
22
-
23
- def variables_source_set(source)
24
- @variables_source = source
25
- self
26
22
  end
27
23
 
28
24
  def run
29
- on_build_dir do
30
- copy_git_content
31
- copy_appended_content
32
- mkdir_target
33
- clear_content
34
- send_untar_package
35
- set_target_permission
36
- end
25
+ fd = ::Avm::Files::Deploy.new(target_env, target_path)
26
+ fd.append_tar_output_command(git_archive_command)
27
+ fd.appended.push(*appended)
28
+ fd.run
37
29
  end
38
30
 
39
31
  private
40
32
 
41
- def on_build_dir
42
- @build_dir = ::Dir.mktmpdir
43
- yield
44
- ensure
45
- ::FileUtils.rm_rf(@build_dir)
46
- end
47
-
48
- def copy_git_content
49
- git_archive_command.pipe(untar_git_archive_command).execute!
50
- end
51
-
52
- def mkdir_target
53
- target_env.command('mkdir', '-p', target_path).execute!
54
- end
55
-
56
- def clear_content
57
- target_env.command(
58
- 'find', target_path, '-mindepth', '1', '-maxdepth', '1', '-exec', 'rm', '-rf', '{}', ';'
59
- ).execute!
60
- end
61
-
62
- def send_untar_package
63
- tar_build_command.pipe(untar_build_command).execute!
64
- end
65
-
66
- def set_target_permission
67
- target_env.command('chmod', '755', target_path).execute!
68
- end
69
-
70
33
  def git_archive_command
71
34
  commit.git.command('archive', '--format=tar', commit.sha1)
72
35
  end
73
-
74
- def untar_git_archive_command
75
- source_env.command('tar', '-xf', '-', '-C', build_dir)
76
- end
77
-
78
- def tar_build_command
79
- source_env.command('tar', '-czO', '-C', build_dir, '.')
80
- end
81
-
82
- def untar_build_command
83
- target_env.command('tar', '-xzf', '-', '-C', target_path)
84
- end
85
-
86
- def source_env
87
- ::EacRubyUtils::Envs.local
88
- end
89
36
  end
90
37
  end
91
38
  end
@@ -13,6 +13,10 @@ module Avm
13
13
  @id = id.to_s
14
14
  end
15
15
 
16
+ def to_s
17
+ id
18
+ end
19
+
16
20
  def instance(suffix)
17
21
  ::Avm::Instances::Base.new(self, suffix)
18
22
  end
@@ -3,6 +3,7 @@
3
3
  require 'eac_ruby_utils/require_sub'
4
4
  require 'eac_ruby_utils/simple_cache'
5
5
  require 'avm/instances/entries'
6
+ require 'avm/instances/entry_keys'
6
7
  ::EacRubyUtils.require_sub(__FILE__)
7
8
 
8
9
  module Avm
@@ -62,7 +63,7 @@ module Avm
62
63
  private
63
64
 
64
65
  def source_instance_uncached
65
- ::Avm::Instances::Base.by_id(read_entry(:source_instance_id))
66
+ ::Avm::Instances::Base.by_id(read_entry(::Avm::Instances::EntryKeys::SOURCE_INSTANCE_ID))
66
67
  end
67
68
  end
68
69
  end
@@ -10,7 +10,8 @@ module Avm
10
10
  extend ::ActiveSupport::Concern
11
11
 
12
12
  included do
13
- %w[Access Admin Data Database Filesystem Ruby Source System Web].each do |class_name|
13
+ %w[Access Admin Data Database Filesystem Mailer Ruby Source System Web]
14
+ .each do |class_name|
14
15
  include const_get(class_name)
15
16
  end
16
17
  end
@@ -10,19 +10,20 @@ module Avm
10
10
  end
11
11
 
12
12
  def auto_ssh_hostname
13
- inherited_entry_value(:host_id, 'ssh.hostname')
13
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ssh.hostname')
14
14
  end
15
15
 
16
16
  def auto_ssh_port
17
- inherited_entry_value(:host_id, 'ssh.port') || 22
17
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ssh.port') || 22
18
18
  end
19
19
 
20
20
  def auto_ssh_username
21
- inherited_entry_value(:host_id, 'ssh.username')
21
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ssh.username')
22
22
  end
23
23
 
24
24
  def auto_ssh_url
25
- inherited_entry_value(:host_id, 'ssh.url') || auto_ssh_url_by_parts
25
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ssh.url') ||
26
+ auto_ssh_url_by_parts
26
27
  end
27
28
 
28
29
  def auto_ssh_url_by_parts
@@ -6,11 +6,11 @@ module Avm
6
6
  module AutoValues
7
7
  module Admin
8
8
  def auto_admin_email
9
- inherited_entry_value(:host_id, 'admin.email')
9
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'admin.email')
10
10
  end
11
11
 
12
12
  def auto_admin_name
13
- inherited_entry_value(:host_id, 'admin.name')
13
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'admin.name')
14
14
  end
15
15
  end
16
16
  end
@@ -46,7 +46,7 @@ module Avm
46
46
  def database_auto_common(suffix)
47
47
  database_key = ::Avm::Instances::EntryKeys.const_get("database_#{suffix}".upcase)
48
48
  inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID, database_key) ||
49
- inherited_entry_value(:host_id, database_key)
49
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, database_key)
50
50
  end
51
51
 
52
52
  def database_port_by_system
@@ -8,11 +8,15 @@ module Avm
8
8
  FS_PATH_KEY = :fs_path
9
9
 
10
10
  def auto_fs_path
11
- inherited_entry_value(:host_id, FS_PATH_KEY) { |v| v + '/' + id }
11
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, FS_PATH_KEY) do |v|
12
+ v + '/' + id
13
+ end
12
14
  end
13
15
 
14
16
  def auto_data_fs_path
15
- inherited_entry_value(:host_id, :data_fs_path) { |v| v + '/' + id }
17
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, :data_fs_path) do |v|
18
+ v + '/' + id
19
+ end
16
20
  end
17
21
 
18
22
  def auto_fs_url
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/entry'
4
+ require 'avm/instances/entry_keys'
5
+
6
+ module Avm
7
+ module Instances
8
+ class Base
9
+ module AutoValues
10
+ module Mailer
11
+ ::Avm::Instances::EntryKeys.all.select { |c| c.to_s.start_with?('mailer.') }
12
+ .reject { |c| c == ::Avm::Instances::EntryKeys::MAILER_ID }
13
+ .each do |mailer_key|
14
+ define_method ::Avm::Instances::Entry.auto_value_method_name(mailer_key) do
15
+ mailer_auto_common(mailer_key)
16
+ end
17
+ end
18
+
19
+ def auto_mailer_id
20
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID,
21
+ ::Avm::Instances::EntryKeys::MAILER_ID) ||
22
+ read_entry_optional(::Avm::Instances::EntryKeys::HOST_ID)
23
+ end
24
+
25
+ private
26
+
27
+ def mailer_auto_common(mailer_key)
28
+ inherited_entry_value(::Avm::Instances::EntryKeys::MAILER_ID, mailer_key)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -6,7 +6,7 @@ module Avm
6
6
  module AutoValues
7
7
  module Ruby
8
8
  def auto_ruby_version
9
- inherited_entry_value(:host_id, 'ruby.version')
9
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ruby.version')
10
10
  end
11
11
  end
12
12
  end
@@ -8,12 +8,12 @@ module Avm
8
8
  module AutoValues
9
9
  module System
10
10
  def auto_system_username
11
- inherited_entry_value(:host_id, 'system.username') ||
11
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'system.username') ||
12
12
  read_entry_optional('ssh.username')
13
13
  end
14
14
 
15
15
  def auto_system_groupname
16
- inherited_entry_value(:host_id, 'system.groupname') ||
16
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'system.groupname') ||
17
17
  read_entry_optional('system.username')
18
18
  end
19
19
  end
@@ -5,6 +5,12 @@ require 'eac_ruby_utils/core_ext'
5
5
  module Avm
6
6
  module Instances
7
7
  class Entry
8
+ class << self
9
+ def auto_value_method_name(suffix)
10
+ "auto_#{suffix.to_s.gsub('.', '_')}"
11
+ end
12
+ end
13
+
8
14
  common_constructor :parent, :suffix, :options
9
15
 
10
16
  def auto_value
@@ -12,7 +18,7 @@ module Avm
12
18
  end
13
19
 
14
20
  def auto_value_method
15
- "auto_#{suffix.to_s.gsub('.', '_')}"
21
+ self.class.auto_value_method_name(suffix)
16
22
  end
17
23
 
18
24
  def full_path
@@ -3,17 +3,52 @@
3
3
  module Avm
4
4
  module Instances
5
5
  module EntryKeys
6
- {
7
- database: %w[id hostname name password port system username],
8
- web: %w[authority hostname path port scheme url userinfo]
9
- }.each do |prefix, suffixes|
10
- suffixes.each do |suffix|
11
- key = "#{prefix}.#{suffix}"
6
+ class << self
7
+ def all
8
+ all_keys.to_a
9
+ end
10
+
11
+ def keys_consts_set(prefix, suffixes)
12
+ if suffixes.is_a?(::Hash)
13
+ keys_consts_set_from_hash(prefix, suffixes)
14
+ elsif suffixes.is_a?(::Enumerable)
15
+ keys_consts_set_from_enum(prefix, suffixes)
16
+ else
17
+ raise "Unmapped suffixes class: #{suffixes.class}"
18
+ end
19
+ end
20
+
21
+ def key_const_set(prefix, suffix)
22
+ key = [prefix, suffix].reject(&:blank?).join('.')
12
23
  const_set(key.gsub('.', '_').upcase, key)
24
+ all_keys << key
25
+ end
26
+
27
+ private
28
+
29
+ def all_keys
30
+ @all_keys ||= ::Set.new
31
+ end
32
+
33
+ def keys_consts_set_from_enum(prefix, suffixes)
34
+ suffixes.each { |suffix| key_const_set(prefix, suffix) }
35
+ end
36
+
37
+ def keys_consts_set_from_hash(prefix, suffixes)
38
+ suffixes.each { |k, v| keys_consts_set(prefix.to_s + (k.blank? ? '' : ".#{k}"), v) }
13
39
  end
14
40
  end
15
41
 
16
- FS_PATH = 'fs_path'
42
+ {
43
+ '' => %w[fs_path host_id source_instance_id],
44
+ database: %w[id hostname name password port system username],
45
+ mailer: {
46
+ '' => %w[id from reply_to],
47
+ smtp: %w[address port domain username password authentication starttls_auto]
48
+ },
49
+ ssh: %w[hostname port url username],
50
+ web: %w[authority hostname path port scheme url userinfo]
51
+ }.each { |prefix, suffixes| keys_consts_set(prefix, suffixes) }
17
52
  end
18
53
  end
19
54
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+
6
+ module Avm
7
+ module Instances
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class << self
10
+ def instance_class
11
+ ::Avm.const_get(stereotype_name).const_get('Instance')
12
+ end
13
+
14
+ def stereotype_module
15
+ ::Avm.const_get(stereotype_name)
16
+ end
17
+
18
+ def stereotype_name
19
+ name.demodulize
20
+ end
21
+ end
22
+
23
+ runner_with
24
+ description = "Utilities for #{stereotype_name} instances."
25
+ runner_definition do
26
+ desc description
27
+ pos_arg 'instance-id'
28
+ subcommands
29
+ end
30
+
31
+ delegate :instance_class, :stereotype_module, :stereotype_name, to: :class
32
+
33
+ private
34
+
35
+ def instance_uncached
36
+ self.class.instance_class.by_id(options.fetch('<instance-id>'))
37
+ end
38
+ end
39
+ end
40
+ end
@@ -4,8 +4,6 @@ require 'eac_ruby_utils/require_sub'
4
4
  ::EacRubyUtils.require_sub(__FILE__)
5
5
 
6
6
  module Avm
7
- module Stereotypes
8
- module Postgresql
9
- end
7
+ module Postgresql
10
8
  end
11
9
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/postgresql/instance/data_unit'
4
+
5
+ module Avm
6
+ module Postgresql
7
+ class Instance
8
+ def initialize(env, connection_params)
9
+ @env = env
10
+ @connection_params = connection_params.with_indifferent_access
11
+ end
12
+
13
+ def data_unit
14
+ ::Avm::Postgresql::Instance::DataUnit.new(self)
15
+ end
16
+
17
+ def dump_command
18
+ env.command('pg_dump', '--no-privileges', '--clean', '--no-owner', *common_command_args)
19
+ .envvar('PGPASSWORD', password)
20
+ end
21
+
22
+ def dump_gzip_command
23
+ dump_command.append(['@ESC_|', 'gzip', '-9', '-c'])
24
+ end
25
+
26
+ def psql_command
27
+ env.command("@ESC_PGPASSWORD=#{password}", 'psql', *common_command_args)
28
+ end
29
+
30
+ def psql_command_command(sql)
31
+ psql_command.append(['--quiet', '--tuples-only', '--command', sql])
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :env, :connection_params
37
+
38
+ def common_command_args
39
+ ['--host', host, '--username', user, '--port', port, name]
40
+ end
41
+
42
+ def host
43
+ connection_params[:host] || '127.0.0.1'
44
+ end
45
+
46
+ def port
47
+ connection_params[:port] || '5432'
48
+ end
49
+
50
+ def user
51
+ connection_params.fetch(:user)
52
+ end
53
+
54
+ def password
55
+ connection_params.fetch(:password)
56
+ end
57
+
58
+ def name
59
+ connection_params.fetch(:name)
60
+ end
61
+ end
62
+ end
63
+ end