avm-tools 0.68.0 → 0.70.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/data/instance/files_unit.rb +1 -1
  3. data/lib/avm/eac_rails_base0/apache_host.rb +17 -0
  4. data/lib/avm/eac_rails_base0/apache_path.rb +50 -0
  5. data/lib/avm/eac_rails_base0/deploy.rb +51 -0
  6. data/lib/avm/eac_rails_base0/instance.rb +14 -0
  7. data/lib/avm/eac_redmine_base0/deploy.rb +4 -4
  8. data/lib/avm/eac_redmine_base0/instance.rb +6 -5
  9. data/lib/avm/eac_ubuntu_base0/apache.rb +26 -0
  10. data/lib/avm/eac_ubuntu_base0/apache/resource.rb +59 -0
  11. data/lib/avm/eac_ubuntu_base0/docker_image.rb +14 -0
  12. data/lib/avm/eac_webapp_base0/apache_host.rb +103 -0
  13. data/lib/avm/eac_webapp_base0/deploy.rb +102 -0
  14. data/lib/avm/eac_webapp_base0/deploy/appended_directories.rb +25 -0
  15. data/lib/avm/eac_webapp_base0/deploy/file_unit.rb +42 -0
  16. data/lib/avm/eac_webapp_base0/deploy/git_info.rb +49 -0
  17. data/lib/avm/eac_webapp_base0/deploy/version.rb +20 -0
  18. data/lib/avm/eac_webapp_base0/instance.rb +50 -0
  19. data/lib/avm/eac_webapp_base0/runner/apache_host.rb +39 -0
  20. data/lib/avm/eac_webapp_base0/runner/data.rb +25 -0
  21. data/lib/avm/eac_webapp_base0/runner/data/dump.rb +69 -0
  22. data/lib/avm/eac_webapp_base0/runner/data/load.rb +66 -0
  23. data/lib/avm/eac_webapp_base0/runner/deploy.rb +59 -0
  24. data/lib/avm/git/issue/complete/_git_subrepos.rb +1 -0
  25. data/lib/avm/instances/base/auto_values/filesystem.rb +3 -1
  26. data/lib/avm/instances/entries.rb +5 -8
  27. data/lib/avm/instances/entry.rb +47 -0
  28. data/lib/avm/instances/entry_keys.rb +2 -0
  29. data/lib/avm/self/instance.rb +1 -1
  30. data/lib/avm/stereotypes/eac_wordpress_base0/apache_host.rb +3 -3
  31. data/lib/avm/stereotypes/eac_wordpress_base0/deploy.rb +2 -2
  32. data/lib/avm/stereotypes/eac_wordpress_base0/instance.rb +2 -2
  33. data/lib/avm/tools/runner/eac_rails_base0.rb +9 -14
  34. data/lib/avm/tools/runner/eac_rails_base0/apache_host.rb +3 -26
  35. data/lib/avm/tools/runner/eac_rails_base0/apache_path.rb +38 -0
  36. data/lib/avm/tools/runner/eac_rails_base0/data.rb +2 -2
  37. data/lib/avm/tools/runner/eac_rails_base0/deploy.rb +3 -3
  38. data/lib/avm/tools/runner/eac_redmine_base0/data.rb +1 -1
  39. data/lib/avm/tools/runner/eac_redmine_base0/data/dump.rb +2 -2
  40. data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +2 -2
  41. data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +1 -0
  42. data/lib/avm/tools/runner/eac_wordpress_base0/apache_host.rb +3 -25
  43. data/lib/avm/tools/runner/eac_wordpress_base0/data.rb +2 -2
  44. data/lib/avm/tools/runner/eac_wordpress_base0/deploy.rb +2 -2
  45. data/lib/avm/tools/runner/git/deploy.rb +3 -1
  46. data/lib/avm/tools/version.rb +1 -1
  47. data/template/avm/eac_rails_base0/apache_path/default.conf +13 -0
  48. data/template/avm/{stereotypes/eac_rails_base0 → eac_rails_base0}/deploy/config/database.yml.template +0 -0
  49. data/template/avm/{stereotypes/eac_webapp_base0 → eac_webapp_base0}/apache_host/no_ssl.conf +0 -0
  50. data/template/avm/self/docker_image/Dockerfile +1 -1
  51. data/vendor/eac_cli/Gemfile +5 -0
  52. data/vendor/eac_cli/eac_cli.gemspec +18 -0
  53. data/vendor/eac_cli/lib/eac_cli.rb +7 -0
  54. data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
  55. data/vendor/eac_cli/lib/eac_cli/default_runner.rb +14 -0
  56. data/vendor/eac_cli/lib/eac_cli/definition.rb +72 -0
  57. data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
  58. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +26 -0
  59. data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
  60. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +27 -0
  61. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +77 -0
  62. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +45 -0
  63. data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
  64. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +56 -0
  65. data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
  66. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +105 -0
  67. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +21 -0
  68. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +49 -0
  69. data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
  70. data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
  71. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +24 -0
  72. data/vendor/eac_cli/lib/eac_cli/runner.rb +87 -0
  73. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +18 -0
  74. data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
  75. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
  76. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
  77. data/vendor/eac_cli/lib/eac_cli/version.rb +5 -0
  78. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +70 -0
  79. data/vendor/eac_cli/spec/rubocop_spec.rb +7 -0
  80. data/vendor/eac_cli/spec/spec_helper.rb +100 -0
  81. data/vendor/eac_git/lib/eac_git/version.rb +1 -1
  82. data/vendor/eac_git/vendor/git-subrepo/lib/git-subrepo +9 -7
  83. data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +3 -3
  84. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +5 -1
  85. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  86. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +10 -0
  87. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb +6 -5
  88. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +5 -34
  89. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb +42 -0
  90. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/result.rb +25 -0
  91. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
  92. data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb +14 -0
  93. data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb +7 -0
  94. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
  95. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
  96. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
  97. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
  100. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
  102. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
  103. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +53 -0
  104. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  105. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
  106. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
  107. metadata +66 -22
  108. data/lib/avm/instances/entries/entry_reader.rb +0 -45
  109. data/lib/avm/stereotypes/eac_rails_base0/apache_host.rb +0 -19
  110. data/lib/avm/stereotypes/eac_rails_base0/deploy.rb +0 -52
  111. data/lib/avm/stereotypes/eac_rails_base0/instance.rb +0 -16
  112. data/lib/avm/stereotypes/eac_ubuntu_base0/apache.rb +0 -27
  113. data/lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb +0 -61
  114. data/lib/avm/stereotypes/eac_ubuntu_base0/docker_image.rb +0 -16
  115. data/lib/avm/stereotypes/eac_webapp_base0/apache_host.rb +0 -97
  116. data/lib/avm/stereotypes/eac_webapp_base0/deploy.rb +0 -104
  117. data/lib/avm/stereotypes/eac_webapp_base0/deploy/appended_directories.rb +0 -27
  118. data/lib/avm/stereotypes/eac_webapp_base0/deploy/file_unit.rb +0 -43
  119. data/lib/avm/stereotypes/eac_webapp_base0/deploy/git_info.rb +0 -51
  120. data/lib/avm/stereotypes/eac_webapp_base0/deploy/version.rb +0 -22
  121. data/lib/avm/stereotypes/eac_webapp_base0/instance.rb +0 -52
  122. data/lib/avm/stereotypes/eac_webapp_base0/runner/data.rb +0 -27
  123. data/lib/avm/stereotypes/eac_webapp_base0/runner/data/dump.rb +0 -71
  124. data/lib/avm/stereotypes/eac_webapp_base0/runner/data/load.rb +0 -68
  125. data/lib/avm/stereotypes/eac_webapp_base0/runner/deploy.rb +0 -61
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 804e613bfa303949fb0ed952f999d5815b6de62aea34e9c03c0e87ecf65f35b4
4
- data.tar.gz: a86f89745be17ae8bc039beb9d0e28680481e30069975c809a9083e42ef17589
3
+ metadata.gz: 4f29b6293211fb41769c831fee400ab44f3e7b23cce9a80cbe43fe66ff6c793f
4
+ data.tar.gz: b4ae8baa035b47388bf6266033a3a901911adbbf3841a4c5dc401bbf2e5081b8
5
5
  SHA512:
