eac_tools 0.30.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (21) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +6 -6
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +2 -2
  5. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/{apache_host.rb → instances/apache_host.rb} +3 -1
  6. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb +6 -5
  7. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/data_unit.rb +53 -0
  8. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/{rest_api.rb → instances/rest_api.rb} +3 -1
  9. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project_rename.rb +1 -1
  10. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/runners/base.rb +1 -1
  11. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/core_update.rb +120 -0
  12. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/core_update.rb +3 -2
  13. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
  14. data/sub/avm-eac_redmine_base0/spec/lib/avm/eac_redmine_base0/instances/apache_host_spec.rb +22 -0
  15. data/sub/avm-eac_redmine_base0/spec/lib/avm/eac_redmine_base0/instances/apache_host_spec_files/apache_host_spec_no_ssl_content.conf +11 -0
  16. data/sub/avm-eac_redmine_base0/spec/spec_helper.rb +1 -0
  17. data/sub/avm-files/lib/avm/files/text_replacer.rb +1 -1
  18. data/sub/avm-files/lib/avm/files/version.rb +1 -1
  19. metadata +10 -8
  20. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/core_update.rb +0 -118
  21. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/data_unit.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc1385a1932c7e4a6b89b66db8ea6084663a9c690571b00ca73465b47421ddd2
4
- data.tar.gz: 7dd2dab5f79240a7b8087532ee959accaf130ac12f4c6d9745b86a0ab85efd5f
3
+ metadata.gz: 4ca7fa87db2c97ecf60dc93100760491b936f91d3d979a38953bbf2f1c9c964a
4
+ data.tar.gz: ce07adf422abd3a143defcd747de05d527a605934dce9300bf8cf48b46195dc8
5
5
  SHA512:
6
- metadata.gz: 6b28b72f7c1eafb7ca609ab9b0450cc07254316756668ae980af135710fa01dcd364d18bc403c2912b50dd1c3e6c5832f220c59aa8aaac7b2366436801aebb4a
7
- data.tar.gz: e6fcad611277f1d36707f180da96fed11a25a98139e5cc889bb5aa3e5728d42d3a9fa4667d70f1055fdff114291dbc364b099d4fb72615696d6d6be1e19a05fc
6
+ metadata.gz: 813cd67c73235bd826df76db57fc0711fd4a176a2ac601111cd3f5359a68d6c05ceeff179c4311f2ec51d5f8d4b79ce6e6413242e93b44a07507e9f87407f726
7
+ data.tar.gz: 2e8042ef0bf14c1bc656f9735f978364ad51bf18c0330b0edd73f88ff75f078f37e48d39aeb9a498d72aee87af8e1662aefee29ba98db930a33b37041860b9ee
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eac_tools (0.30.0)
4
+ eac_tools (0.31.0)
5
5
  avm (~> 0.43)
6
6
  avm-eac_asciidoctor_base0 (~> 0.7)
7
7
  avm-eac_generic_base0 (~> 0.5)
8
8
  avm-eac_latex_base0 (~> 0.2)
9
9
  avm-eac_rails_base0 (~> 0.8)
10
10
  avm-eac_rails_base1 (~> 0.6)
11
- avm-eac_redmine_base0 (~> 0.14)
11
+ avm-eac_redmine_base0 (~> 0.15)
12
12
  avm-eac_redmine_plugin_base0 (~> 0.3)
13
13
  avm-eac_ruby_base1 (~> 0.21)
14
14
  avm-eac_webapp_base0 (~> 0.8)
@@ -60,15 +60,15 @@ PATH
60
60
  PATH
61
61
  remote: sub/avm-eac_redmine_base0
62
62
  specs:
63
- avm-eac_redmine_base0 (0.14.0)
64
- avm (~> 0.41)
63
+ avm-eac_redmine_base0 (0.15.0)
64
+ avm (~> 0.43)
65
65
  avm-eac_generic_base0 (~> 0.5)
66
66
  avm-eac_rails_base1 (~> 0.6)
67
67
  avm-eac_ubuntu_base0 (~> 0.3)
68
68
  curb (~> 0.9, >= 0.9.11)
