avm 0.4.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/data/instance/files_unit.rb +40 -0
  3. data/lib/avm/data/instance/package.rb +18 -0
  4. data/lib/avm/data/instance/unit.rb +17 -0
  5. data/lib/avm/{git/issue.rb → data/instance.rb} +2 -2
  6. data/lib/avm/data/package/dump.rb +119 -0
  7. data/lib/avm/data/package/load.rb +48 -0
  8. data/lib/avm/data/package.rb +42 -0
  9. data/lib/avm/{files → data}/rotate.rb +1 -1
  10. data/lib/avm/data/unit.rb +94 -0
  11. data/lib/avm/docker/runner.rb +8 -0
  12. data/lib/avm/instances/application.rb +25 -0
  13. data/lib/avm/instances/base/auto_values/access.rb +40 -0
  14. data/lib/avm/instances/base/auto_values/admin.rb +19 -0
  15. data/lib/avm/instances/base/auto_values/data.rb +26 -0
  16. data/lib/avm/instances/base/auto_values/database.rb +71 -0
  17. data/lib/avm/instances/base/auto_values/filesystem.rb +45 -0
  18. data/lib/avm/instances/base/auto_values/mailer.rb +34 -0
  19. data/lib/avm/instances/base/auto_values/ruby.rb +15 -0
  20. data/lib/avm/instances/base/auto_values/source.rb +15 -0
  21. data/lib/avm/instances/base/auto_values/system.rb +23 -0
  22. data/lib/avm/instances/base/auto_values/web.rb +46 -0
  23. data/lib/avm/instances/base/auto_values.rb +21 -0
  24. data/lib/avm/instances/base/dockerizable.rb +45 -0
  25. data/lib/avm/instances/base/entry_keys.rb +22 -0
  26. data/lib/avm/instances/base.rb +64 -0
  27. data/lib/avm/instances/entries.rb +43 -0
  28. data/lib/avm/instances/entry.rb +54 -0
  29. data/lib/avm/instances/entry_keys.rb +57 -0
  30. data/lib/avm/instances/runner.rb +38 -0
  31. data/lib/avm/instances.rb +8 -0
  32. data/lib/avm/jobs/base.rb +1 -0
  33. data/lib/avm/path_string.rb +27 -0
  34. data/lib/avm/registry/base.rb +65 -0
  35. data/lib/avm/registry.rb +29 -0
  36. data/lib/avm/rspec/setup.rb +22 -0
  37. data/lib/avm/rspec/shared_examples/in_avm_registry.rb +11 -0
  38. data/lib/avm/rspec/shared_examples/not_in_avm_registry.rb +14 -0
  39. data/lib/avm/{app_src.rb → rspec.rb} +1 -1
  40. data/lib/avm/runners/base.rb +31 -0
  41. data/lib/avm/scms/base.rb +28 -0
  42. data/lib/avm/scms/commit.rb +43 -0
  43. data/lib/avm/self/docker_image.rb +14 -0
  44. data/lib/avm/self/instance/entry_keys.rb +12 -0
  45. data/lib/avm/self/instance.rb +24 -0
  46. data/lib/avm/source_stereotypes/base.rb +21 -0
  47. data/lib/avm/{app_src → sources}/base.rb +25 -3
  48. data/lib/avm/{app_src → sources}/configuration/_locale.rb +1 -1
  49. data/lib/avm/{app_src → sources}/configuration/_rubocop.rb +1 -1
  50. data/lib/avm/{app_src → sources}/configuration/_tests.rb +1 -1
  51. data/lib/avm/{app_src → sources}/configuration.rb +1 -1
  52. data/lib/avm/{git/organize.rb → sources.rb} +2 -4
  53. data/lib/avm/sync.rb +94 -0
  54. data/lib/avm/version.rb +1 -1
  55. metadata +74 -73
  56. data/lib/avm/files/appendable/file_content.rb +0 -24
  57. data/lib/avm/files/appendable/plain_directory.rb +0 -25
  58. data/lib/avm/files/appendable/resource_base.rb +0 -13
  59. data/lib/avm/files/appendable/tar_output_command.rb +0 -26
  60. data/lib/avm/files/appendable/templatized_directory.rb +0 -29
  61. data/lib/avm/files/appendable.rb +0 -55
  62. data/lib/avm/files/appender.rb +0 -11
  63. data/lib/avm/files/deploy.rb +0 -71
  64. data/lib/avm/files/formatter/formats/base.rb +0 -62
  65. data/lib/avm/files/formatter/formats/generic_plain.rb +0 -34
  66. data/lib/avm/files/formatter/formats/html.rb +0 -45
  67. data/lib/avm/files/formatter/formats/javascript.rb +0 -24
  68. data/lib/avm/files/formatter/formats/json.rb +0 -27
  69. data/lib/avm/files/formatter/formats/php.rb +0 -22
  70. data/lib/avm/files/formatter/formats/python.rb +0 -22
  71. data/lib/avm/files/formatter/formats/ruby.rb +0 -22
  72. data/lib/avm/files/formatter/formats/xml.rb +0 -28
  73. data/lib/avm/files/formatter/formats.rb +0 -13
  74. data/lib/avm/files/formatter/utf8_assert.rb +0 -74
  75. data/lib/avm/files/formatter.rb +0 -90
  76. data/lib/avm/files.rb +0 -9
  77. data/lib/avm/git/auto_commit/commit_info.rb +0 -23
  78. data/lib/avm/git/auto_commit/rules/base.rb +0 -39
  79. data/lib/avm/git/auto_commit/rules/last.rb +0 -19
  80. data/lib/avm/git/auto_commit/rules/manual.rb +0 -45
  81. data/lib/avm/git/auto_commit/rules/new.rb +0 -24
  82. data/lib/avm/git/auto_commit/rules/nth.rb +0 -31
  83. data/lib/avm/git/auto_commit/rules/unique.rb +0 -21
  84. data/lib/avm/git/auto_commit/rules.rb +0 -31
  85. data/lib/avm/git/auto_commit_path/ruby.rb +0 -20
  86. data/lib/avm/git/auto_commit_path.rb +0 -28
  87. data/lib/avm/git/commit/class_methods.rb +0 -31
  88. data/lib/avm/git/commit/deploy.rb +0 -38
  89. data/lib/avm/git/commit/deploy_methods.rb +0 -19
  90. data/lib/avm/git/commit/diff_tree_line.rb +0 -32
  91. data/lib/avm/git/commit/file.rb +0 -46
  92. data/lib/avm/git/commit.rb +0 -59
  93. data/lib/avm/git/file_auto_fixup.rb +0 -83
  94. data/lib/avm/git/issue/complete/commits.rb +0 -42
  95. data/lib/avm/git/issue/complete/git_subrepos.rb +0 -23
  96. data/lib/avm/git/issue/complete/local_branch.rb +0 -54
  97. data/lib/avm/git/issue/complete/local_tag.rb +0 -39
  98. data/lib/avm/git/issue/complete/push.rb +0 -54
  99. data/lib/avm/git/issue/complete/remote.rb +0 -33
  100. data/lib/avm/git/issue/complete/test.rb +0 -45
  101. data/lib/avm/git/issue/complete/tracker.rb +0 -28
  102. data/lib/avm/git/issue/complete/validation.rb +0 -31
  103. data/lib/avm/git/issue/complete/validations.rb +0 -53
  104. data/lib/avm/git/issue/complete/working_tree.rb +0 -19
  105. data/lib/avm/git/issue/complete.rb +0 -51
  106. data/lib/avm/git/issue/deliver.rb +0 -56
  107. data/lib/avm/git/organize/reference_update.rb +0 -34
  108. data/lib/avm/git/organize/repository.rb +0 -76
  109. data/lib/avm/git/revision_test.rb +0 -105
  110. data/lib/avm/git/subrepo_check/parent.rb +0 -51
  111. data/lib/avm/git/subrepo_check/remote.rb +0 -89
  112. data/lib/avm/git/subrepo_check/show_result.rb +0 -32
  113. data/lib/avm/git/subrepo_check.rb +0 -38
  114. data/lib/avm/git/subrepo_checks.rb +0 -59
  115. data/lib/avm/git.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a5a8832847c76afcae4e76ef3e8f7d1391d7cfb0b13788c3dc7273f9ef879f1
