eac_tools 0.45.1 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +35 -30
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +2 -2
  5. data/sub/avm/lib/avm/data/callbacks.rb +37 -0
  6. data/sub/avm/lib/avm/data/package.rb +15 -7
  7. data/sub/avm/lib/avm/data/unit.rb +2 -23
  8. data/sub/avm/lib/avm/entries/uri_builder.rb +3 -1
  9. data/sub/avm/lib/avm/instances/base/auto_values/data.rb +1 -1
  10. data/sub/avm/lib/avm/instances/data/files_unit.rb +55 -0
  11. data/sub/avm/lib/avm/{data/instance → instances/data}/package.rb +2 -2
  12. data/sub/avm/lib/avm/instances/data/unit.rb +14 -0
  13. data/sub/avm/lib/avm/instances/data.rb +11 -0
  14. data/sub/avm/lib/avm/version.rb +1 -1
  15. data/sub/avm/spec/lib/avm/instances/base_spec.rb +3 -1
  16. data/sub/avm/spec/lib/avm/instances/base_spec_files/config.yml +2 -0
  17. data/sub/avm-eac_postgresql_base0/Gemfile +5 -0
  18. data/sub/avm-eac_postgresql_base0/avm-eac_postgresql_base0.gemspec +19 -0
  19. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/assert.rb +77 -0
  20. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/data_unit.rb +39 -0
  21. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance.rb +74 -0
  22. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance_with.rb +18 -0
  23. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/version.rb +7 -0
  24. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0.rb +9 -0
  25. data/sub/avm-eac_postgresql_base0/spec/rubocop_spec.rb +3 -0
  26. data/sub/avm-eac_postgresql_base0/spec/spec_helper.rb +4 -0
  27. data/sub/avm-eac_rails_base1/avm-eac_rails_base1.gemspec +4 -4
  28. data/sub/avm-eac_rails_base1/lib/avm/eac_rails_base1/version.rb +1 -1
  29. data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +5 -5
  30. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/files.rb +22 -0
  31. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/gitolite.rb +11 -0
  32. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/install.rb +37 -0
  33. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb +3 -9
  34. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/data_package.rb +23 -0
  35. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/deploy.rb +1 -19
  36. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
  37. data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/instances/deploy/config/install.sh.template +2 -2
  38. data/sub/avm-eac_redmine_plugin_base0/avm-eac_redmine_plugin_base0.gemspec +2 -2
  39. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/init.rb +27 -0
  40. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/parent.rb +31 -0
  41. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/rubocop.rb +29 -0
  42. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/version.rb +31 -0
  43. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base.rb +2 -36
  44. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/init_file.rb +43 -0
  45. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/version.rb +1 -1
  46. data/sub/avm-eac_redmine_plugin_base0/spec/lib/avm/eac_redmine_plugin_base0/sources/init_file_spec.rb +14 -0
  47. data/sub/avm-eac_redmine_plugin_base0/spec/lib/avm/eac_redmine_plugin_base0/sources/init_file_spec_files/a_init_file.rb +12 -0
  48. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +3 -3
  49. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/base.rb +4 -4
  50. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  51. metadata +41 -15
  52. data/sub/avm/lib/avm/data/instance/files_unit.rb +0 -41
  53. data/sub/avm/lib/avm/data/instance/unit.rb +0 -17
  54. data/sub/avm/lib/avm/data/instance.rb +0 -11
  55. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/data_unit.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c529e1c368fe44c68e5bbaafd5258fab08baefca7852a4c5bd2285825352374e
4
- data.tar.gz: 464f786052703260b2d4b7364fd3edbeae7403020036108f1faeb6a49df0e426
3
+ metadata.gz: 42d2af3ec5802d3d4deaef86b0e225332d92bb079767121a8601d0d7a9765418
4
+ data.tar.gz: 062b466f4a749f6094769ede0583d1bd574f73ae05ffa30e0aeaa8a167e6ea2b
5
5
  SHA512:
6
- metadata.gz: 14972773fe50b2bcb87738798c0608d78557a3c60d1c57bfb36d4590fe024b91a121b360b7f8cd8cbe058d827c90886a62b133127a4d744e2609924fb92ce792
7
- data.tar.gz: 98e35772f9f6152c3e7f69b7667bf195e3280fd4ffb7ba1bf25be23968473b3403ecbdbbc37c11c05483cba11e9b43fc8be8099159117b324fdbc83ee5ab114f
6
+ metadata.gz: ae897ed254a4902dd543c1644015ee6f4ed269bd401949594cd8c5bfc764d9abce299cdbe4a9c6a04de72ec8f0870c93e617d36b39e7c83b202058970dd5f94b
7
+ data.tar.gz: 349afc035604be730dec4bc4a1ebf9ef670dc15c27364f2abe4a752d853c8a2f4a689493f087f86598434d886900d0d81cb26409970dba895f8e7028c92d7869
data/Gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eac_tools (0.45.1)
5
- avm (~> 0.56)
4
+ eac_tools (0.46.0)
5
+ avm (~> 0.57)
6
6
  avm-eac_asciidoctor_base0 (~> 0.12)
7
7
  avm-eac_generic_base0 (~> 0.8)
8
8
  avm-eac_latex_base0 (~> 0.3)
9
9
  avm-eac_php_base0 (~> 0.3)
10
10
  avm-eac_rails_base0 (~> 0.8, >= 0.8.1)
11
- avm-eac_rails_base1 (~> 0.7)
12
- avm-eac_redmine_base0 (~> 0.16)
13
- avm-eac_redmine_plugin_base0 (~> 0.3)
11
+ avm-eac_rails_base1 (~> 0.7, >= 0.7.1)
12
+ avm-eac_redmine_base0 (~> 0.17)
13
+ avm-eac_redmine_plugin_base0 (~> 0.4)
14
14
  avm-eac_ruby_base1 (~> 0.27, >= 0.27.1)
15
- avm-eac_webapp_base0 (~> 0.12, >= 0.12.2)
15
+ avm-eac_webapp_base0 (~> 0.12, >= 0.12.3)
16
16
  avm-eac_wordpress_base0 (~> 0.2, >= 0.2.1)
17
17
  avm-tools (~> 0.142, >= 0.142.6)
18
18
  eac_ruby_utils (~> 0.107, >= 0.107.1)
@@ -62,6 +62,13 @@ PATH
62
62
  avm-eac_generic_base0 (~> 0.7)
63
63
  eac_ruby_utils (~> 0.106)
64
64
 
65
+ PATH
66
+ remote: sub/avm-eac_postgresql_base0
67
+ specs:
68
+ avm-eac_postgresql_base0 (0.2.1)
69
+ avm (~> 0.56, >= 0.56.1)
70
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
71
+
65
72
  PATH
66
73
  remote: sub/avm-eac_python_base0
67
74
  specs:
@@ -79,31 +86,31 @@ PATH
79
86
  PATH
80
87
  remote: sub/avm-eac_rails_base1
81
88
  specs:
82
- avm-eac_rails_base1 (0.7.0)
83
- avm (~> 0.45)
84
- avm-eac_ruby_base1 (~> 0.21)
85
- avm-eac_webapp_base0 (~> 0.9)
86
- eac_ruby_utils (~> 0.104)
89
+ avm-eac_rails_base1 (0.7.1)
90
+ avm (~> 0.57)
91
+ avm-eac_ruby_base1 (~> 0.27, >= 0.27.1)
92
+ avm-eac_webapp_base0 (~> 0.12, >= 0.12.3)
93
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
87
94
 
88
95
  PATH
89
96
  remote: sub/avm-eac_redmine_base0
90
97
  specs:
91
- avm-eac_redmine_base0 (0.16.0)
92
- avm (~> 0.44)
93
- avm-eac_generic_base0 (~> 0.5)
94
- avm-eac_rails_base1 (~> 0.6)
98
+ avm-eac_redmine_base0 (0.17.0)
99
+ avm (~> 0.57)
100
+ avm-eac_generic_base0 (~> 0.8)
101
+ avm-eac_rails_base1 (~> 0.7, >= 0.7.1)
95
102
  avm-eac_ubuntu_base0 (~> 0.3)
96
103
  curb (~> 0.9, >= 0.9.11)
97
- eac_fs (~> 0.12, >= 0.12.3)
104
+ eac_fs (~> 0.15)
98
105
  eac_rest (~> 0.6, >= 0.6.1)
99
- eac_ruby_utils (~> 0.104)
106
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
100
107
 
101
108
  PATH
102
109
  remote: sub/avm-eac_redmine_plugin_base0
103
110
  specs:
104
- avm-eac_redmine_plugin_base0 (0.3.0)
105
- avm-eac_ruby_base1 (~> 0.11)
106
- eac_ruby_utils (~> 0.95, >= 0.95.1)
111
+ avm-eac_redmine_plugin_base0 (0.4.0)
112
+ avm-eac_ruby_base1 (~> 0.27, >= 0.27.1)
113
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
107
114
 