69
69
  eac_fs (~> 0.12, >= 0.12.3)
70
70
  eac_rest (~> 0.6, >= 0.6.1)
71
- eac_ruby_utils (~> 0.102)
71
+ eac_ruby_utils (~> 0.103)
72
72
 
73
73
  PATH
74
74
  remote: sub/avm-eac_redmine_plugin_base0
@@ -106,7 +106,7 @@ PATH
106
106
  PATH
107
107
  remote: sub/avm-files
108
108
  specs:
109
- avm-files (0.4.0)
109
+ avm-files (0.4.1)
110
110
  avm (~> 0.43)
111
111
  eac_cli (~> 0.28)
112
112
  eac_fs (~> 0.12, >= 0.12.3)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacTools
4
- VERSION = '0.30.0'
4
+ VERSION = '0.31.0'
5
5
  end
@@ -12,14 +12,14 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,locale,template}/**/*']
14
14
 
15
- s.add_dependency 'avm', '~> 0.41'
15
+ s.add_dependency 'avm', '~> 0.43'
16
16
  s.add_dependency 'avm-eac_generic_base0', '~> 0.5'
17
17
  s.add_dependency 'avm-eac_rails_base1', '~> 0.6'
18
18
  s.add_dependency 'avm-eac_ubuntu_base0', '~> 0.3'
19
19
  s.add_dependency 'curb', '~> 0.9', '>= 0.9.11'
20
20
  s.add_dependency 'eac_fs', '~> 0.12', '>= 0.12.3'
21
21
  s.add_dependency 'eac_rest', '~> 0.6', '>= 0.6.1'
22
- s.add_dependency 'eac_ruby_utils', '~> 0.102'
22
+ s.add_dependency 'eac_ruby_utils', '~> 0.103'
23
23
 
24
24
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
25
25
  end
@@ -4,7 +4,9 @@ require 'avm/eac_rails_base1/apache_host'
4
4
 
5
5
  module Avm
6
6
  module EacRedmineBase0
7
- class ApacheHost < ::Avm::EacRailsBase1::ApacheHost
7
+ module Instances
8
+ class ApacheHost < ::Avm::EacRailsBase1::ApacheHost
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'addressable/uri'
4
- require 'avm/eac_redmine_base0/data_unit'
4
+ require 'avm/eac_redmine_base0/instances/data_unit'
5
5
  require 'avm/eac_redmine_base0/instances/docker_image'
6
- require 'avm/eac_redmine_base0/rest_api'
6
+ require 'avm/eac_redmine_base0/instances/runners'
7
+ require 'avm/eac_redmine_base0/instances/rest_api'
7
8
  require 'avm/eac_rails_base1/instances/base'
8
9
 
9
10
  module Avm
@@ -32,7 +33,7 @@ module Avm
32
33
  @data_package ||= ::Avm::Data::Instance::Package.new(
33
34
  self,
34
35
  units: {
35
- all: ::Avm::EacRedmineBase0::DataUnit.new(self)
36
+ all: ::Avm::EacRedmineBase0::Instances::DataUnit.new(self)
36
37
  }
37
38
  )
38
39
  end
@@ -46,11 +47,11 @@ module Avm
46
47
 
47
48
  private
48
49
 
49
- # @return [Avm::EacRedmineBase0::RestApi]
50
+ # @return [Avm::EacRedmineBase0::Instances::RestApi]
50
51
  def rest_api_uncached
51
52
  url = root_url
52
53
  url.query_values = { key: read_entry('api.key') }
53
- ::Avm::EacRedmineBase0::RestApi.new(url)
54
+ ::Avm::EacRedmineBase0::Instances::RestApi.new(url)
54
55
  end
55
56
  end
