avm 0.5.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/data/package/dump.rb +3 -3
  3. data/lib/avm/{files → data}/rotate.rb +1 -1
  4. data/lib/avm/docker/runner.rb +8 -0
  5. data/lib/avm/instances/application.rb +25 -0
  6. data/lib/avm/instances/base/auto_values/access.rb +40 -0
  7. data/lib/avm/instances/base/auto_values/admin.rb +19 -0
  8. data/lib/avm/instances/base/auto_values/data.rb +26 -0
  9. data/lib/avm/instances/base/auto_values/database.rb +76 -0
  10. data/lib/avm/instances/base/auto_values/filesystem.rb +45 -0
  11. data/lib/avm/instances/base/auto_values/mailer.rb +34 -0
  12. data/lib/avm/instances/base/auto_values/ruby.rb +15 -0
  13. data/lib/avm/instances/base/auto_values/source.rb +15 -0
  14. data/lib/avm/instances/base/auto_values/system.rb +23 -0
  15. data/lib/avm/instances/base/auto_values/web.rb +46 -0
  16. data/lib/avm/instances/base/auto_values.rb +21 -0
  17. data/lib/avm/instances/base/dockerizable.rb +45 -0
  18. data/lib/avm/instances/base/entry_keys.rb +22 -0
  19. data/lib/avm/instances/base.rb +64 -0
  20. data/lib/avm/instances/entries.rb +43 -0
  21. data/lib/avm/instances/entry.rb +54 -0
  22. data/lib/avm/instances/entry_keys.rb +57 -0
  23. data/lib/avm/instances/runner.rb +38 -0
  24. data/lib/avm/instances.rb +8 -0
  25. data/lib/avm/jobs/base.rb +1 -0
  26. data/lib/avm/registry/base.rb +65 -0
  27. data/lib/avm/registry.rb +29 -0
  28. data/lib/avm/rspec/setup.rb +22 -0
  29. data/lib/avm/rspec/shared_examples/in_avm_registry.rb +11 -0
  30. data/lib/avm/rspec/shared_examples/not_in_avm_registry.rb +14 -0
  31. data/lib/avm/{git/organize.rb → rspec.rb} +2 -4
  32. data/lib/avm/runners/base.rb +31 -0
  33. data/lib/avm/scms/base.rb +28 -0
  34. data/lib/avm/scms/commit.rb +43 -0
  35. data/lib/avm/self/docker_image.rb +14 -0
  36. data/lib/avm/self/instance/entry_keys.rb +12 -0
  37. data/lib/avm/self/instance.rb +24 -0
  38. data/lib/avm/source_stereotypes/base.rb +21 -0
  39. data/lib/avm/sources/base.rb +22 -0
  40. data/lib/avm/version.rb +1 -1
  41. metadata +58 -67
  42. data/lib/avm/files/appendable/file_content.rb +0 -24
  43. data/lib/avm/files/appendable/plain_directory.rb +0 -25
  44. data/lib/avm/files/appendable/resource_base.rb +0 -13
  45. data/lib/avm/files/appendable/tar_output_command.rb +0 -26
  46. data/lib/avm/files/appendable/templatized_directory.rb +0 -29
  47. data/lib/avm/files/appendable.rb +0 -55
  48. data/lib/avm/files/appender.rb +0 -11
  49. data/lib/avm/files/deploy.rb +0 -71
  50. data/lib/avm/files/formatter/formats/base.rb +0 -62
  51. data/lib/avm/files/formatter/formats/generic_plain.rb +0 -34
  52. data/lib/avm/files/formatter/formats/html.rb +0 -45
  53. data/lib/avm/files/formatter/formats/javascript.rb +0 -24
  54. data/lib/avm/files/formatter/formats/json.rb +0 -27
  55. data/lib/avm/files/formatter/formats/php.rb +0 -22
  56. data/lib/avm/files/formatter/formats/python.rb +0 -22
  57. data/lib/avm/files/formatter/formats/ruby.rb +0 -22
  58. data/lib/avm/files/formatter/formats/xml.rb +0 -28
  59. data/lib/avm/files/formatter/formats.rb +0 -13
  60. data/lib/avm/files/formatter/utf8_assert.rb +0 -74
  61. data/lib/avm/files/formatter.rb +0 -90
  62. data/lib/avm/files.rb +0 -9
  63. data/lib/avm/git/auto_commit/commit_info.rb +0 -23
  64. data/lib/avm/git/auto_commit/rules/base.rb +0 -39
  65. data/lib/avm/git/auto_commit/rules/last.rb +0 -19
  66. data/lib/avm/git/auto_commit/rules/manual.rb +0 -45
  67. data/lib/avm/git/auto_commit/rules/new.rb +0 -24
  68. data/lib/avm/git/auto_commit/rules/nth.rb +0 -31
  69. data/lib/avm/git/auto_commit/rules/unique.rb +0 -21
  70. data/lib/avm/git/auto_commit/rules.rb +0 -31
  71. data/lib/avm/git/auto_commit_path/ruby.rb +0 -20
  72. data/lib/avm/git/auto_commit_path.rb +0 -28
  73. data/lib/avm/git/commit/class_methods.rb +0 -31
  74. data/lib/avm/git/commit/deploy.rb +0 -38
  75. data/lib/avm/git/commit/deploy_methods.rb +0 -19
  76. data/lib/avm/git/commit/diff_tree_line.rb +0 -32
  77. data/lib/avm/git/commit/file.rb +0 -46
  78. data/lib/avm/git/commit.rb +0 -59
  79. data/lib/avm/git/file_auto_fixup.rb +0 -83
  80. data/lib/avm/git/issue/complete/commits.rb +0 -42
  81. data/lib/avm/git/issue/complete/git_subrepos.rb +0 -23
  82. data/lib/avm/git/issue/complete/local_branch.rb +0 -54
  83. data/lib/avm/git/issue/complete/local_tag.rb +0 -39
  84. data/lib/avm/git/issue/complete/push.rb +0 -54
  85. data/lib/avm/git/issue/complete/remote.rb +0 -33
  86. data/lib/avm/git/issue/complete/test.rb +0 -45
  87. data/lib/avm/git/issue/complete/tracker.rb +0 -28
  88. data/lib/avm/git/issue/complete/validation.rb +0 -31
  89. data/lib/avm/git/issue/complete/validations.rb +0 -53
  90. data/lib/avm/git/issue/complete/working_tree.rb +0 -19
  91. data/lib/avm/git/issue/complete.rb +0 -51
  92. data/lib/avm/git/issue/deliver.rb +0 -56
  93. data/lib/avm/git/issue.rb +0 -11
  94. data/lib/avm/git/organize/reference_update.rb +0 -34
  95. data/lib/avm/git/organize/repository.rb +0 -76
  96. data/lib/avm/git/revision_test.rb +0 -105
  97. data/lib/avm/git/subrepo_check/parent.rb +0 -51
  98. data/lib/avm/git/subrepo_check/remote.rb +0 -89
  99. data/lib/avm/git/subrepo_check/show_result.rb +0 -32
  100. data/lib/avm/git/subrepo_check.rb +0 -38
  101. data/lib/avm/git/subrepo_checks.rb +0 -59
  102. data/lib/avm/git.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c21e54d17440b61336b3345c8c6f2db32b0d2d31f6f9d56f78894d4f01bbb3c7
