avm-tools 0.61.0 → 0.62.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '039f5b3b40307ddabe21c292a6f2fb1accf902dee691dac160648f9b305d094a'
4
- data.tar.gz: f3a4993ab7abf9d0d5ae0a75196532460a4b5c5cd1ad24be2656f19113fd2749
3
+ metadata.gz: 37ce02b35f53298066d48205ff8442084a1d702baecb901c91ba3dffe5d2cd0d
4
+ data.tar.gz: f4bf6b545744791267fdbdc0eb47f4dc1f0d6b5c1ebef912dd1cbaa8c06b6bfe
5
5
  SHA512:
6
- metadata.gz: 4777eeb21d3a8a7feb1bd172f23a5fef179456beb2503f20e855f82bd54c9ac06cff90c7d3319b435d6533123d66f28f72a39fb168f37b9897bf0468dbdecced
7
- data.tar.gz: 9c90eac1666e3ff96c0bb58d71928f8fb9283e081f643e80989b19f6e05fe1cde3c86bda6d125a1b4f60c3e1f9b02b83eee17af7a0d91623f0dcacfdc5c023b9
6
+ metadata.gz: a2c271e9d1e95373e7957b55d26b3ffc87b227e1fe4a4d90d94b686e16d4bbf90e40e9be639ab4ea2063698aa42d5e43284472e5e271e3d8e55d4a68acc2e5e3
7
+ data.tar.gz: 58d5924ed8c0e329292240d866b7c567bd1eec97f1774d4ef8573fa4d77b09477a07aa6c90e4ae99806f235af4892d752653667d5d9de7dc3806dee507d2a774
@@ -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,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ class Sync
7
+ attr_reader :excludes, :includes
8
+
9
+ common_constructor :source_path, :target_path do
10
+ self.source_path = source_path.to_pathname
11
+ self.target_path = target_path.to_pathname
12
+ @excludes = []
13
+ @includes = []
14
+ end
15
+
16
+ def run
17
+ clear_target
18
+ copy
19
+ end
20
+
21
+ def add_exclude(exclude)
22
+ excludes << exclude
23
+
24
+ self
25
+ end
26
+
27
+ def add_excludes(*excludes)
28
+ excludes.each { |exclude| add_exclude(exclude) }
29
+
30
+ self
31
+ end
32
+
33
+ def add_include(include)
34
+ includes << include
35
+
36
+ self
37
+ end
38
+
39
+ def add_includes(*includes)
40
+ includes.each { |include| add_include(include) }
41
+
42
+ self
43
+ end
44
+
45
+ def move_mode(value)
46
+ @move_mode = value
47
+
48
+ self
49
+ end
50
+
51
+ def move_mode?
52
+ @move_mode ? true : false
53
+ end
54
+
55
+ private
56
+
57
+ def clear_target
58
+ target_remove(target_path)
59
+ target_path.children.each { |tchild| target_remove(tchild) }
60
+ end
61
+
62
+ def copy
63
+ source_path.children.each do |schild|
64
+ ::FileUtils.cp_r(schild.to_path, target_path.to_path)
65
+ schild.rmtree if move_mode?
66
+ end
67
+ end
68
+
69
+ def source_to_target_path(source_path)
70
+ source_path.relative_path_from(self.source_path).expand_path(target_path)
71
+ end
72
+
73
+ def target_remove(tpath)
74
+ return if skip_target_path?(tpath)
75
+
76
+ if tpath.directory?
77
+ tpath.children.each { |tchild| target_remove(tchild) }
78
+ tpath.rmdir if tpath.children.empty?
79
+ elsif tpath.file?
80
+ tpath.unlink
81
+ end
82
+ end
83
+
84
+ def skip_target_path?(tpath)
85
+ skip_path?(tpath.relative_path_from(target_path))
86
+ end
87
+
88
+ def skip_path?(relpath)
89
+ relpath = relpath.expand_path('/')
90
+ excludes.any? { |exclude| relpath.fnmatch?(exclude) } &&
91
+ includes.none? { |include| relpath.fnmatch?(include) }
92
+ end
93
+ end
94
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'eac_ruby_utils/console/docopt_runner'
4
4
  require 'eac_ruby_utils/simple_cache'