108
115
  PATH
109
116
  remote: sub/avm-eac_ruby_base1
@@ -116,13 +123,13 @@ PATH
116
123
  PATH
117
124
  remote: sub/avm-eac_webapp_base0
118
125
  specs:
119
- avm-eac_webapp_base0 (0.12.2)
120
- avm (~> 0.54)
126
+ avm-eac_webapp_base0 (0.12.3)
127
+ avm (~> 0.57)
121
128
  avm-eac_generic_base0 (~> 0.8)
122
- avm-eac_postgresql_base0 (~> 0.2)
129
+ avm-eac_postgresql_base0 (~> 0.2, >= 0.2.1)
123
130
  avm-eac_ubuntu_base0 (~> 0.3)
124
131
  avm-files (~> 0.6)
125
- eac_ruby_utils (~> 0.106, >= 0.106.1)
132
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
126
133
 
127
134
  PATH
128
135
  remote: sub/avm-eac_wordpress_base0
@@ -173,13 +180,13 @@ PATH
173
180
  PATH
174
181
  remote: sub/avm
175
182
  specs:
176
- avm (0.56.0)
183
+ avm (0.57.0)
177
184
  aranha-parsers (~> 0.14, >= 0.14.4)
178
- eac_cli (~> 0.29)
185
+ eac_cli (~> 0.30)
179
186
  eac_config (~> 0.12)
180
187
  eac_docker (~> 0.5)
181
188
  eac_fs (~> 0.15)
182
- eac_git (~> 0.13)
189
+ eac_git (~> 0.14)
183
190
  eac_ruby_utils (~> 0.107, >= 0.107.1)
184
191
  eac_templates (~> 0.3, >= 0.3.2)
185
192
  filesize (~> 0.2)
@@ -255,9 +262,6 @@ GEM
255
262
  public_suffix (>= 2.0.2, < 6.0)
256
263
  asciidoctor (2.0.18)
257
264
  ast (2.4.2)
258
- avm-eac_postgresql_base0 (0.2.0)
259
- avm (~> 0.12, >= 0.12.1)
260
- eac_ruby_utils (~> 0.82)
261
265
  avm-eac_ubuntu_base0 (0.3.0)
262
266
  avm (~> 0.7)
263
267
  eac_ruby_utils (~> 0.77, >= 0.77.1)
@@ -383,6 +387,7 @@ DEPENDENCIES
383
387
  avm-eac_generic_base0!
384
388
  avm-eac_latex_base0!
385
389
  avm-eac_php_base0!
390
+ avm-eac_postgresql_base0!
386
391
  avm-eac_python_base0!
387
392
  avm-eac_rails_base0!
388
393
  avm-eac_rails_base1!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacTools
4
- VERSION = '0.45.1'
4
+ VERSION = '0.46.0'
5
5
  end
data/sub/avm/avm.gemspec CHANGED
@@ -13,11 +13,11 @@ Gem::Specification.new do |s|
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
15
  s.add_dependency 'aranha-parsers', '~> 0.14', '>= 0.14.4'
16
- s.add_dependency 'eac_cli', '~> 0.29'
16
+ s.add_dependency 'eac_cli', '~> 0.30'
17
17
  s.add_dependency 'eac_config', '~> 0.12'
18
18
  s.add_dependency 'eac_docker', '~> 0.5'
19
19
  s.add_dependency 'eac_fs', '~> 0.15'
20
- s.add_dependency 'eac_git', '~> 0.13'
20
+ s.add_dependency 'eac_git', '~> 0.14'
21
21
  s.add_dependency 'eac_ruby_utils', '~> 0.107', '>= 0.107.1'
22
22
  s.add_dependency 'eac_templates', '~> 0.3', '>= 0.3.2'
23
23
  s.add_dependency 'filesize', '~> 0.2'
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/callbacks'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Data
8
+ module Callbacks
9
+ common_concern do
10
+ include ::ActiveSupport::Callbacks
11
+
12
+ %i[dump load].each do |action|
13
+ define_callbacks action
14
+
15
+ %i[before after].each do |callback|
16
+ method_name = "#{callback}_#{action}"
17
+ singleton_class.class_eval do
18
+ define_method method_name do |callback_method = nil, &block|
19
+ if callback_method
20
+ set_callback action, callback, callback_method
21
+ else
22
+ set_callback action, callback, &block
23
+ end
24
+ self
25
+ end
26
+ end
27
+
28
+ define_method method_name do |callback_method = nil, &block|
29
+ singleton_class.send(method_name, callback_method, &block)
30
+ self
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/data/package/dump'
4
- require 'avm/data/package/load'
3
+ require 'avm/data/callbacks'
4
+ require 'eac_ruby_utils/core_ext'
5
5
 