4
- data.tar.gz: 0b89bd147edb92e0e3e4d158d16f0995ef41f0544a680beb053f9fa55b96a282
3
+ metadata.gz: 3be29c02f4be9deec23c40452cf17ad0ce0478c6ae32508690d0a54bc9c4987a
4
+ data.tar.gz: e63f5d086715190a1803f4289a48f9e25e56094d570d62f6ed5c22b0ceeb6084
5
5
  SHA512:
6
- metadata.gz: a70af189af9aee66a693706ba031e5eb7c6d4c8533144099f325dfe2b88b9ef08daae16de8d2f09857f194816d653d3669527d6bc9c07d173566c9ab9121c3f6
7
- data.tar.gz: d66a1741ec6295f54166a2007a4d168eddd4e7de30f538f87329067b580faf2572514d99302bb467e0b408dfe1a44dd54a9e4e2abaaed0292b3a7ba69bb02b95
6
+ metadata.gz: 372b53edca7fe1187fa0faa39e145437779a3608b7ce7d248b2d5fe753520079c0542dda99a80b4936f09438f6bda1fceebdb78ce1b741e14854f10160468085
7
+ data.tar.gz: 02bd6cdb0cdb4f02e7a202d69de40ca2c5f1c981af6198e8ce1e93b36380b0d39a436d36a358e58856675df9e040080ad6879367e013228cd6bfa3efb3e66735
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/instance/unit'
4
+
5
+ module Avm
6
+ module Data
7
+ module Instance
8
+ class FilesUnit < ::Avm::Data::Instance::Unit
9
+ EXTENSION = '.tar.gz'
10
+
11
+ attr_reader :fs_path_subpath
12
+
13
+ def initialize(instance, fs_path_subpath)
14
+ super(instance)
15
+ @fs_path_subpath = fs_path_subpath
16
+ end
17
+
18
+ before_load :clear_files
19
+
20
+ def files_path
21
+ ::File.join(instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH), fs_path_subpath)
22
+ end
23
+
24
+ def dump_command
25
+ instance.host_env.command('tar', '-czf', '-', '-C', files_path, '.')
26
+ end
27
+
28
+ def load_command
29
+ instance.host_env.command('tar', '-xzf', '-', '-C', files_path)
30
+ end
31
+
32
+ def clear_files
33
+ infom "Removing all files under #{files_path}..."
34
+ instance.host_env.command('mkdir', '-p', files_path).execute!
35
+ instance.host_env.command('find', files_path, '-mindepth', 1, '-delete').execute!
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/package'
4
+
5
+ module Avm
6
+ module Data
7
+ module Instance
8
+ class Package < ::Avm::Data::Package
9
+ attr_reader :instance
10
+
11
+ def initialize(instance, options = {})
12
+ @instance = instance
13
+ super options
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/unit'
4
+
5
+ module Avm
6
+ module Data
7
+ module Instance
8
+ class Unit < ::Avm::Data::Unit
9
+ attr_reader :instance
10
+
11
+ def initialize(instance)
12
+ @instance = instance
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -4,8 +4,8 @@ require 'eac_ruby_utils/require_sub'
4
4
  ::EacRubyUtils.require_sub(__FILE__)
