avm-tools 0.61.0 → 0.62.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/cached_download.rb +39 -0
  3. data/lib/avm/eac_redmine_base0/core_update.rb +110 -0
  4. data/lib/avm/eac_redmine_base0/data_unit.rb +27 -0
  5. data/lib/avm/eac_redmine_base0/deploy.rb +36 -0
  6. data/lib/avm/eac_redmine_base0/instance.rb +38 -0
  7. data/lib/avm/instances/configuration.rb +11 -3
  8. data/lib/avm/instances/configuration/_tests.rb +1 -1
  9. data/lib/avm/launcher/context/instance_manager.rb +76 -0
  10. data/lib/avm/launcher/context/instance_manager/cached_instance.rb +37 -0
  11. data/lib/avm/launcher/context/instance_manager/cached_instances.rb +35 -0
  12. data/lib/avm/launcher/errors/base.rb +10 -0
  13. data/lib/avm/launcher/errors/non_project.rb +15 -0
  14. data/lib/avm/launcher/instances/base.rb +94 -0
  15. data/lib/avm/launcher/instances/base/cache.rb +43 -0
  16. data/lib/avm/patches/eac_ruby_gems_utils/gem.rb +28 -0
  17. data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +5 -4
  18. data/lib/avm/projects/stereotypes/ruby_gem/local_project_mixin.rb +1 -1
  19. data/lib/avm/ruby/rubocop/_gemfile.rb +2 -2
  20. data/lib/avm/stereotypes/eac_webapp_base0/runner/deploy.rb +3 -1
  21. data/lib/avm/sync.rb +94 -0
  22. data/lib/avm/tools/runner/eac_redmine_base0.rb +2 -2
  23. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +67 -0
  24. data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +1 -1
  25. data/lib/avm/tools/version.rb +1 -1
  26. data/lib/eac_launcher/context.rb +2 -2
  27. data/lib/eac_launcher/context/instance_discovery.rb +2 -2
  28. data/lib/eac_launcher/git/base/dirty_files.rb +1 -1
  29. data/lib/eac_launcher/git/sub_warp_base.rb +3 -2
  30. data/lib/eac_launcher/instances.rb +2 -2
  31. data/lib/eac_launcher/instances/error.rb +7 -3
  32. data/lib/eac_launcher/paths/logical.rb +2 -2
  33. data/lib/eac_launcher/publish/base.rb +2 -2
  34. data/template/avm/{stereotypes/eac_redmine_base0 → eac_redmine_base0}/deploy/config/install.sh.template +0 -0
  35. data/template/avm/{stereotypes/eac_redmine_base0 → eac_redmine_base0}/deploy/config/secrets.yml +0 -0
  36. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +1 -1
  37. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
  38. metadata +20 -11
  39. data/lib/avm/stereotypes/eac_redmine_base0/data_unit.rb +0 -29
  40. data/lib/avm/stereotypes/eac_redmine_base0/deploy.rb +0 -38
  41. data/lib/avm/stereotypes/eac_redmine_base0/instance.rb +0 -40
  42. data/lib/eac_launcher/context/instance_manager.rb +0 -95
  43. data/lib/eac_launcher/instances/base.rb +0 -91
  44. data/lib/eac_launcher/instances/base/cache.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '039f5b3b40307ddabe21c292a6f2fb1accf902dee691dac160648f9b305d094a'
4
- data.tar.gz: f3a4993ab7abf9d0d5ae0a75196532460a4b5c5cd1ad24be2656f19113fd2749
3
+ metadata.gz: 38f999acefb3965e6b892798012b79d38fe80aed211c008efbb4f0e7d0d1de11
4
+ data.tar.gz: 6bb113d722f19ce336368e675d3785aee55ee1f63e2e67cc3ff3b681c9de5811
5
5
  SHA512:
6
- metadata.gz: 4777eeb21d3a8a7feb1bd172f23a5fef179456beb2503f20e855f82bd54c9ac06cff90c7d3319b435d6533123d66f28f72a39fb168f37b9897bf0468dbdecced
7
- data.tar.gz: 9c90eac1666e3ff96c0bb58d71928f8fb9283e081f643e80989b19f6e05fe1cde3c86bda6d125a1b4f60c3e1f9b02b83eee17af7a0d91623f0dcacfdc5c023b9
6
+ metadata.gz: 979ca70b0e402b50b7b5a92340d1da20312937e4d9fa7df4bb1dd358e08f68f63a9e973109abb3d5568e5d7e0e4ebef672ed03dbd74d8dc1e992069e1e90bcc1
7
+ data.tar.gz: 990a1f70e3317c05ac0764b4dfe0d28183eae7723f1b599cfaf2bf7ac192226f45a370f9b6ef29e9bfe367427f67fb3a57cec5764d48d4773601856a2cc9bbfa
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/fs_cache'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ class CachedDownload
8
+ attr_reader :url, :fs_cache
9
+
10
+ def initialize(url, parent_fs_cache = nil)
11
+ @url = url
12
+ @fs_cache = (parent_fs_cache || ::Avm.fs_cache).child(url.parameterize)
13
+ end
14
+
15
+ def assert
16
+ download unless fs_cache.cached?
17
+ end
18
+
19
+ def download
20
+ ::EacRubyUtils::Fs::Temp.on_file do |temp|
21
+ download_to(temp)
22
+ fs_cache.content_path.to_pathname.dirname.mkpath
23
+ ::FileUtils.mv(temp.to_path, fs_cache.content_path)
24
+ end
25
+ end
26
+
27
+ def path
28
+ @path ||= fs_cache.content_path.to_pathname
29
+ end
30
+
31
+ private
32
+
33
+ def download_to(local_file)
34
+ ::URI.parse(url).open do |remote|
35
+ local_file.open('wb') { |handle| handle.write(remote.read) }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_redmine_base0/core_update'
4
+ require 'avm/cached_download'
5
+ require 'avm/sync'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module Avm
9
+ module EacRedmineBase0
10
+ class CoreUpdate
11
+ enable_console_speaker
12
+ enable_simple_cache
13
+ common_constructor :instance, :version, :url
14
+
15
+ GITIGNORE_ADD = %w[/public/assets/**/* /config/install.sh /log/**/*].freeze
16
+ GITIGNORE_DEL = %w[/Gemfile.lock /plugins/* /public/themes/*].freeze
17
+ TARGET_KEEP = %w[/Gemfile.lock].freeze
18
+
19
+ def run
20
+ ::EacRubyUtils::Fs::Temp.on_directory do |dir|
21
+ @tempdir = dir
22
+ assert_source_package
23
+ extract_package_to_tempdir
24
+ sync_content
25
+ change_git_ignore
26
+ validate_empty_dir
27
+ end
28
+ git_commit
29
+ success 'Done!'
30
+ end
31
+
32
+ def assert_source_package
33
+ infom 'Asserting source package...'
34
+ source_package.assert
35
+ infov 'Package cache path', source_package.path
36
+ infov 'Package size', source_package.path.size
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :tempdir
42
+
43
+ def change_git_ignore
44
+ file = target_path.join('.gitignore')
45
+ file.write(
46
+ (file.read.each_line.map(&:strip).reject { |line| GITIGNORE_DEL.include?(line) } +
47
+ ['', '#eac_redmine_base0'] + GITIGNORE_ADD).map { |line| "#{line}\n" }.join
48
+ )
49
+ end
50
+
51
+ def extract_package_to_tempdir
52
+ infom "Extracting package to tempdir #{tempdir}..."
53
+ ::EacRubyUtils::Envs.local.command(
54
+ 'tar', '-xf', source_package.path.to_path, '-C', tempdir.to_path,
55
+ '--strip-components', '1'
56
+ ).execute!
57
+ end
58
+
59
+ def git_commit
60
+ if git_repo.dirty?
61
+ infom 'Git commiting...'
62
+ git_repo.command('add', '--', target_path).execute!
63
+ git_repo.command('commit', '-m', git_commit_message, '--', target_path).execute!
64
+ else
65
+ infom 'Nothing to commit'
66
+ end
67
+ end
68
+
69
+ def git_commit_message
70
+ "Core: update to #{version}."
71
+ end
72
+
73
+ def git_repo_uncached
74
+ ::EacGit::Local.new(target_path)
75
+ end
76
+
77
+ def sync_content
78
+ ::Avm::Sync.new(source_path, target_path)
79
+ .add_exclude('/*').add_includes(*target_files_to_remove).move_mode(true).run
80
+ end
81
+
82
+ def source_package_uncached
83
+ ::Avm::CachedDownload.new(url, ::Avm.fs_cache.child('eac_redmine_base0', 'core_update'))
84
+ end
85
+
86
+ def validate_empty_dir
87
+ if source_path.children.empty?
88
+ infom 'No content left in source directory'
89
+ else
90
+ fatal_error 'Found entries in source directory: ' +
91
+ source_path.children.map { |c| c.basename.to_path }.join(', ')
92
+ end
93
+ end
94
+
95
+ def source_path_uncached
96
+ ::Pathname.new(tempdir.to_path)
97
+ end
98
+
99
+ def target_files_to_remove
100
+ git_repo.command('ls-files').execute!
101
+ .each_line.map { |v| "/#{v.strip}" }
102
+ .without(*TARGET_KEEP)
103
+ end
104
+
105
+ def target_path_uncached
106
+ instance.read_entry('fs_path').to_pathname
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/instance/unit'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'open-uri'
6
+
7
+ module Avm
8
+ module EacRedmineBase0
9
+ class DataUnit < ::Avm::Data::Instance::Unit
10
+ common_constructor :instance
11
+
12
+ EXTENSION = '.tar'
13
+
14
+ def do_dump(data_path)
15
+ ::File.open(data_path, 'wb') do |file|
16
+ file << URI.parse(export_url).read
17
+ end
18
+ end
19
+
20
+ def export_url
21
+ uri = ::Addressable::URI.parse(instance.read_entry('web.url')) + '/backup/export'
22
+ uri.query_values = { key: instance.read_entry('admin.api_key') }
23
+ uri.to_s
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/stereotypes/eac_webapp_base0/deploy'
4
+ require 'eac_ruby_utils/ruby'
5
+
6
+ module Avm
7
+ module EacRedmineBase0
8
+ class Deploy < ::Avm::Stereotypes::EacWebappBase0::Deploy
9
+ set_callback :assert_instance_branch, :after, :run_installer
10
+
11
+ def run_installer
12
+ infom 'Running installer'
13
+ ::EacRubyUtils::Ruby.on_clean_environment do
14
+ installer_command.system!
15
+ end
16
+ end
17
+
18
+ def installer_command
19
+ instance.host_env.command(installer_path, install_task)
20
+ end
21
+
22
+ def installer_path
23
+ ::File.join(instance.read_entry(:fs_path), 'plugins', 'redmine_installer', 'installer',
24
+ 'run.sh')
25
+ end
26
+
27
+ def install_task
28
+ if instance.read_entry_optional('web.path').present?
29
+ 'redmine_as_apache_path'
30
+ else
31
+ 'redmine_as_apache_base'
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
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'
6
+ require 'avm/stereotypes/rails/instance'
7
+
8
+ module Avm
9
+ module EacRedmineBase0
10
+ class Instance < ::Avm::Stereotypes::EacWebappBase0::Instance
11
+ include ::Avm::Stereotypes::Rails::Instance
12
+
13
+ FILES_UNITS = { files: 'files' }.freeze
14
+
15
+ def docker_image_class
16
+ ::Avm::Stereotypes::EacUbuntuBase0::DockerImage
17
+ end
18
+
19
+ def docker_run_arguments
20
+ [
21
+ '--volume', "#{read_entry(:fs_path)}:/home/myuser/eac_redmine_base0",
22
+ '--publish', "#{read_entry(:ssh_port)}:22",
23
+ '--publish', "#{read_entry(:http_port)}:80",
24
+ '--publish', "#{read_entry(:https_port)}:443"
25
+ ]
26
+ end
27
+
28
+ def data_package
29
+ @data_package ||= ::Avm::Data::Instance::Package.new(
30
+ self,
31
+ units: {
32
+ all: ::Avm::EacRedmineBase0::DataUnit.new(self)
33
+ }
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
@@ -17,15 +17,23 @@ module Avm
17
17
  internal_find_path(path.expand_path)
18
18
  end
19
19
 
20
- private
21
-
22
- def internal_find_path(absolute_pathname)
20
+ def find_in_path(path)
21
+ absolute_pathname = path.to_pathname.expand_path
23
22
  if absolute_pathname.directory?
24
23
  FILENAMES.each do |filename|
25
24
  file = absolute_pathname.join(filename)
26
25
  return new(file) if file.exist?
27
26
  end
28
27
  end
28
+ nil
29
+ end
30
+
31
+ private
32
+
33
+ def internal_find_path(absolute_pathname)
34
+ r = find_in_path(absolute_pathname)
35
+ return r if r.present?
36
+
29
37
  internal_find_path(absolute_pathname.dirname) unless absolute_pathname.root?
30
38
  end
31
39
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_gems_utils/gem'
3
+ require 'avm/patches/eac_ruby_gems_utils/gem'
4
4
 
5
5
  module Avm
6
6
  module Instances
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_launcher/publish/check_result'
5
+ require('yaml')
6
+
7
+ module Avm
8
+ module Launcher
9
+ class Context
10
+ class InstanceManager
11
+ require_sub __FILE__
12
+ enable_simple_cache
13
+ common_constructor :context
14
+
15
+ def publish_state_set(instance, stereotype_name, check_status)
16
+ data = cached_instances_file_content_uncached
17
+ data[instance.logical] ||= {}
18
+ data[instance.logical][:publish_state] ||= {}
19
+ data[instance.logical][:publish_state][stereotype_name] = check_status
20
+ write_cache_file(data)
21
+ end
22
+
23
+ def pending_instances
24
+ instances.select { |instance| pending_instance?(instance) }
25
+ end
26
+
27
+ private
28
+
29
+ def instances_uncached
30
+ (cached_instances || search_instances).select(&:included?)
31
+ end
32
+
33
+ def search_instances
34
+ cache_instances(::EacLauncher::Context::InstanceDiscovery.new(context).instances)
35
+ end
36
+
37
+ def cached_instances
38
+ return nil if context.recache
39
+ return nil unless cached_instances_file_content
40
+
41
+ CachedInstances.new(self, cached_instances_file_content).instances
42
+ end
43
+
44
+ def cached_instances_file_content_uncached
45
+ r = YAML.load_file(cache_file_path)
46
+ r.is_a?(::Hash) ? r : nil
47
+ rescue Errno::ENOENT
48
+ nil
49
+ end
50
+
51
+ def cache_instances(instances)
52
+ write_cache_file(Hash[instances.map { |i| [i.logical, i.to_h] }])
53
+ instances
54
+ end
55
+
56
+ def write_cache_file(data)
57
+ ::File.write(cache_file_path, data.to_yaml)
58
+ end
59
+
60
+ def cache_file_path
61
+ ::File.join(context.cache_root, 'instances.yml')
62
+ end
63
+
64
+ def pending_instance?(instance)
65
+ data = cached_instances_file_content
66
+ return false unless data[instance.logical]
67
+ return false unless data[instance.logical][:publish_state].is_a?(Hash)
68
+
69
+ data[instance.logical][:publish_state].any? do |_k, v|
70
+ ::EacLauncher::Publish::CheckResult.pending_status?(v)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/launcher/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Launcher
8
+ class Context
9
+ class InstanceManager
10
+ class CachedInstance
11
+ enable_console_speaker
12
+ enable_simple_cache
13
+ common_constructor :cached_instances, :data
14
+
15
+ private
16
+
17
+ def instance_uncached
18
+ ::Avm::Launcher::Instances::Base.instanciate(path, parent_instance)
19
+ rescue ::Avm::Launcher::Errors::NonProject
20
+ warn "Cached instance \"#{data[:logical]}\" not found"
21
+ nil
22
+ end
23
+
24
+ def parent_instance_uncached
25
+ data[:parent]
26
+ .if_present { |v| cached_instances.by_logical_path(v) }
27
+ .if_present(&:instance)
28
+ end
29
+
30
+ def path_uncached
31
+ ::EacLauncher::Paths::Logical.from_h(cached_instances.context, data)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/launcher/context/instance_manager/cached_instance'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Launcher
8
+ class Context
9
+ class InstanceManager
10
+ class CachedInstances
11
+ enable_simple_cache
12
+ common_constructor :context, :content
13
+
14
+ def instances
15
+ content.keys.map { |k| by_logical_path(k).instance }.reject(&:blank?)
16
+ end
17
+
18
+ def by_logical_path(key)
19
+ cached_instances[key].if_blank do
20
+ cached_instances[key] = ::Avm::Launcher::Context::InstanceManager::CachedInstance.new(
21
+ self, content.fetch(key)
22
+ )
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def cached_instances_uncached
29
+ {}
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end