6
6
  module Avm
7
7
  module Data
8
8
  class Package
9
- attr_reader :units
9
+ require_sub __FILE__
10
+ include ::Avm::Data::Callbacks
10
11
 
11
12
  def initialize(options)
12
- @units = {}
13
13
  options = options.to_options_consumer
14
14
  units = options.consume(:units)
15
15
  options.validate
@@ -19,7 +19,7 @@ module Avm
19
19
  end
20
20
 
21
21
  def add_unit(identifier, unit)
22
- @units[identifier.to_sym] = unit
22
+ units[identifier.to_sym] = unit
23
23
  end
24
24
 
25
25
  def dump(data_path, options = {})
@@ -31,11 +31,19 @@ module Avm
31
31
  end
32
32
 
33
33
  def dump_units_to_directory(directory)
34
- @units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
34
+ run_callbacks :dump do
35
+ units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
36
+ end
35
37
  end
36
38
 
37
39
  def load_units_from_directory(directory)
38
- @units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
40
+ run_callbacks :load do
41
+ units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
42
+ end
43
+ end
44
+
45
+ def units
46
+ @units ||= {}
39
47
  end
40
48
  end
41
49
  end
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/data/callbacks'
3
4
  require 'eac_ruby_utils/core_ext'
4
- require 'active_support/callbacks'
5
5
 
6
6
  module Avm
7
7
  module Data
8
8
  class Unit
9
- include ::ActiveSupport::Callbacks
9
+ include ::Avm::Data::Callbacks
10
10
 
11
- define_callbacks :dump, :load
12
11
  enable_speaker
13
12
 
14
13
  %w[dump load].each do |action|
@@ -20,26 +19,6 @@ module Avm
20
19
  fail "\\"#{method_name}\\" is a abstract method. Override in #{singleton_class}."
21
20
  end
22
21
  CODE
23
-
24
- # Callbacks
25
- %w[before after].each do |callback|
26
- method = "#{callback}_#{action}"
27
- class_eval <<~CODE, __FILE__, __LINE__ + 1
28
- def self.#{method}(callback_method = nil, &block)
29
- if callback_method
30
- set_callback :#{action}, :#{callback}, callback_method
31
- else
32
- set_callback :#{action}, :#{callback}, &block
33
- end
34
- self
35
- end
36
-
37
- def #{method}(callback_method = nil, &block)
38
- singleton_class.#{method}(callback_method, &block)
39
- self
40
- end
41
- CODE
42
- end
43
22
  end
44
23
 
45
24
  def extension
@@ -46,8 +46,10 @@ module Avm
46
46
  field_get(translate_field(avm_field))
47
47
  end
48
48
 
49
+ # @return [String, nil]
49
50
  def field_get(name)
50
- data[name.to_sym].if_present(&:to_s)
51
+ v = data[name.to_sym]
52
+ v.nil? ? nil : v.to_s
51
53
  end
52
54
 
53
55
  def field_set(field, value)
@@ -15,7 +15,7 @@ module Avm
15
15
  .if_present do |v|
16
16
  ::File.join(
17
17
  v,
18
- "#{id}#{::Avm::Data::Instance::Package::Dump::DEFAULT_FILE_EXTENSION}"
18
+ "#{id}#{::Avm::Instances::Data::Package::Dump::DEFAULT_FILE_EXTENSION}"
19
19
  )
20
20
  end