6
- metadata.gz: fcd4890d0c29dc11ddd5c1cbce9c5d767900e5e9be10d763afcb91fd73cfdd715c0f6ae217c64fc82f5e87128dbad619500e2ee3a33c4500a29c49739b5a93dc
7
- data.tar.gz: 89a8e507755008a2f7a18c0ee84ed2572588aff5ab12e0e9d5ec7e897a7c397f4cc6e1d2e7d83595d46fd3b835fcd3104dbb5cfebb38ae837113f25091169a85
6
+ metadata.gz: 12892c4a448f9238bd4e3ec55e1c4f03761a0a29ed5fb0fcf5a65962c314eae74903a4e1412acdeef945b896dc44f6f22bdaf4a3c989b78edd8b2f880efb32fe
7
+ data.tar.gz: 1f24a30ed4cd5f821ade563da4e1e3595cc3416fec7037ff847a988d8dc49f932a45c15143a3637a155ed5372027e2fd3be66c97bf34f99b53f55e234a2553b5
@@ -18,7 +18,7 @@ module Avm
18
18
  before_load :clear_files
19
19
 
20
20
  def files_path
21
- ::File.join(instance.read_entry(:fs_path), fs_path_subpath)
21
+ ::File.join(instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH), fs_path_subpath)
22
22
  end