5
- require 'avm/stereotypes/eac_redmine_base0/instance'
5
+ require 'avm/eac_redmine_base0/instance'
6
6
  require 'eac_ruby_utils/require_sub'
7
7
  ::EacRubyUtils.require_sub(__FILE__)
8
8
 
@@ -26,7 +26,7 @@ module Avm
26
26
  private
27
27
 
28
28
  def instance_uncached
29
- ::Avm::Stereotypes::EacRedmineBase0::Instance.by_id(options['<instance_id>'])
29
+ ::Avm::EacRedmineBase0::Instance.by_id(options['<instance_id>'])
30
30
  end
31
31
  end
32
32
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_redmine_base0/core_update'
4
+ require 'eac_cli/default_runner'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module Avm
9
+ module Tools
10
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
11
+ class EacRedmineBase0 < ::EacRubyUtils::Console::DocoptRunner
12
+ class CoreUpdate < ::EacRubyUtils::Console::DocoptRunner
13
+ include ::EacCli::DefaultRunner
14
+
15
+ runner_definition do
16
+ arg_opt '-u', '--url', 'Core\'s package URL.'
17
+ arg_opt '-v', '--version', 'Core\'s version.'
18
+ desc 'Update instance\' core.'
19
+ end
20
+
21
+ def run
22
+ start_banner
23
+ validate
24
+ update
25
+ end
26
+
27
+ private
28
+
29
+ def start_banner
30
+ infov 'URL', url
31
+ infov 'Version', version
32
+ end
33
+
34
+ def update
35
+ ::Avm::EacRedmineBase0::CoreUpdate.new(context(:instance), version, url).run
36
+ end
37
+
38
+ def url
39
+ options.fetch('--url') || url_by_version
40
+ end
41
+
42
+ def url_by_version
43
+ options.fetch('--version').if_present do |v|
44
+ "https://www.redmine.org/releases/redmine-#{v}.tar.gz"
45
+ end
46
+ end
47
+
48
+ def validate
49
+ %w[url version].each do |attr|
50
+ fatal_error "\"#{attr}\" is blank. See avaiable options." if send(attr).blank?
51
+ end
52
+ end
53
+
54
+ def version
55
+ options.fetch('--version') || version_by_url
56
+ end
57
+
58
+ def version_by_url
59
+ options.fetch('--url').if_present do |v|
60
+ /(\d+.\d+.\d+)/.if_match(v, false) { |m| m[1] }
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/stereotypes/eac_redmine_base0/deploy'
3
+ require 'avm/eac_redmine_base0/deploy'
4
4
  require 'avm/stereotypes/eac_webapp_base0/runner/deploy'
5
5
 
6
6
  module Avm
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.61.0'
5
+ VERSION = '0.62.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.61.0
4
+ version: 0.62.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-26 00:00:00.000000000 Z
11
+ date: 2020-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -274,6 +274,7 @@ files:
274
274
  - Gemfile
275
275
  - exe/avm
276
276
  - lib/avm.rb
277
+ - lib/avm/cached_download.rb
277
278
  - lib/avm/configs.rb
278
279
  - lib/avm/data.rb
279
280
  - lib/avm/data/instance.rb
@@ -289,6 +290,10 @@ files:
289
290
  - lib/avm/docker/image.rb
290
291
  - lib/avm/docker/registry.rb
291
292
  - lib/avm/docker/runner.rb
293
+ - lib/avm/eac_redmine_base0/core_update.rb
294
+ - lib/avm/eac_redmine_base0/data_unit.rb
295
+ - lib/avm/eac_redmine_base0/deploy.rb
296
+ - lib/avm/eac_redmine_base0/instance.rb
292
297
  - lib/avm/executables.rb
293
298
  - lib/avm/files.rb
294
299
  - lib/avm/files/formatter.rb
@@ -405,9 +410,6 @@ files:
405
410
  - lib/avm/stereotypes/eac_rails_base0/deploy.rb
406
411
  - lib/avm/stereotypes/eac_rails_base0/instance.rb
407
412
  - lib/avm/stereotypes/eac_redmine_base0.rb
408
- - lib/avm/stereotypes/eac_redmine_base0/data_unit.rb
409
- - lib/avm/stereotypes/eac_redmine_base0/deploy.rb
410
- - lib/avm/stereotypes/eac_redmine_base0/instance.rb
411
413
  - lib/avm/stereotypes/eac_ubuntu_base0.rb