21
21
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/data/unit'
4
+
5
+ module Avm
6
+ module Instances
7
+ module Data
8
+ class FilesUnit < ::Avm::Instances::Data::Unit
9
+ EXTENSION = '.tar.gz'
10
+
11
+ enable_listable
12
+ lists.add_symbol :option, :sudo_user
13
+
14
+ common_constructor :instance, :fs_path_subpath, :options, default: [{}],
15
+ super_args: -> { [instance] } do
16
+ self.fs_path_subpath = fs_path_subpath.to_pathname
17
+ self.options = self.class.lists.option.hash_keys_validate!(options)
18
+ end
19
+
20
+ before_load :clear_files
21
+
22
+ # @return [Pathname]
23
+ def files_path
24
+ fs_path_subpath
25
+ .expand_path(instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH))
26
+ end
27
+
28
+ def dump_command
29
+ instance_command('tar', '-czf', '-', '-C', files_path, '.')
30
+ end
31
+
32
+ def load_command
33
+ instance_command('tar', '-xzf', '-', '-C', files_path)
34
+ end
35
+
36
+ def clear_files
37
+ infom "Removing all files under #{files_path}..."
38
+ instance_command('mkdir', '-p', files_path).execute!
39
+ instance_command('find', files_path, '-mindepth', 1, '-delete').execute!
40
+ end
41
+
42
+ # @return [EacRubyUtils::Envs::Command]
43
+ def instance_command(*args)
44
+ args = ['sudo', '-Hu', sudo_user] + args if sudo_user.present?
45
+ instance.host_env.command(*args)
46
+ end
47
+
48
+ # @return [String, nil]
49
+ def sudo_user
50
+ options[OPTION_SUDO_USER]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -3,8 +3,8 @@
3
3
  require 'avm/data/package'
4
4
 
5
5
  module Avm
6
- module Data
7
- module Instance
6
+ module Instances
7
+ module Data
8
8
  class Package < ::Avm::Data::Package
9
9
  attr_reader :instance
10
10
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/unit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Instances
8
+ module Data
9
+ class Unit < ::Avm::Data::Unit
10
+ common_constructor :instance
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Instances
7
+ module Data
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.56.0'
4
+ VERSION = '0.57.0'
5
5
  end
@@ -22,7 +22,9 @@ RSpec.describe ::Avm::Instances::Base do
22
22
  ::Avm::Instances::EntryKeys::INSTALL_HOSTNAME => 'myhost.com',
23
23
  ::Avm::Instances::EntryKeys::INSTALL_USERNAME => 'myuser',
24
24
  ::Avm::Instances::EntryKeys::INSTALL_GROUPNAME => 'myuser',
25
- ::Avm::Instances::EntryKeys::INSTALL_URL => 'ssh://otheruser@otherhost.com'
25
+ ::Avm::Instances::EntryKeys::INSTALL_URL => 'ssh://otheruser@otherhost.com',
26
+ ::Avm::Instances::EntryKeys::WEB_URL => 'https://app0.net',
27
+ ::Avm::Instances::EntryKeys::WEB_PATH => ''
26
28
  },