23
23
 
24
24
  def dump_command
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/apache_host'
4
+
5
+ module Avm
6
+ module EacRailsBase0
7
+ class ApacheHost < ::Avm::EacWebappBase0::ApacheHost
8
+ def document_root
9
+ "#{instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)}/public"
10
+ end
11
+
12
+ def extra_content
13
+ 'PassengerEnabled On'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_ubuntu_base0/apache'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module EacRailsBase0
8
+ class ApachePath
9
+ enable_console_speaker
10
+ enable_simple_cache
11
+ common_constructor :instance, :options, default: [{}]
12
+
13
+ def run
14
+ write_available_conf
15
+ enable_conf
16
+ reload_apache
17
+ ::Avm::Result.success('Done')
18
+ end
19
+
20
+ def content
21
+ template.child('default.conf').apply(instance)
22
+ end
23
+
24
+ private
25
+
26
+ def apache_uncached
27
+ ::Avm::EacUbuntuBase0::Apache.new(instance.host_env)
28
+ end
29
+
30
+ def enable_conf
31
+ infom 'Enabling configuration...'
32
+ conf.enable
33
+ end
34
+
35
+ def reload_apache
36
+ infom 'Reloading Apache...'
37
+ apache.service('reload')
38
+ end
39
+
40
+ def conf_uncached
41
+ apache.conf(instance.id)
42
+ end
43
+
44
+ def write_available_conf
45
+ infom 'Writing available configuration...'
46
+ conf.write(content)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/deploy'
4
+
5
+ module Avm
6
+ module EacRailsBase0
7
+ class Deploy < ::Avm::EacWebappBase0::Deploy
8
+ set_callback :assert_instance_branch, :after do
9
+ bundle_install
10
+ assert_database
11
+ database_migrate
12
+ compile_assets
13
+ restart_tasks_scheduler
14
+ touch_restart_file
15
+ end
16
+
17
+ def assert_database
18
+ infom 'Asserting database...'
19
+ instance.rake('db:create').system!
20
+ end
21
+
22
+ def bundle_install
23
+ infom 'Running "bundle install"...'
24
+ instance.bundle('install').system!
25
+ end
26
+
27
+ def compile_assets
28
+ infom 'Compiling assets...'
29
+ instance.rake('assets:clean', 'assets:precompile').system!
30
+ end
31
+
32
+ def database_migrate
33
+ infom 'Running database migrations...'
34
+ instance.rake('db:migrate').system!
35
+ end
36
+
37
+ def restart_tasks_scheduler
38
+ infom 'Restarting Tasks Scheduler\'s daemon...'
39
+ instance.bundle('exec', 'tasks_scheduler', 'restart').system!
40
+ end
41
+
42
+ def touch_restart_file
43
+ infom 'Touching restart file...'
44
+ instance.host_env.command(
45
+ 'touch', ::File.join(instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH),
46
+ 'tmp', 'restart.txt')
47
+ ).system!
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/instance'
4
+ require 'avm/stereotypes/rails/instance'
5
+
6
+ module Avm
7
+ module EacRailsBase0
8
+ class Instance < ::Avm::EacWebappBase0::Instance
9
+ include ::Avm::Stereotypes::Rails::Instance
10
+
11
+ FILES_UNITS = { uploads: 'public/uploads' }.freeze
12
+ end
13
+ end
14
+ end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/stereotypes/eac_webapp_base0/deploy'
3
+ require 'avm/eac_webapp_base0/deploy'
4
4
  require 'eac_ruby_utils/ruby'