4
- data.tar.gz: 29604235a823f781751eaf5031b967a1cf01c5d6c14e194c09e7bfaaba8c2043
3
+ metadata.gz: 6ca24d93ae7424cc6e6d3929b9341e236602aacbb75e2930ca2cb2b435bce9e6
4
+ data.tar.gz: b0af011f034b3cbfa225cea4dc452d33315c34811f82f90a0843848ef2f3f3b7
5
5
  SHA512:
6
- metadata.gz: a3240b4fafbfedcd68581fec71de2099906e599df3adb4f64d4bd66b4ced66582a02ced5db16d47c91ed78eb580daea910c44554d9abfef10ab3b308ff160ab2
7
- data.tar.gz: 1104ec38c87bc15499ad0cd3d37ddd9c6ad0075d1c286ecb514a142d62f329e9c83035f23223788a5d5acb41a769e13f394180d84b80591a5035e347107de153
6
+ metadata.gz: 58d1f630e478a6a7967f61e7979f40f76b2edf467cdda9d95b6228830daf0f87b88342e4e8abdfea5fbd944ba5ed05064efd9e300a81509bbfe8fbe6b2da78e8
7
+ data.tar.gz: 025d2bc3ad847b019bb297c00436ebbb6b2d6655040d98a98d3137fba90285b496b0afd08cba53d234252a0fd9d92f551234a59ae7c248e08eb87db3a0f60565
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/tools/core_ext'
4
- require 'avm/files/rotate'
3
+ require 'avm/data/rotate'
4
+ require 'eac_ruby_utils/core_ext'
5
5
  require 'minitar'
6
6
 
7
7
  module Avm
@@ -88,7 +88,7 @@ module Avm
88
88
  return unless existing == EXISTING_ROTATE
89
89
 