56
57
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/instance/unit'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'curb'
6
+ require 'open-uri'
7
+
8
+ module Avm
9
+ module EacRedmineBase0
10
+ module Instances
11
+ class DataUnit < ::Avm::Data::Instance::Unit
12
+ common_constructor :instance
13
+
14
+ EXPORT_PATH = '/backup/export'
15
+ EXTENSION = '.tar'
16
+ IMPORT_PATH = '/backup/import.json'
17
+
18
+ def do_dump(data_path)
19
+ ::File.open(data_path, 'wb') do |file|
20
+ file << export_request.response.body_data_or_raise
21
+ end
22
+ end
23
+
24
+ def do_load(data_path)
25
+ do_load_by_web(data_path) || do_load_by_rake(data_path) || raise('Failed to load')
26
+ end
27
+
28
+ def do_load_by_web(data_path)
29
+ c = Curl::Easy.new(import_url)
30
+ c.multipart_form_post = true
31
+ c.http_post(Curl::PostField.file('redmine_with_git_tableless_load[path]', data_path))
32
+ c.perform
33
+ true
34
+ rescue Curl::Err::ConnectionFailedError
35
+ false
36
+ end
37
+
38
+ def do_load_by_rake(data_path)
39
+ instance.bundle('exec', 'rake', "redmine_with_git:load:all[#{data_path}]").system
40
+ true
41
+ end
42
+
43
+ def export_request
44
+ instance.rest_api.request(EXPORT_PATH)
45
+ end
46
+
47
+ def import_url
48
+ instance.rest_api.build_service_url(IMPORT_PATH).to_s
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -5,7 +5,9 @@ require 'eac_rest/api'
5
5
 
6
6
  module Avm
7
7
  module EacRedmineBase0
8
- class RestApi < ::EacRest::Api
8
+ module Instances
9
+ class RestApi < ::EacRest::Api
10
+ end
9
11
  end
10
12
  end
11
13
  end
@@ -8,7 +8,7 @@ module Avm
8
8
  module Instances
9
9
  module Runners
10
10
  class ProjectRename
11
- runner_with ::Avm::EacRailsBase1::RunnerWith::Bundle do
11
+ runner_with :help, ::Avm::EacRailsBase1::RunnerWith::Bundle do
12
12
  pos_arg :from
13
13
  pos_arg :to
14
14
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'avm/eac_redmine_base0/instances/base'
4
4
  require 'avm/eac_redmine_base0/instances/deploy'
5
- require 'avm/eac_redmine_base0/apache_host'
5
+ require 'avm/eac_redmine_base0/instances/apache_host'
6
6
  require 'avm/eac_rails_base1/runner'
7
7
  require 'eac_ruby_utils/core_ext'