5
5
 
6
6
  module Avm
7
7
  module EacRedmineBase0
8
- class Deploy < ::Avm::Stereotypes::EacWebappBase0::Deploy
8
+ class Deploy < ::Avm::EacWebappBase0::Deploy
9
9
  set_callback :assert_instance_branch, :after, :run_installer
10
10
 
11
11
  def run_installer
@@ -20,8 +20,8 @@ module Avm
20
20
  end
21
21
 
22
22
  def installer_path
23
- ::File.join(instance.read_entry(:fs_path), 'plugins', 'redmine_installer', 'installer',
24
- 'run.sh')
23
+ ::File.join(instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH), 'plugins',
24
+ 'redmine_installer', 'installer', 'run.sh')
25
25
  end
26
26
 
27
27
  def install_task
@@ -1,24 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/eac_redmine_base0/data_unit'
4
- require 'avm/stereotypes/eac_ubuntu_base0/docker_image'
5
- require 'avm/stereotypes/eac_webapp_base0/instance'
4
+ require 'avm/eac_ubuntu_base0/docker_image'
5
+ require 'avm/eac_webapp_base0/instance'
6
6
  require 'avm/stereotypes/rails/instance'
7
7
 
8
8
  module Avm
9
9
  module EacRedmineBase0
10
- class Instance < ::Avm::Stereotypes::EacWebappBase0::Instance
10
+ class Instance < ::Avm::EacWebappBase0::Instance
11
11
  include ::Avm::Stereotypes::Rails::Instance
12
12
 
13
13
  FILES_UNITS = { files: 'files' }.freeze
14
14
 
15
15
  def docker_image_class
16
- ::Avm::Stereotypes::EacUbuntuBase0::DockerImage
16
+ ::Avm::EacUbuntuBase0::DockerImage
17
17
  end
18
18
 
19
19
  def docker_run_arguments