5
5
 
6
6
  module Avm
7
- module Git
8
- module Issue
7
+ module Data
8
+ module Instance
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/rotate'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'minitar'
6
+
7
+ module Avm
8
+ module Data
9
+ class Package
10
+ class Dump
11
+ enable_speaker
12
+ enable_listable
13
+
14
+ DEFAULT_EXPIRE_TIME = 1.day
15
+ DEFAULT_FILE_EXTENSION = '.tar'
16
+
17
+ attr_reader :package, :data_file_path, :existing
18
+
19
+ lists.add_string :existing, :denied, :overwrite, :rotate, :rotate_expired
20
+
21
+ def initialize(package, data_file_path, options = {})
22
+ @package = package
23
+ @data_file_path = data_file_path
24
+ options = options.to_options_consumer
25
+ @existing, @expire_time = options.consume(:existing, :expire_time)
26
+ options.validate
27
+ self.class.lists.existing.value_validate!(@existing)
28
+ end
29
+
30
+ def runnable?
31
+ cannot_run_reason.blank?
32
+ end
33
+
34
+ def cannot_run_reason
35
+ return nil if !data_file_exist? ||
36
+ [EXISTING_OVERWRITE, EXISTING_ROTATE].include?(existing)
37
+
38
+ if existing == EXISTING_DENIED
39
+ 'Data exist and overwriting is denied'
40
+ elsif existing == EXISTING_ROTATE_EXPIRED && !data_file_expired?
41
+ 'Data exist and yet is not expired'
42
+ end
43
+ end
44
+
45
+ def run
46
+ raise "Cannot run: #{cannot_run_reason}" unless runnable?
47
+
48
+ build_dir = dump_units_to_build_directory
49
+ package_file = create_package_file(build_dir)
50
+ rotate
51
+ move_download_to_final_dest(package_file)
52
+ end
53
+
54
+ def data_file_exist?
55
+ ::File.exist?(data_file_path)
56
+ end
57
+
58
+ def data_file_time
59
+ data_file_exist? ? ::Time.now - ::File.mtime(data_file_path) : nil
60
+ end
61
+
62
+ def data_file_expired?
63
+ data_file_time.if_present(false) { |v| v >= expire_time }
64
+ end
65
+
66
+ def expire_time
67
+ @expire_time || DEFAULT_EXPIRE_TIME
68
+ end
69
+
70
+ private
71
+
72
+ def download
73
+ infom 'Downloading dump...'
74
+ download_path = find_download_path
75
+ dump_command.system!(output_file: download_path)
76
+ fatal_error "File \"#{download_path}\" not saved" unless ::File.exist?(download_path)
77
+ fatal_error "File \"#{download_path}\" is empty" if ::File.zero?(download_path)
78
+ download_path
79
+ end
80
+
81
+ def move_download_to_final_dest(download_path)
82
+ ::FileUtils.mkdir_p(::File.dirname(data_file_path))
83
+ ::FileUtils.mv(download_path, data_file_path)
84
+ end
85
+
86
+ def rotate
87
+ return unless data_file_exist?
88
+ return unless existing == EXISTING_ROTATE
89
+
90
+ infom "Rotating \"#{data_file_path}\"..."
91
+ ::Avm::Data::Rotate.new(data_file_path).run
92
+ end
93
+
94
+ def new_build_path
95
+ f = ::Tempfile.new(self.class.name.parameterize + '-download')
96
+ path = f.path
97
+ f.close
98
+ f.unlink
99
+ path
100
+ end
101
+
102
+ def dump_units_to_build_directory
103
+ dir = ::Dir.mktmpdir
104
+ package.dump_units_to_directory(dir)
105
+ dir
106
+ end
107
+
108
+ def create_package_file(build_dir)
109
+ package_path = new_build_path
110
+ infom "Creating package \"#{package_path}\" from \"#{build_dir}\"..."
111
+ Dir.chdir(build_dir) do
112
+ ::Minitar.pack('.', File.open(::File.expand_path(package_path), 'wb'))
113
+ end
114
+ package_path
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'minitar'
5
+
6
+ module Avm
7
+ module Data
8
+ class Package
9
+ class Load
10
+ enable_speaker
11
+
12
+ attr_reader :package, :data_file_path
13
+
14
+ def initialize(package, data_file_path)
15
+ @package = package
16
+ @data_file_path = data_file_path
17
+ end
18
+
19
+ def runnable?
20
+ cannot_run_reason.blank?
21
+ end
22
+
23
+ def cannot_run_reason
24
+ return nil if data_file_exist?
25
+
26
+ "Data file \"#{data_file_path}\" does not exist"
27
+ end
28
+
29
+ def run
30
+ raise "Cannot run: #{cannot_run_reason}" unless runnable?
31
+
32
+ build_dir = extract_packages_to_build_directory
33
+ package.load_units_from_directory(build_dir)
34
+ end
35
+
36
+ def data_file_exist?
37
+ ::File.exist?(data_file_path)
38
+ end
39
+
40
+ def extract_packages_to_build_directory
41
+ dir = ::Dir.mktmpdir
42
+ ::Minitar.unpack(data_file_path, dir)
43
+ dir
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/package/dump'
4
+ require 'avm/data/package/load'
5
+
6
+ module Avm
7
+ module Data
8
+ class Package
9
+ attr_reader :units
10
+
11
+ def initialize(options)
12
+ @units = {}
13
+ options = options.to_options_consumer
14
+ units = options.consume(:units)
15
+ options.validate
16
+ units.if_present do |v|
17
+ v.each { |identifier, unit| add_unit(identifier, unit) }
18
+ end
19
+ end
20
+
21
+ def add_unit(identifier, unit)
22
+ @units[identifier.to_sym] = unit
23
+ end
24
+
25
+ def dump(data_path, options = {})
26
+ ::Avm::Data::Package::Dump.new(self, data_path, options)
27
+ end
28
+
29
+ def load(data_path)
30
+ ::Avm::Data::Package::Load.new(self, data_path)
31
+ end
32
+
33
+ def dump_units_to_directory(directory)
34
+ @units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
35
+ end
36
+
37
+ def load_units_from_directory(directory)
38
+ @units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -4,7 +4,7 @@ require 'active_support/core_ext/object/blank'
4
4
  require 'eac_ruby_utils/simple_cache'