8
8
 
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_redmine_base0/sources/core_update'
4
+ require 'avm/sources/base/configuration'
5
+ require 'avm/sync'
6
+ require 'eac_fs/cached_download'
7
+ require 'eac_ruby_utils/core_ext'
8
+
9
+ module Avm
10
+ module EacRedmineBase0
11
+ module Sources
12
+ class CoreUpdate
13
+ enable_speaker
14
+ enable_simple_cache
15
+ common_constructor :source, :version, :url
16
+
17
+ GITIGNORE_ADD = %w[/public/assets/**/* /config/install.sh /config/secrets_key.txt
18
+ /log/**/*].freeze
19
+ GITIGNORE_DEL = %w[/Gemfile.lock /plugins/* /public/themes/*].freeze
20
+ TARGET_KEEP = ::Avm::Sources::Base::Configuration::CONFIGURATION_FILENAMES
21
+ .map { |b| "/#{b}" } + %w[/Gemfile.lock].freeze
22
+
23
+ def run
24
+ ::EacRubyUtils::Fs::Temp.on_directory do |dir|
25
+ @tempdir = dir
26
+ assert_source_package
27
+ extract_package_to_tempdir
28
+ sync_content
29
+ change_git_ignore
30
+ validate_empty_dir
31
+ end
32
+ git_commit
33
+ success 'Done!'
34
+ end
35
+
36
+ def assert_source_package
37
+ infom 'Asserting source package...'
38
+ source_package.assert
39
+ infov 'Package cache path', source_package.path
40
+ infov 'Package size', source_package.path.size
41
+ end
42
+
43
+ def fs_object_id
44
+ [source.path, version].join('_').variableize
45
+ end
46
+
47
+ private
48
+
49
+ attr_reader :tempdir
50
+
51
+ def change_git_ignore
52
+ file = target_path.join('.gitignore')
53
+ file.write(
54
+ (file.read.each_line.map(&:strip).reject { |line| GITIGNORE_DEL.include?(line) } +
55
+ ['', '#eac_redmine_base0'] + GITIGNORE_ADD).map { |line| "#{line}\n" }.join
56
+ )
57
+ end
58
+
59
+ def extract_package_to_tempdir
60
+ infom "Extracting package to tempdir #{tempdir}..."
61
+ ::EacRubyUtils::Envs.local.command(
62
+ 'tar', '-xf', source_package.path.to_path, '-C', tempdir.to_path,
63
+ '--strip-components', '1'
64
+ ).execute!
65
+ end
66
+
67
+ def git_commit
68
+ if git_repo.dirty?
69
+ infom 'Git commiting...'
70
+ git_repo.command('add', '--', target_path).execute!
71
+ git_repo.command('commit', '-m', git_commit_message, '--', target_path).execute!
72
+ else
73
+ infom 'Nothing to commit'
74
+ end
75
+ end
76
+
77
+ def git_commit_message
78
+ i18n_translate(__method__, version: version, __locale: source.locale)
79
+ end
80
+
81
+ def git_repo_uncached
82
+ ::EacGit::Local.new(target_path)
83
+ end
84
+
85
+ def sync_content
86
+ ::Avm::Sync.new(source_path, target_path)
87
+ .add_exclude('/*').add_includes(*target_files_to_remove).move_mode(true).run
88
+ end
89
+
90
+ # @return [EacFs::CachedDownload]
91
+ def source_package_uncached
92
+ ::EacFs::CachedDownload.new(url, fs_cache)
93
+ end
94
+
95
+ def validate_empty_dir
96
+ if source_path.children.empty?
97
+ infom 'No content left in source directory'
98
+ else
99
+ fatal_error 'Found entries in source directory: ' +
100
+ source_path.children.map { |c| c.basename.to_path }.join(', ')
101
+ end
102
+ end
103
+
104
+ def source_path_uncached
105
+ ::Pathname.new(tempdir.to_path)
106
+ end
107
+
108
+ def target_files_to_remove
109
+ git_repo.command('ls-files').execute!
110
+ .each_line.map { |v| "/#{v.strip}" }
111
+ .without(*TARGET_KEEP)
112
+ end
113
+
114
+ def target_path_uncached
115
+ source.path
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/eac_rails_base1/sources/base'
4
- require 'avm/eac_redmine_base0/core_update'
4
+ require 'avm/eac_redmine_base0/sources/core_update'
5
5
  require 'eac_cli/core_ext'
6
6
 
7
7
  module Avm
@@ -29,7 +29,8 @@ module Avm
29
29
  end
30
30
 
31
31
  def update
32
- ::Avm::EacRedmineBase0::CoreUpdate.new(runner_context.call(:subject), version, url).run
32
+ ::Avm::EacRedmineBase0::Sources::CoreUpdate
33
+ .new(runner_context.call(:subject), version, url).run
33
34
  end
34
35
 
35
36
  def url
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacRedmineBase0
5
- VERSION = '0.14.0'
5
+ VERSION = '0.15.0'
6
6
  end
7
7
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_redmine_base0/instances/apache_host'
4
+ require 'avm/eac_redmine_base0/instances/base'
5
+
6
+ RSpec.describe ::Avm::EacRedmineBase0::Instances::ApacheHost do
7
+ describe '#no_ssl_site_content' do
8
+ let(:instance) { ::Avm::EacRedmineBase0::Instances::Base.by_id('stub-app_0') }
9
+ let(:apache_host) { described_class.new(instance) }
10
+ let(:fixtures_dir) { ::Pathname.new('apache_host_spec_files').expand_path(__dir__) }
11
+ let(:expected_content) { fixtures_dir.join('apache_host_spec_no_ssl_content.conf').read }
12
+
13
+ before do
14
+ instance.entry('install.path').write('/path/to/stub-app_0')
15
+ instance.entry('web.url').write('http://stubapp.net')
16
+ end
17
+
18
+ it do
19
+ expect(apache_host.no_ssl_site_content).to eq(expected_content)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ <VirtualHost *:80>
2
+ ServerName "stubapp.net"
3
+ DocumentRoot "/path/to/stub-app_0/public"
4
+ PassengerEnabled On
5
+
6
+ <Directory "/path/to/stub-app_0/public">
7
+ Allow from all
8
+ Options -MultiViews
9
+ Require all granted
10
+ </Directory>
11
+ </VirtualHost>
@@ -2,3 +2,4 @@
2
2
 
3
3
  require 'eac_ruby_utils/rspec/default_setup'
4
4
  ::EacRubyUtils::Rspec.default_setup_create(::File.expand_path('..', __dir__))
5
+ ::EacRubyUtils::Rspec.default_setup.stub_eac_config_node
@@ -25,7 +25,7 @@ module Avm
25
25
  end
26
26
 
27
27
  def gsub(from, to)
28
- replacement(::Avm::TextReplacer::Gsub.new(from, to))
28
+ replacement(::Avm::Files::TextReplacer::Gsub.new(from, to))
29
29
  end
30
30
  end
31
31
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Files
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.0
4
+ version: 0.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-14 00:00:00.000000000 Z
11
+ date: 2022-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.14'
103
+ version: '0.15'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.14'
110
+ version: '0.15'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: avm-eac_redmine_plugin_base0
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -369,27 +369,29 @@ files:
369
369
  - sub/avm-eac_redmine_base0/Gemfile
370
370
  - sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec
371
371
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0.rb
372
- - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/apache_host.rb
373
- - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/core_update.rb
374
- - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/data_unit.rb
375
372
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances.rb
373
+ - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/apache_host.rb
376
374
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb
375
+ - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/data_unit.rb
377
376
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/deploy.rb
378
377
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/docker_image.rb
378
+ - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api.rb
379
379
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners.rb
380
380
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/docker.rb
381
381
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project_rename.rb
382
- - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/rest_api.rb
383
382
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/runners.rb
384
383
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/runners/base.rb
385
384
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources.rb
386
385
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/base.rb
386
+ - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/core_update.rb
387
387
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners.rb
388
388
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/core_update.rb
389
389
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/docker.rb
390
390
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb
391
391
  - sub/avm-eac_redmine_base0/locale/en.yml
392
392
  - sub/avm-eac_redmine_base0/locale/pt-BR.yml
393
+ - sub/avm-eac_redmine_base0/spec/lib/avm/eac_redmine_base0/instances/apache_host_spec.rb
394
+ - sub/avm-eac_redmine_base0/spec/lib/avm/eac_redmine_base0/instances/apache_host_spec_files/apache_host_spec_no_ssl_content.conf
393
395
  - sub/avm-eac_redmine_base0/spec/rubocop_spec.rb
394
396
  - sub/avm-eac_redmine_base0/spec/spec_helper.rb
395
397
  - sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/instances/deploy/config/install.sh.template
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/eac_redmine_base0/core_update'
4
- require 'avm/sources/base/configuration'
5
- require 'avm/sync'
6
- require 'eac_fs/cached_download'
7
- require 'eac_ruby_utils/core_ext'
8
-
9
- module Avm
10
- module EacRedmineBase0
11
- class CoreUpdate
12
- enable_speaker
13
- enable_simple_cache
14
- common_constructor :source, :version, :url
15
-
16
- GITIGNORE_ADD = %w[/public/assets/**/* /config/install.sh /config/secrets_key.txt
17
- /log/**/*].freeze
18
- GITIGNORE_DEL = %w[/Gemfile.lock /plugins/* /public/themes/*].freeze
19
- TARGET_KEEP = ::Avm::Sources::Base::Configuration::CONFIGURATION_FILENAMES
20
- .map { |b| "/#{b}" } + %w[/Gemfile.lock].freeze
21
-
22
- def run
23
- ::EacRubyUtils::Fs::Temp.on_directory do |dir|
24
- @tempdir = dir
25
- assert_source_package
26
- extract_package_to_tempdir
27
- sync_content
28
- change_git_ignore
29
- validate_empty_dir
30
- end
31
- git_commit
32
- success 'Done!'
33
- end
34
-
35
- def assert_source_package
36
- infom 'Asserting source package...'
37
- source_package.assert
38
- infov 'Package cache path', source_package.path
39
- infov 'Package size', source_package.path.size
40
- end
41
-
42
- def fs_object_id
43
- [source.path, version].join('_').variableize
44
- end
45
-
46
- private
47
-
48
- attr_reader :tempdir
49
-
50
- def change_git_ignore
51
- file = target_path.join('.gitignore')
52
- file.write(
53
- (file.read.each_line.map(&:strip).reject { |line| GITIGNORE_DEL.include?(line) } +
54
- ['', '#eac_redmine_base0'] + GITIGNORE_ADD).map { |line| "#{line}\n" }.join
55
- )
56
- end
57
-
58
- def extract_package_to_tempdir
59
- infom "Extracting package to tempdir #{tempdir}..."
60
- ::EacRubyUtils::Envs.local.command(
61
- 'tar', '-xf', source_package.path.to_path, '-C', tempdir.to_path,
62
- '--strip-components', '1'
63
- ).execute!
64
- end
65
-
66
- def git_commit
67
- if git_repo.dirty?
68
- infom 'Git commiting...'
69
- git_repo.command('add', '--', target_path).execute!
70
- git_repo.command('commit', '-m', git_commit_message, '--', target_path).execute!
71
- else
72
- infom 'Nothing to commit'
73
- end
74
- end
75
-
76
- def git_commit_message
77
- i18n_translate(__method__, version: version, __locale: source.locale)
78
- end
79
-
80
- def git_repo_uncached
81
- ::EacGit::Local.new(target_path)
82
- end
83
-
84
- def sync_content
85
- ::Avm::Sync.new(source_path, target_path)
86
- .add_exclude('/*').add_includes(*target_files_to_remove).move_mode(true).run
87
- end
88
-
89
- # @return [EacFs::CachedDownload]
90
- def source_package_uncached
91
- ::EacFs::CachedDownload.new(url, fs_cache)
92
- end
93
-
94
- def validate_empty_dir
95
- if source_path.children.empty?
96
- infom 'No content left in source directory'
97
- else
98
- fatal_error 'Found entries in source directory: ' +
99
- source_path.children.map { |c| c.basename.to_path }.join(', ')
100
- end
101
- end
102
-
103
- def source_path_uncached
104
- ::Pathname.new(tempdir.to_path)
105
- end
106
-
107
- def target_files_to_remove
108
- git_repo.command('ls-files').execute!
109
- .each_line.map { |v| "/#{v.strip}" }
110
- .without(*TARGET_KEEP)
111
- end
112
-
113
- def target_path_uncached
114
- source.path
115
- end
116
- end
117
- end
118
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/data/instance/unit'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'curb'
6
- require 'open-uri'
7
-
8
- module Avm
9
- module EacRedmineBase0
10
- class DataUnit < ::Avm::Data::Instance::Unit
11
- common_constructor :instance
12
-
13
- EXPORT_PATH = '/backup/export'
14
- EXTENSION = '.tar'
15
- IMPORT_PATH = '/backup/import.json'
16
-
17
- def do_dump(data_path)
18
- ::File.open(data_path, 'wb') do |file|
19
- file << export_request.response.body_data_or_raise
20
- end
21
- end
22
-
23
- def do_load(data_path)
24
- do_load_by_web(data_path) || do_load_by_rake(data_path) || raise('Failed to load')
25
- end
26
-
27
- def do_load_by_web(data_path)
28
- c = Curl::Easy.new(import_url)
29
- c.multipart_form_post = true
30
- c.http_post(Curl::PostField.file('redmine_with_git_tableless_load[path]', data_path))
31
- c.perform
32
- true
33
- rescue Curl::Err::ConnectionFailedError
34
- false
35
- end
36
-
37
- def do_load_by_rake(data_path)
38
- instance.bundle('exec', 'rake', "redmine_with_git:load:all[#{data_path}]").system
39
- true
40
- end
41
-
42
- def export_request
43
- instance.rest_api.request(EXPORT_PATH)
44
- end
45
-
46
- def import_url
47
- instance.rest_api.build_service_url(IMPORT_PATH).to_s
48
- end
49
- end
50
- end
51
- end