20
20
  [
21
- '--volume', "#{read_entry(:fs_path)}:/home/myuser/eac_redmine_base0",
21
+ '--volume',
22
+ "#{read_entry(::Avm::Instances::EntryKeys::FS_PATH)}:/home/myuser/eac_redmine_base0",
22
23
  '--publish', "#{read_entry(:ssh_port)}:22",
23
24
  '--publish', "#{read_entry(:http_port)}:80",
24
25
  '--publish', "#{read_entry(:https_port)}:443"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacUbuntuBase0
7
+ class Apache
8
+ require_sub __FILE__
9
+ common_constructor :host_env
10
+
11
+ def etc_root
12
+ '/etc/apache2'
13
+ end
14
+
15
+ def service(command)
16
+ host_env.command('sudo', 'service', 'apache2', command)
17
+ end
18
+
19
+ { conf: :conf, site: :sites }.each do |type, directory_prefix|
20
+ define_method type do |name|
21
+ ::Avm::EacUbuntuBase0::Apache::Resource.new(self, type, directory_prefix, name)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacUbuntuBase0
7
+ class Apache
8
+ class Resource
9
+ common_constructor :apache, :type, :directory_prefix, :name
10
+
11
+ def available_path
12
+ ::File.join(apache.etc_root, "#{directory_prefix}-available", "#{name}.conf")
13
+ end
14
+
15
+ def available?
16
+ apache.host_env.file(available_path).exist?
17
+ end
18
+
19
+ def disable
20
+ apache.host_env.command('sudo', "a2dis#{type}", name).execute!
21
+ end
22
+
23
+ def enable
24
+ apache.host_env.command('sudo', "a2en#{type}", name).execute!
25
+ end
26
+
27
+ def enabled_path
28
+ ::File.join(apache.etc_root, "#{directory_prefix}-enabled", "#{name}.conf")
29
+ end
30
+
31
+ def enabled?
32
+ apache.host_env.file(enabled_path).exist?
33
+ end
34
+
35
+ def remove
36
+ remove_disabled
37
+ remove_available
38
+ end
39
+
40
+ def remove_available
41
+ raise 'Remove enabled before' if enabled?
42
+
43
+ apache.host_env.command('sudo', 'rm', '-f', available_path).execute! if available?
44
+ end
45
+
46
+ def remove_disabled
47
+ disable if enabled?
48
+ apache.host_env.command('sudo', 'rm', '-f', enabled_path).execute! if enabled?
49
+ end
50
+
51
+ def write(content)
52
+ ::EacRubyUtils::Envs.local.command('echo', content).pipe(
53
+ apache.host_env.command('sudo', 'tee', available_path)
54
+ ).execute!
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/docker/image'
5
+
6
+ module Avm
7
+ module EacUbuntuBase0
8
+ class DockerImage < ::Avm::Docker::Image
9
+ def stereotype_tag
10
+ 'eac_ubuntu_base0'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/patches/object/template'
5
+ require 'avm/eac_ubuntu_base0/apache'
6
+ require 'avm/patches/object/template'
7
+
8
+ module Avm
9
+ module EacWebappBase0
10
+ class ApacheHost
11
+ enable_console_speaker
12
+ enable_simple_cache
13
+ common_constructor :instance, :options, default: [{}]
14
+
15
+ def run
16
+ write_available_no_ssl_site
17
+ enable_no_ssl_site
18
+ remove_ssl_site
19
+ reload_apache
20
+ run_certbot
21
+ enable_ssl_site
22
+ reload_apache
23
+ ::Avm::Result.success('Done')
24
+ end
25
+
26
+ def no_ssl_site_content
27
+ ::Avm::EacWebappBase0::ApacheHost.template.child('no_ssl.conf')
28
+ .apply(EntriesReader.new(self, instance))
29
+ end
30
+
31
+ def ssl?
32
+ options[:certbot]
33
+ end
34
+
35
+ private
36
+
37
+ def apache_uncached
38
+ ::Avm::EacUbuntuBase0::Apache.new(instance.host_env)
39
+ end
40
+
41
+ def enable_no_ssl_site
42
+ infom 'Enabling no SSL site...'
43
+ no_ssl_site.enable
44
+ end
45
+
46
+ def enable_ssl_site
47
+ return unless ssl?
48
+
49
+ infom 'Enabling SSL site...'
50
+ ssl_site.enable
51
+ end
52
+
53
+ def no_ssl_site_uncached
54
+ apache.site(instance.id)
55
+ end
56
+
57
+ def reload_apache
58
+ infom 'Reloading Apache...'
59
+ apache.service('reload')
60
+ end
61
+
62
+ def remove_ssl_site
63
+ infom 'Removing SSL site...'
64
+ ssl_site.remove
65
+ end
66
+
67
+ def run_certbot
68
+ return unless ssl?
69
+
70
+ infom 'Running Certbot...'
71
+ instance.host_env.command(
72
+ 'sudo', 'certbot', '--apache', '--domain', instance.read_entry('web.hostname'),
73
+ '--redirect', '--non-interactive', '--agree-tos',
74
+ '--email', instance.read_entry('admin.email')
75
+ ).system!
76
+ end
77
+
78
+ def ssl_site_uncached
79
+ apache.site(no_ssl_site.name + '-le-ssl')
80
+ end
81
+
82
+ def write_available_no_ssl_site
83
+ infom 'Writing no SSL site conf...'
84
+ no_ssl_site.write(no_ssl_site_content)
85
+ end
86
+
87
+ class EntriesReader
88
+ common_constructor :job, :instance
89
+
90
+ def read_entry(path, options = {})
91
+ entry_from_job(path) || instance.read_entry(path, options)
92
+ end
93
+
94
+ private
95
+
96
+ def entry_from_job(path)
97
+ method = path.gsub('.', '_').underscore
98
+ return job.send(method) if job.respond_to?(method, true)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/callbacks'
4
+ require 'delegate'
5
+ require 'eac_ruby_utils/core_ext'
6
+ require 'eac_launcher/git/base'
7
+ require 'avm/git'
8
+ require 'avm/patches/object/template'
9
+ require 'net/http'
10
+
11
+ module Avm
12
+ module EacWebappBase0
13
+ class Deploy
14
+ require_sub __FILE__, include_modules: true
15
+ include ::ActiveSupport::Callbacks
16
+
17
+ DEFAULT_REFERENCE = 'HEAD'
18
+
19
+ enable_console_speaker
20
+ enable_simple_cache
21
+
22
+ JOBS = %w[git_deploy setup_files_units assert_instance_branch request_test].freeze
23
+ define_callbacks(*JOBS)
24
+
25
+ attr_reader :instance, :options
26
+
27
+ def initialize(instance, options = {})
28
+ @instance = instance
29
+ @options = options
30
+ end
31
+
32
+ def build_git_commit
33
+ ::Avm::Git::Commit.new(git, commit_sha1).deploy_to_env_path(
34
+ instance.host_env,
35
+ instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)
36
+ ).variables_source_set(instance)
37
+ end
38
+
39
+ def run
40
+ start_banner
41
+ JOBS.each do |job|
42
+ run_callbacks job do
43
+ send(job)
44
+ end
45
+ end
46
+ ::Avm::Result.success('Deployed')
47
+ rescue ::Avm::Result::Error => e
48
+ e.to_result
49
+ end
50
+
51
+ def start_banner
52
+ infov 'Instance', instance
53
+ infov 'Git reference (User)', git_reference.if_present('- BLANK -')
54
+ infov 'Git remote name', git_remote_name
55
+ infov 'Git reference (Found)', git_reference_found
56
+ infov 'Git commit SHA1', commit_sha1
57
+ infov 'Appended directories', appended_directories
58
+ end
59
+
60
+ def git_deploy
61
+ infom 'Deploying source code and appended content...'
62
+ build_git_commit
63
+ .append_directory(template.path)
64
+ .append_directories(appended_directories)
65
+ .append_file_content(VERSION_TARGET_PATH, version)
66
+ .run
67
+ end
68
+
69
+ def setup_files_units
70
+ instance.class.const_get('FILES_UNITS').each do |data_key, fs_path_subpath|
71
+ FileUnit.new(self, data_key, fs_path_subpath).run
72
+ end
73
+ end
74
+
75
+ def assert_instance_branch
76
+ infom 'Setting instance branch...'
77
+ git.execute!('push', git_remote_name, "#{commit_sha1}:refs/heads/#{instance.id}", '-f')
78
+ end
79
+
80
+ def request_test
81
+ infom 'Requesting web interface...'
82
+ uri = URI(instance.read_entry('web.url'))
83
+ response = ::Net::HTTP.get_response(uri)
84
+ infov 'Response status', response.code
85
+ fatal_error "Request to #{uri} failed" unless response.code.to_i == 200
86
+ end
87
+
88
+ def git_uncached
89
+ ::EacLauncher::Git::Base.new(git_repository_path)
90
+ end
91
+
92
+ def git_fetch_uncached
93
+ infom "Fetching remote \"#{git_remote_name}\" from \"#{git_repository_path}\"..."
94
+ git.fetch(git_remote_name)
95
+ end
96
+
97
+ def git_repository_path
98
+ instance.source_instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)
99
+ end
100
+ end
101
+ end
102
+ end