5
5
 
6
6
  module Avm
7
- module Files
7
+ module Data
8
8
  class Rotate
9
9
  include ::EacRubyUtils::SimpleCache
10
10
 
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'active_support/callbacks'
5
+
6
+ module Avm
7
+ module Data
8
+ class Unit
9
+ include ::ActiveSupport::Callbacks
10
+
11
+ define_callbacks :dump, :load
12
+ enable_speaker
13
+
14
+ %w[dump load].each do |action|
15
+ method_name = "#{action}_command"
16
+ class_eval <<~CODE, __FILE__, __LINE__ + 1
17
+ # Should be overrided.
18
+ # @return [EacRubyUtils::Envs::Command]
19
+ def #{method_name}
20
+ fail "\\"#{method_name}\\" is a abstract method. Override in #{singleton_class}."
21
+ end
22
+ 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
+ end
44
+
45
+ def extension
46
+ singleton_class.const_get('EXTENSION')
47
+ rescue NameError
48
+ ''
49
+ end
50
+
51
+ def name
52
+ self.class
53
+ end
54
+
55
+ def load_from_directory(directory, identifier)
56
+ load(unit_on_directory_path(directory, identifier))
57
+ end
58
+
59
+ def dump_to_directory(directory, identifier)
60
+ dump(unit_on_directory_path(directory, identifier))
61
+ end
62
+
63
+ def dump(data_path)
64
+ run_callbacks :dump do
65
+ infom "Dumping unit \"#{name}\" to \"#{data_path}\"..."
66
+ do_dump(data_path)
67
+ end
68
+ end
69
+
70
+ def load(data_path)
71
+ run_callbacks :load do
72
+ infom "Loading unit \"#{name}\" from \"#{data_path}\"..."
73
+ do_load(data_path)
74
+ end
75
+ end
76
+
77
+ protected
78
+
79
+ def do_dump(data_path)
80
+ dump_command.execute!(output_file: data_path)
81
+ end
82
+
83
+ def do_load(data_path)
84
+ load_command.execute!(input_file: data_path)
85
+ end
86
+
87
+ private
88
+
89
+ def unit_on_directory_path(directory, identifier)
90
+ ::File.join(directory, "#{identifier}#{extension}")
91
+ end
92
+ end
93
+ end
94
+ end
@@ -13,6 +13,7 @@ module Avm
13
13
 