27
29
  'app_2' => {
28
30
  ::Avm::Instances::EntryKeys::DATABASE_HOSTNAME => '127.0.0.1',
@@ -2,6 +2,8 @@
2
2
  app_0:
3
3
  install:
4
4
  id: app_1
5
+ web:
6
+ url: https://app0.net
5
7
  app_1:
6
8
  install:
7
9
  id: app_2
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'avm/eac_postgresql_base0/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'avm-eac_postgresql_base0'
9
+ s.version = Avm::EacPostgresqlBase0::VERSION
10
+ s.authors = ['Put here the authors']
11
+ s.summary = 'Put here de description.'
12
+
13
+ s.files = Dir['{lib}/**/*']
14
+
15
+ s.add_dependency 'avm', '~> 0.56', '>= 0.56.1'
16
+ s.add_dependency 'eac_ruby_utils', '~> 0.107', '>= 0.107.1'
17
+
18
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.4'
19
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacPostgresqlBase0
7
+ class Instance
8
+ class Assert
9
+ common_constructor :instance
10
+ delegate :name, :password, :user, to: :instance
11
+
12
+ def perform
13
+ create_user unless user_exist?
14
+ change_password unless password_ok?
15
+ create_database unless database_exist?
16
+ change_owner unless user_owner?
17
+ end
18
+
19
+ def change_owner
20
+ root_execute("ALTER DaTABASE \"#{name}\" OWNER TO \"#{user}\"")
21
+ end
22
+
23
+ def change_password
24
+ root_execute("ALTER USER \"#{user}\" WITH PASSWORD '#{password}'")
25
+ end
26
+
27
+ def create_user
28
+ root_execute("CREATE USER \"#{user}\" WITH PASSWORD '#{password}'")
29
+ end
30
+
31
+ def current_owner
32
+ root_query(<<~SQL
33
+ SELECT pg_catalog.pg_get_userbyid(datdba)
34
+ FROM pg_catalog.pg_database
35
+ WHERE datname = '#{name}'
36
+ SQL
37
+ )
38
+ end
39
+
40
+ def database_exist?
41
+ root_boolean_query("FROM pg_database WHERE datname='#{name}'")
42
+ end
43
+
44
+ def password_ok?
45
+ instance.psql_command_command('SELECT 1', false)
46
+ .execute!(exit_outputs: { 512 => 'login_failed' }).strip == '1'
47
+ end
48
+
49
+ def user_exist?
50
+ root_boolean_query("FROM pg_roles WHERE rolname='#{user}'")
51
+ end
52
+
53
+ def user_owner?
54
+ user == current_owner
55
+ end
56
+
57
+ def create_database
58
+ root_execute("CREATE DATABASE \"#{name}\" WITH OWNER \"#{user}\"")
59
+ end
60
+
61
+ private
62
+
63
+ def root_boolean_query(sql_after_projection)
64
+ root_query("SELECT 1 #{sql_after_projection}") == '1'
65
+ end
66
+
67
+ def root_execute(sql)
68
+ instance.root_psql_command(sql).execute!
69
+ end
70
+
71
+ def root_query(sql)
72
+ root_execute(sql).strip
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/data/unit'
4
+
5
+ module Avm
6
+ module EacPostgresqlBase0
7
+ class Instance
8
+ class DataUnit < ::Avm::Instances::Data::Unit
9
+ EXTENSION = '.pgdump.gz'
10
+
11
+ before_load :clear_database
12
+
13
+ def dump_command
14
+ instance.dump_gzip_command
15
+ end
16
+
17
+ def load_command
18
+ instance.psql_command.prepend(['gzip', '-d', '@ESC_|'])
19
+ end
20
+
21
+ private
22
+
23
+ def clear_database
24
+ info 'Clearing database (Dropping all tables)...'
25
+ run_sql(drop_all_tables_sql).if_present { |v| run_sql(v) }
26
+ end
27
+
28
+ def drop_all_tables_sql
29
+ "select 'drop table \"' || tablename || '\" cascade;' from pg_tables " \
30
+ "where schemaname = 'public';"
31
+ end
32
+
33
+ def run_sql(sql)
34
+ instance.psql_command_command(sql).execute!
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_postgresql_base0/instance/data_unit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module EacPostgresqlBase0
8
+ class Instance
9
+ require_sub __FILE__
10
+
11
+ MAINTENANCE_DATABASE = 'postgres'
12
+
13
+ common_constructor :env, :connection_params do
14
+ self.connection_params = connection_params.with_indifferent_access
15
+ end
16
+
17
+ def assert
18
+ ::Avm::EacPostgresqlBase0::Instance::Assert.new(self).perform
19
+ end
20
+
21
+ def data_unit
22
+ ::Avm::EacPostgresqlBase0::Instance::DataUnit.new(self)
23
+ end
24
+
25
+ def dump_command
26
+ env.command('pg_dump', '--no-privileges', '--clean', '--no-owner', *common_command_args)
27
+ .envvar('PGPASSWORD', password)
28
+ end
29
+
30
+ def dump_gzip_command
31
+ dump_command.append(['@ESC_|', 'gzip', '-9', '-c'])
32
+ end
33
+
34
+ def psql_command(database = true)
35
+ env.command("@ESC_PGPASSWORD=#{password}", 'psql', *common_command_args(database))
36
+ end
37
+
38
+ def psql_command_command(sql, database = true)
39
+ psql_command(database).append(['--quiet', '--tuples-only', '--command', sql])
40
+ end
41
+
42
+ def root_psql_command(sql = nil)
43
+ args = ['sudo', '-u', 'postgres', 'psql']
44
+ args += ['--quiet', '--tuples-only', '--command', sql] if sql.present?
45
+ env.command(*args)
46
+ end
47
+
48
+ def common_command_args(database = true)
49
+ ['--host', host, '--username', user, '--port', port,
50
+ (database ? name : MAINTENANCE_DATABASE)]
51
+ end
52
+
53
+ def host
54
+ connection_params[:host] || '127.0.0.1'
55
+ end
56
+
57
+ def port
58
+ connection_params[:port] || '5432'
59
+ end
60
+
61
+ def user
62
+ connection_params.fetch(:user)
63
+ end
64
+
65
+ def password
66
+ connection_params.fetch(:password)
67
+ end
68
+
69
+ def name
70
+ connection_params.fetch(:name)
71
+ end
72
+ end
73
+ end
74
+ end