avm-tools 0.60.0 → 0.62.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) 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/launcher/context/instance_manager.rb +76 -0
  8. data/lib/avm/launcher/context/instance_manager/cached_instance.rb +37 -0
  9. data/lib/avm/launcher/context/instance_manager/cached_instances.rb +35 -0
  10. data/lib/avm/launcher/errors/base.rb +10 -0
  11. data/lib/avm/launcher/errors/non_project.rb +15 -0
  12. data/lib/avm/launcher/instances/base.rb +94 -0
  13. data/lib/avm/launcher/instances/base/cache.rb +43 -0
  14. data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +5 -4
  15. data/lib/avm/stereotypes/eac_webapp_base0/runner/deploy.rb +3 -1
  16. data/lib/avm/sync.rb +94 -0
  17. data/lib/avm/tools/runner/eac_redmine_base0.rb +2 -2
  18. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +67 -0
  19. data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +1 -1
  20. data/lib/avm/tools/runner/git/issue.rb +43 -4
  21. data/lib/avm/tools/version.rb +1 -1
  22. data/lib/eac_launcher/context.rb +2 -2
  23. data/lib/eac_launcher/context/instance_discovery.rb +2 -2
  24. data/lib/eac_launcher/git/base/dirty_files.rb +1 -1
  25. data/lib/eac_launcher/git/sub_warp_base.rb +3 -2
  26. data/lib/eac_launcher/instances.rb +2 -2
  27. data/lib/eac_launcher/instances/error.rb +7 -3
  28. data/lib/eac_launcher/paths/logical.rb +2 -2
  29. data/lib/eac_launcher/publish/base.rb +2 -2
  30. data/template/avm/{stereotypes/eac_redmine_base0 → eac_redmine_base0}/deploy/config/install.sh.template +0 -0
  31. data/template/avm/{stereotypes/eac_redmine_base0 → eac_redmine_base0}/deploy/config/secrets.yml +0 -0
  32. metadata +19 -11
  33. data/lib/avm/stereotypes/eac_redmine_base0/data_unit.rb +0 -29
  34. data/lib/avm/stereotypes/eac_redmine_base0/deploy.rb +0 -38
  35. data/lib/avm/stereotypes/eac_redmine_base0/instance.rb +0 -40
  36. data/lib/eac_launcher/context/instance_manager.rb +0 -95
  37. data/lib/eac_launcher/instances/base.rb +0 -91
  38. 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: 3a03f7f27fdfdd821203ba28f951ca16404a91b886453f9839e855dcf78627ef
4
- data.tar.gz: 8f02cc5b2e5454e4e5253be317e73c94d8f007538b3464281f9a84c1bd83768f
3
+ metadata.gz: 373072ac50452efe90c4a8408828dff28b48209d5a387709d89972678ab92e21
4
+ data.tar.gz: 2f09de5ac81af5bc0992c6c3facb97e908001deffcd5d0f17492fc0258aa415c
5
5
  SHA512:
6
- metadata.gz: dd7d158d5b73aea3e54c715b2a13ec15fa3bc5fd6f87b3252f70ae9b0fd8dce36fb3a6b9c1d043f0b2365087848627595aaf7041142bf27f18d60a3f1ac4e0a9
7
- data.tar.gz: a8300831601639f79484dcd81934900c4be5003e85ed4e5a6345bb0c19ea5f4b3149556633238bd63fff97c933df7535622bfe588021c06e0567a064ccaca7e2
6
+ metadata.gz: 7a9f83824449276c9fedbd9d7ef07aa8e124f8de1d948c477bb9734c57cfbffef29b1416e249edc5de11e5a23ee9d02c982a9e80d6b9a40b9f9b5a011807d27b
7
+ data.tar.gz: 5a09becd99a994a50fa875ae2566262c461d3f9bd6557b670c8a1e81d59768f736e59bbad5cbea127efb4ae6476d7104347169b13958c0d15dde5a158e41a5de
@@ -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
@@ -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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Launcher
5
+ module Errors
6
+ class Base < ::StandardError
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/launcher/errors/base'
4
+
5
+ module Avm
6
+ module Launcher
7
+ module Errors
8
+ class NonProject < ::Avm::Launcher::Errors::Base
9
+ def initialize(path)
10
+ super("#{path} is not a project")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end