14
14
  runner_with :help do
15
15
  desc 'Manipulate Docker images.'
16
+ bool_opt '-I', '--image-name', 'Output image name.'
16
17
  arg_opt '-n', '--registry-name', 'Docker registry\'s name.'
17
18
  bool_opt '-p', '--push', 'Push the image to Docker registry.'
18
19
  bool_opt '-r', '--run', 'Run or start a container with builded image.'
@@ -27,6 +28,7 @@ module Avm
27
28
  setup
28
29
  banner
29
30
  build
31
+ output_image_name
30
32
  push
31
33
  container_run
32
34
  end
@@ -84,6 +86,12 @@ module Avm
84
86
  )
85
87
  end
86
88
 
89
+ def output_image_name
90
+ return unless parsed.image_name
91
+
92
+ out(docker_image.tag.to_s.strip + "\n")
93
+ end
94
+
87
95
  def registry_uncached
88
96
  registry_from_option || registry_from_instance || registry_from_default ||
89
97
  fatal_error('No registry defined')
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/entries'
4
+
5
+ module Avm
6
+ module Instances
7
+ class Application
8
+ include ::Avm::Instances::Entries
9
+
10
+ attr_reader :id
11
+
12
+ def initialize(id)
13
+ @id = id.to_s
14
+ end
15
+
16
+ def to_s
17
+ id
18
+ end
19
+
20
+ def instance(suffix)
21
+ ::Avm::Instances::Base.new(self, suffix)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Access
8
+ def auto_access
9
+ read_entry_optional('ssh.url').present? ? 'ssh' : 'local'
10
+ end
11
+
12
+ def auto_ssh_hostname
13
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ssh.hostname')
14
+ end
15
+
16
+ def auto_ssh_port
17
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ssh.port') || 22
18
+ end
19
+
20
+ def auto_ssh_username
21
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ssh.username')
22
+ end
23
+
24
+ def auto_ssh_url
25
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ssh.url') ||
26
+ auto_ssh_url_by_parts
27
+ end
28
+
29
+ def auto_ssh_url_by_parts
30
+ read_entry_optional('ssh.hostname').if_present do |a|
31
+ a = read_entry_optional('ssh.username').if_present(a) { |v| "#{v}@#{a}" }
32
+ a = read_entry_optional('ssh.port').if_present(a) { |v| "#{a}:#{v}" }
33
+ "ssh://#{a}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Admin
8
+ def auto_admin_email
9
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'admin.email')
10
+ end
11
+
12
+ def auto_admin_name
13
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'admin.name')
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/package/dump'
4
+ require 'avm/self/instance'
5
+
6
+ module Avm
7
+ module Instances
8
+ class Base
9
+ module AutoValues
10
+ module Data
11
+ def auto_data_default_dump_path
12
+ ::Avm::Self
13
+ .instance
14
+ .read_entry_optional(::Avm::Self::Instance::EntryKeys::DATA_DEFAULT_PATH)
15
+ .if_present do |v|
16
+ ::File.join(
17
+ v,
18
+ "#{id}#{::Avm::Data::Instance::Package::Dump::DEFAULT_FILE_EXTENSION}"
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/entry_keys'
4
+
5
+ module Avm
6
+ module Instances
7
+ class Base
8
+ module AutoValues
9
+ module Database
10
+ DEFAULT_HOSTNAME = '127.0.0.1'
11
+ DEFAULT_LIMIT = 5
12
+ DEFAULT_PORTS = {
13
+ 'postgresql' => 5432,
14
+ 'mysql' => 3306,
15
+ 'oracle' => 1521,
16
+ 'sqlserver' => 1433
17
+ }.freeze
18
+ DEFAULT_SYSTEM = 'postgresql'
19
+ DEFAULT_TIMEOUT = 5000
20
+
21
+ def auto_database_name
22
+ inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID,
23
+ ::Avm::Instances::EntryKeys::DATABASE_NAME) || id
24
+ end
25
+
26
+ def auto_database_hostname
27
+ database_auto_common('hostname') || DEFAULT_HOSTNAME
28
+ end
29
+
30
+ def auto_database_limit
31
+ database_auto_common('limit') || DEFAULT_LIMIT
32
+ end
33
+
34
+ def auto_database_password
35
+ database_auto_common('password')
36
+ end
37
+
38
+ def auto_database_port
39
+ database_auto_common('port') || database_port_by_system
40
+ end
41
+
42
+ def auto_database_username
43
+ database_auto_common('username')
44
+ end
45
+
46
+ def auto_database_system
47
+ database_auto_common('system') || DEFAULT_SYSTEM
48
+ end
49
+
50
+ def auto_database_timeout
51
+ database_auto_common('timeout') || DEFAULT_TIMEOUT
52
+ end
53
+
54
+ private
55
+
56
+ def database_auto_common(suffix)
57
+ database_key = ::Avm::Instances::EntryKeys.const_get("database_#{suffix}".upcase)
58
+ inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID, database_key) ||
59
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, database_key)
60
+ end
61
+
62
+ def database_port_by_system
63
+ read_entry_optional(::Avm::Instances::EntryKeys::DATABASE_SYSTEM).if_present do |v|
64
+ DEFAULT_PORTS.fetch(v)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Filesystem
8
+ FS_PATH_KEY = :fs_path
9
+
10
+ def auto_fs_path
11
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, FS_PATH_KEY) do |v|
12
+ v + '/' + id
13
+ end
14
+ end
15
+
16
+ def auto_data_fs_path
17
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, :data_fs_path) do |v|
18
+ v + '/' + id
19
+ end
20
+ end
21
+
22
+ def auto_fs_url
23
+ auto_fs_url_with_ssh || auto_fs_url_without_ssh
24
+ end
25
+
26
+ def auto_fs_url_with_ssh
27
+ read_entry_optional('ssh.url').if_present do |ssh_url|
28
+ read_entry_optional('fs_path').if_present do |fs_path|
29
+ "#{ssh_url}#{fs_path}"
30
+ end
31
+ end
32
+ end
33
+
34
+ def auto_fs_url_without_ssh
35
+ return nil if read_entry_optional('ssh.url').present?
36
+
37
+ read_entry_optional('fs_path').if_present do |fs_path|
38
+ "file://#{fs_path}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end