412
414
  - lib/avm/stereotypes/eac_ubuntu_base0/apache.rb
413
415
  - lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb
@@ -433,6 +435,7 @@ files:
433
435
  - lib/avm/stereotypes/postgresql/instance_with.rb
434
436
  - lib/avm/stereotypes/rails.rb
435
437
  - lib/avm/stereotypes/rails/instance.rb
438
+ - lib/avm/sync.rb
436
439
  - lib/avm/tools.rb
437
440
  - lib/avm/tools/runner.rb
438
441
  - lib/avm/tools/runner/eac_rails_base0.rb
@@ -443,6 +446,7 @@ files:
443
446
  - lib/avm/tools/runner/eac_rails_base0/runner.rb
444
447
  - lib/avm/tools/runner/eac_redmine_base0.rb
445
448
  - lib/avm/tools/runner/eac_redmine_base0/bundle.rb
449
+ - lib/avm/tools/runner/eac_redmine_base0/core_update.rb
446
450
  - lib/avm/tools/runner/eac_redmine_base0/data.rb
447
451
  - lib/avm/tools/runner/eac_redmine_base0/data/dump.rb
448
452
  - lib/avm/tools/runner/eac_redmine_base0/deploy.rb
@@ -966,7 +970,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
966
970
  - !ruby/object:Gem::Version
967
971
  version: '0'
968
972
  requirements: []
969
- rubygems_version: 3.0.6
973
+ rubygems_version: 3.0.8
970
974
  signing_key:
971
975
  specification_version: 4
972
976
  summary: Tools for AVM.
@@ -1,29 +0,0 @@
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 Stereotypes
9
- module EacRedmineBase0
10
- class DataUnit < ::Avm::Data::Instance::Unit
11
- common_constructor :instance
12
-
13
- EXTENSION = '.tar'
14
-
15
- def do_dump(data_path)
16
- ::File.open(data_path, 'wb') do |file|
17
- file << URI.parse(export_url).read
18
- end
19
- end
20
-
21
- def export_url
22
- uri = ::Addressable::URI.parse(instance.read_entry('web.url')) + '/backup/export'
23
- uri.query_values = { key: instance.read_entry('admin.api_key') }
24
- uri.to_s
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,38 +0,0 @@
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 Stereotypes
8
- module EacRedmineBase0
9
- class Deploy < ::Avm::Stereotypes::EacWebappBase0::Deploy
10
- set_callback :assert_instance_branch, :after, :run_installer
11
-
12
- def run_installer
13
- infom 'Running installer'
14
- ::EacRubyUtils::Ruby.on_clean_environment do
15
- installer_command.system!
16
- end
17
- end
18
-
19
- def installer_command
20
- instance.host_env.command(installer_path, install_task)
21
- end
22
-
23
- def installer_path
24
- ::File.join(instance.read_entry(:fs_path), 'plugins', 'redmine_installer', 'installer',
25
- 'run.sh')
26
- end
27
-
28
- def install_task
29
- if instance.read_entry_optional('web.path').present?
30
- 'redmine_as_apache_path'
31
- else
32
- 'redmine_as_apache_base'
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/stereotypes/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 Stereotypes
10
- module EacRedmineBase0
11
- class Instance < ::Avm::Stereotypes::EacWebappBase0::Instance
12
- include ::Avm::Stereotypes::Rails::Instance
13
-
14
- FILES_UNITS = { files: 'files' }.freeze
15
-
16
- def docker_image_class
17
- ::Avm::Stereotypes::EacUbuntuBase0::DockerImage
18
- end
19
-
20
- def docker_run_arguments
21
- [
22
- '--volume', "#{read_entry(:fs_path)}:/home/myuser/eac_redmine_base0",
23
- '--publish', "#{read_entry(:ssh_port)}:22",
24
- '--publish', "#{read_entry(:http_port)}:80",
25
- '--publish', "#{read_entry(:https_port)}:443"
26
- ]
27
- end
28
-
29
- def data_package
30
- @data_package ||= ::Avm::Data::Instance::Package.new(
31
- self,
32
- units: {
33
- all: ::Avm::Stereotypes::EacRedmineBase0::DataUnit.new(self)
34
- }
35
- )
36
- end
37
- end
38
- end
39
- end
40
- end