90
90
  infom "Rotating \"#{data_file_path}\"..."
91
- ::Avm::Files::Rotate.new(data_file_path).run
91
+ ::Avm::Data::Rotate.new(data_file_path).run
92
92
  end
93
93
 
94
94
  def new_build_path
@@ -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
 
@@ -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,76 @@
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_EXTRA = ''
11
+ DEFAULT_HOSTNAME = '127.0.0.1'
12
+ DEFAULT_LIMIT = 5
13
+ DEFAULT_PORTS = {
14
+ 'postgresql' => 5432,
15
+ 'mysql' => 3306,
16
+ 'oracle' => 1521,
17
+ 'sqlserver' => 1433
18
+ }.freeze
19
+ DEFAULT_SYSTEM = 'postgresql'
20
+ DEFAULT_TIMEOUT = 5000
21
+
22
+ def auto_database_extra
23
+ database_auto_common('hostname') || DEFAULT_EXTRA
24
+ end
25
+
26
+ def auto_database_name
27
+ inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID,
28
+ ::Avm::Instances::EntryKeys::DATABASE_NAME) || id
29
+ end
30
+
31
+ def auto_database_hostname
32
+ database_auto_common('hostname') || DEFAULT_HOSTNAME
33
+ end
34
+
35
+ def auto_database_limit
36
+ database_auto_common('limit') || DEFAULT_LIMIT
37
+ end
38
+
39
+ def auto_database_password
40
+ database_auto_common('password')
41
+ end
42
+
43
+ def auto_database_port
44
+ database_auto_common('port') || database_port_by_system
45
+ end
46
+
47
+ def auto_database_username
48
+ database_auto_common('username')
49
+ end
50
+
51
+ def auto_database_system
52
+ database_auto_common('system') || DEFAULT_SYSTEM
53
+ end
54
+
55
+ def auto_database_timeout
56
+ database_auto_common('timeout') || DEFAULT_TIMEOUT
57
+ end
58
+
59
+ private
60
+
61
+ def database_auto_common(suffix)
62
+ database_key = ::Avm::Instances::EntryKeys.const_get("database_#{suffix}".upcase)
63
+ inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID, database_key) ||
64
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, database_key)
65
+ end
66
+
67
+ def database_port_by_system
68
+ read_entry_optional(::Avm::Instances::EntryKeys::DATABASE_SYSTEM).if_present do |v|
69
+ DEFAULT_PORTS.fetch(v)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ 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
@@ -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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Ruby
8
+ def auto_ruby_version
9
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ruby.version')
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Source
8
+ def auto_source_instance_id
9
+ "#{application.id}_dev"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable'
4
+
5
+ module Avm
6
+ module Instances
7
+ class Base
8
+ module AutoValues
9
+ module System
10
+ def auto_system_username
11
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'system.username') ||
12
+ read_entry_optional('ssh.username')
13
+ end
14
+
15
+ def auto_system_groupname
16
+ inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'system.groupname') ||
17
+ read_entry_optional('system.username')
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable'
4
+ require 'avm/instances/entry_keys'
5
+
6
+ module Avm
7
+ module Instances
8
+ class Base
9
+ module AutoValues
10
+ module Web
11
+ def auto_web_authority
12
+ web_url_as_uri(&:authority)
13
+ end
14
+
15
+ def auto_web_hostname
16
+ web_url_as_uri(&:host)
17
+ end
18
+
19
+ def auto_web_path
20
+ web_url_as_uri(&:path)
21
+ end
22
+
23
+ def auto_web_port
24
+ web_url_as_uri(&:port)
25
+ end
26
+
27
+ def auto_web_scheme
28
+ web_url_as_uri(&:scheme)
29
+ end
30
+
31
+ def auto_web_userinfo
32
+ web_url_as_uri(&:userinfo)
33
+ end
34
+
35
+ private
36
+
37
+ def web_url_as_uri
38
+ read_entry_optional(::Avm::Instances::EntryKeys::WEB_URL).if_present do |v|
39
+ yield(::Addressable::URI.parse(v))
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
6
+ module Avm
7
+ module Instances
8
+ class Base
9
+ module AutoValues
10
+ extend ::ActiveSupport::Concern
11
+
12
+ included do
13
+ %w[Access Admin Data Database Filesystem Mailer Ruby Source System Web]
14
+ .each do |class_name|
15
+ include const_get(class_name)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/executables'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'avm/docker/container'
6
+
7
+ module Avm
8
+ module Instances
9
+ class Base
10
+ module Dockerizable
11
+ enable_simple_cache
12
+ attr_reader :docker_image_options
13
+
14
+ def docker_image_options=(options)
15
+ @docker_image_options = ::ActiveSupport::HashWithIndifferentAccess.new(options)
16
+ reset_cache
17
+ end
18
+
19
+ def docker_container_exist?
20
+ ::EacDocker::Executables.docker.command.append(
21
+ ['ps', '-qaf', "name=#{docker_container_name}"]
22
+ ).execute!.present?
23
+ end
24
+
25
+ def docker_container_name
26
+ id
27
+ end
28
+
29
+ private
30
+
31
+ def docker_container_uncached
32
+ ::Avm::Docker::Container.new(self)
33
+ end
34
+
35
+ def docker_image_uncached
36
+ r = docker_image_class.new(docker_image_options.fetch(:registry))
37
+ r.instance = self if r.respond_to?(:instance)
38
+ r.version = docker_image_options[:version] if docker_image_options.key?(:version)
39
+ r.snapshot = docker_image_options[:snapshot] if docker_image_options.key?(:snapshot)
40
+ r
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/entry_keys'
4
+
5
+ module Avm
6
+ module Instances
7
+ class Base
8
+ module EntryKeys
9
+ ::Avm::Instances::EntryKeys.all.each do |key|
10
+ method_name = key.to_s.variableize
11
+ define_method method_name do
12
+ read_entry(key)
13
+ end
14
+
15
+ define_method "#{method_name}_optional" do
16
+ read_entry(key, required: false)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'avm/instances/entries'
6
+
7
+ module Avm
8
+ module Instances
9
+ class Base
10
+ enable_listable
11
+ enable_simple_cache
12
+ require_sub __FILE__, include_modules: true
13
+ include ::Avm::Instances::Entries
14
+
15
+ lists.add_string :access, :local, :ssh
16
+
17
+ ID_PATTERN = /\A([a-z0-9]+(?:\-[a-z0-9]+)*)_(.+)\z/.freeze
18
+
19
+ class << self
20
+ def by_id(id)
21
+ application_id, suffix = parse_id(id)
22
+ require 'avm/instances/application'
23
+ new(::Avm::Instances::Application.new(application_id), suffix)
24
+ end
25
+
26
+ private
27
+
28
+ def parse_id(id)
29
+ m = ID_PATTERN.match(id)
30
+ return [m[1], m[2]] if m
31
+
32
+ raise "ID Pattern no matched: \"#{id}\""
33
+ end
34
+ end
35
+
36
+ common_constructor :application, :suffix do
37
+ self.suffix = suffix.to_s
38
+ end
39
+
40
+ def id
41
+ "#{application.id}_#{suffix}"
42
+ end
43
+
44
+ def to_s
45
+ id
46
+ end
47
+
48
+ def host_env_uncached
49
+ access = read_entry(:access, list: ::Avm::Instances::Base.lists.access.values)
50
+ case access
51
+ when 'local' then ::EacRubyUtils::Envs.local
52
+ when 'ssh' then ::EacRubyUtils::Envs.ssh(read_entry('ssh.url'))
53
+ else raise("Unmapped access value: \"#{access}\"")
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def source_instance_uncached
60
+ ::Avm::Instances::Base.by_id(source_instance_id)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/instances/entry'
5
+
6
+ module Avm
7
+ module Instances
8
+ module Entries
9
+ def entry(suffix, options = {})
10
+ ::Avm::Instances::Entry.new(self, suffix, options)
11
+ end
12
+
13
+ def path_prefix
14
+ @path_prefix ||= [id].freeze
15
+ end
16
+
17
+ def read_entry(entry_suffix, options = {})
18
+ entry(entry_suffix, options).value
19
+ end
20
+
21
+ def read_entry_optional(entry_suffix, options = {})
22
+ entry(entry_suffix, options).optional_value
23
+ end
24
+
25
+ def full_entry_path(entry_suffix)
26
+ unless entry_suffix.is_a?(::Array)
27
+ entry_suffix = ::EacConfig::PathsHash.parse_entry_key(entry_suffix.to_s)
28
+ end
29
+ (path_prefix + entry_suffix).join('.')
30
+ end
31
+
32
+ def inherited_entry_value(source_entry_suffix, target_entry_suffix, &block)
33
+ read_entry_optional(source_entry_suffix).if_present do |instance_id|
34
+ other_entry_value(instance_id, target_entry_suffix).if_present(&block)
35
+ end
36
+ end
37
+
38
+ def other_entry_value(instance_id, entry_suffix)
39
+ ::Avm::Instances::Base.by_id(instance_id).read_entry_optional(entry_suffix)
40
+ end
41
+ end
42
+ end
43
+ end