avm-tools 0.54.2 → 0.55.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: b84d0393c577738f7356c886a99ef8e6c82343f9dd7d751cbf560dda774f32df
4
- data.tar.gz: ffbb4bc86684f7422e7b49c38583a6f9d8df938c8471524e30eced6c6ea40a63
3
+ metadata.gz: df83da96c07da9eadc8be286bd954d0fd8905a2ff0376da5b109289cb8d90635
4
+ data.tar.gz: 8825abbc5032bd4e7d76031caa85782b3e792f588cc8c5e8811c5ed7fc4232f0
5
5
  SHA512:
6
- metadata.gz: 1984afe6dca5217c4ac1085872901e0be97b8ede8a7ce023fb7e7ad87525c37af30e3cb174223c14b870c8a14c0a332d9c8ec6f01bf20f0e18d50e55ea306039
7
- data.tar.gz: fa200e96cb2f36a56e980ec5e179dafe659035c1d8f95c4f6b2c352343d177cdb05aa7fa3bab86bb049931956d5a01c02e5dc0092bc87a659e064919c9dd1df7
6
+ metadata.gz: 3436be6aa4b6017e646f864501f5719d97fe39f9596ef6c2e233e43b2c247302d1d47733573b51d8d596934df9273875f89607762185bf0d27fa9ae8340042aa
7
+ data.tar.gz: bcbb3e38cbdd66d3e8095fb10b4ed1379ddbbb6c2df5e34bdd72e4043ef8b013a8fd08963675f4c0aa546229a39f887f17f060d8cd0c70597631f055e0dbafa1
data/Gemfile CHANGED
@@ -6,8 +6,7 @@ gemspec
6
6
 
7
7
  gems_subdir = ::File.join(__dir__, 'vendor', 'gems')
8
8
  Dir["#{gems_subdir}/*"].each do |dir|
9
- next unless ::File.directory?(dir)
9
+ next unless ::File.file?(::File.join(dir, 'Gemfile'))
10
10
 
11
- basename = ::File.basename(dir)
12
- gem basename, path: "#{gems_subdir}/#{basename}"
11
+ gem ::File.basename(dir), path: dir
13
12
  end
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/simple_cache'
4
- require 'eac_ruby_utils/require_sub'
5
- ::EacRubyUtils.require_sub(__FILE__)
3
+ require 'eac_ruby_utils/core_ext'
6
4
 
7
5
  module Avm
8
6
  module Git
9
7
  class Commit
10
- include ::EacRubyUtils::SimpleCache
8
+ require_sub __FILE__, include_modules: true
9
+ enable_simple_cache
11
10
 
12
11
  FIELDS = {
13
12
  author_name: '%an', author_email: '%ae', author_date: '%ai',
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Git
7
+ class Commit
8
+ module ClassMethods
9
+ common_concern
10
+
11
+ module ClassMethods
12
+ def target_url_to_env_path(target_url)
13
+ uri = ::Addressable::URI.parse(target_url)
14
+ uri.scheme = 'file' if uri.scheme.blank?
15
+ [uri_to_env(uri), uri.path]
16
+ end
17
+
18
+ private
19
+
20
+ def uri_to_env(uri)
21
+ case uri.scheme
22
+ when 'file' then ::EacRubyUtils::Envs.local
23
+ when 'ssh' then ::EacRubyUtils::Envs.ssh(uri)
24
+ else "Invalid schema \"#{uri.schema}\" (URI: #{uri})"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,63 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'addressable'
4
- require 'eac_ruby_utils/simple_cache'
5
- require 'eac_ruby_utils/require_sub'
6
- ::EacRubyUtils.require_sub(__FILE__)
4
+ require 'eac_ruby_utils/core_ext'
7
5
  require 'avm/patches/object/template'
8
6
 
9
7
  module Avm
10
8
  module Git
11
9
  class Commit
12
- class << self
13
- def target_url_to_env_path(target_url)
14
- uri = ::Addressable::URI.parse(target_url)
15
- uri.scheme = 'file' if uri.scheme.blank?
16
- [uri_to_env(uri), uri.path]
17
- end
18
-
19
- private
20
-
21
- def uri_to_env(uri)
22
- case uri.scheme
23
- when 'file' then ::EacRubyUtils::Envs.local
24
- when 'ssh' then ::EacRubyUtils::Envs.ssh(uri)
25
- else "Invalid schema \"#{uri.schema}\" (URI: #{uri})"
26
- end
27
- end
28
- end
29
-
30
- def deploy_to_env_path(target_env, target_path)
31
- Deploy.new(self, target_env, target_path)
32
- end
33
-
34
- def deploy_to_url(target_url)
35
- Deploy.new(self, *self.class.target_url_to_env_path(target_url))
36
- end
37
-
38
10
  class Deploy
39
- include ::EacRubyUtils::SimpleCache
11
+ require_sub __FILE__, include_modules: true
12
+ enable_simple_cache
40
13
 
41
- attr_reader :commit, :target_env, :target_path, :appended_directories, :variables_source
14
+ attr_reader :build_dir, :commit, :target_env, :target_path, :variables_source
42
15
 
43
16
  def initialize(commit, target_env, target_path)
44
17
  @commit = commit
45
18
  @target_env = target_env
46
19
  @target_path = target_path
47
- @appended_directories = []
48
20
  @variables_source = nil
49
21
  end
50
22
 
51
- def append_directory(directory)
52
- @appended_directories << directory
53
- self
54
- end
55
-
56
- def append_directories(directories)
57
- directories.each { |directory| append_directory(directory) }
58
- self
59
- end
60
-
61
23
  def variables_source_set(source)
62
24
  @variables_source = source
63
25
  self
@@ -66,7 +28,7 @@ module Avm
66
28
  def run
67
29
  on_build_dir do
68
30
  copy_git_content
69
- appended_directories.each { |directory| copy_appended_directory(directory) }
31
+ copy_appended_content
70
32
  mkdir_target
71
33
  clear_content
72
34
  send_untar_package
@@ -76,8 +38,6 @@ module Avm
76
38
 
77
39
  private
78
40
 
79
- attr_reader :build_dir
80
-
81
41
  def on_build_dir
82
42
  @build_dir = ::Dir.mktmpdir
83
43
  yield
@@ -89,12 +49,6 @@ module Avm
89
49
  git_archive_command.pipe(untar_git_archive_command).execute!
90
50
  end
91
51
 
92
- def copy_appended_directory(directory)
93
- raise 'Variables source not set' if variables_source.blank?
94
-
95
- ::EacRubyUtils::Templates::Directory.new(directory).apply(variables_source, build_dir)
96
- end
97
-
98
52
  def mkdir_target
99
53
  target_env.command('mkdir', '-p', target_path).execute!
100
54
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ class Commit
6
+ class Deploy
7
+ module Appended
8
+ require_sub __FILE__
9
+
10
+ def appended
11
+ @appended ||= []
12
+ end
13
+
14
+ def append_directory(directory)
15
+ appended << ::Avm::Git::Commit::Deploy::Appended::Directory.new(self, directory)
16
+ self
17
+ end
18
+
19
+ def append_directories(directories)
20
+ directories.each { |directory| append_directory(directory) }
21
+ self
22
+ end
23
+
24
+ def append_file_content(target_path, content)
25
+ appended << ::Avm::Git::Commit::Deploy::Appended::FileContent
26
+ .new(self, target_path, content)
27
+ self
28
+ end
29
+
30
+ def copy_appended_content
31
+ appended.each(&:copy_to_build_dir)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Git
7
+ class Commit
8
+ class Deploy
9
+ module Appended
10
+ class Base
11
+ common_constructor :deploy
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/git/commit/deploy/appended/base'
5
+
6
+ module Avm
7
+ module Git
8
+ class Commit
9
+ class Deploy
10
+ module Appended
11
+ class Directory < ::Avm::Git::Commit::Deploy::Appended::Base
12
+ attr_reader :source_path
13
+
14
+ def initialize(deploy, source_path)
15
+ super(deploy)
16
+ @source_path = source_path
17
+ end
18
+
19
+ def copy_to_build_dir
20
+ raise 'Variables source not set' if deploy.variables_source.blank?
21
+
22
+ ::EacRubyUtils::Templates::Directory.new(source_path).apply(
23
+ deploy.variables_source,
24
+ deploy.build_dir
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/git/commit/deploy/appended/base'
5
+
6
+ module Avm
7
+ module Git
8
+ class Commit
9
+ class Deploy
10
+ module Appended
11
+ class FileContent < ::Avm::Git::Commit::Deploy::Appended::Base
12
+ attr_reader :target_path, :content
13
+
14
+ def initialize(deploy, target_path, content)
15
+ super(deploy)
16
+ @target_path = target_path
17
+ @content = content
18
+ end
19
+
20
+ def copy_to_build_dir
21
+ deploy.build_dir.to_pathname.join(target_path).write(content)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Git
7
+ class Commit
8
+ module DeployMethods
9
+ def deploy_to_env_path(target_env, target_path)
10
+ Deploy.new(self, target_env, target_path)
11
+ end
12
+
13
+ def deploy_to_url(target_url)
14
+ Deploy.new(self, *self.class.target_url_to_env_path(target_url))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -12,10 +12,9 @@ module Avm
12
12
  module Stereotypes
13
13
  module EacWebappBase0
14
14
  class Deploy
15
+ require_sub __FILE__, include_modules: true
15
16
  include ::ActiveSupport::Callbacks
16
17
 
17
- require_relative 'deploy/_appended_directories'
18
-
19
18
  DEFAULT_REFERENCE = 'HEAD'
20
19
 
21
20
  enable_console_speaker
@@ -61,18 +60,16 @@ module Avm
61
60
 
62
61
  def git_deploy
63
62
  infom 'Deploying source code and appended content...'
64
- build_git_commit.append_directory(template.path).append_directories(
65
- appended_directories
66
- ).run
67
- end
68
-
69
- def git_reference
70
- options[:reference] || DEFAULT_REFERENCE
63
+ build_git_commit
64
+ .append_directory(template.path)
65
+ .append_directories(appended_directories)
66
+ .append_file_content(VERSION_TARGET_PATH, version)
67
+ .run
71
68
  end
72
69
 
73
70
  def setup_files_units
74
71
  instance.class.const_get('FILES_UNITS').each do |data_key, fs_path_subpath|
75
- FilesUnit.new(self, data_key, fs_path_subpath).run
72
+ FileUnit.new(self, data_key, fs_path_subpath).run
76
73
  end
77
74
  end
78
75
 
@@ -89,42 +86,10 @@ module Avm
89
86
  fatal_error "Request to #{uri} failed" unless response.code.to_i == 200
90
87
  end
91
88
 
92
- def commit_sha1_uncached
93
- git_fetch
94
- r = git.rev_parse(git_reference_found)
95
- return r if r
96
-
97
- raise ::Avm::Result::Error, "No commit SHA1 found for \"#{git_reference_found}\""
98
- end
99
-
100
- def git_reference_found_uncached
101
- %w[git_reference instance_branch master_branch].map { |b| send(b) }.find(&:present?) ||
102
- raise(
103
- ::Avm::Result::Error,
104
- 'No git reference found (Searched for option, instance and master)'
105
- )
106
- end
107
-
108
89
  def git_uncached
109
90
  ::EacLauncher::Git::Base.new(git_repository_path)
110
91
  end
111
92
 
112
- def instance_branch
113
- remote_branch(instance.id)
114
- end
115
-
116
- def master_branch
117
- remote_branch('master')
118
- end
119
-
120
- def git_remote_name
121
- ::Avm::Git::DEFAULT_REMOTE_NAME
122
- end
123
-
124
- def git_remote_hashs_uncached
125
- git.remote_hashs(git_remote_name)
126
- end
127
-
128
93
  def git_fetch_uncached
129
94
  infom "Fetching remote \"#{git_remote_name}\" from \"#{git_repository_path}\"..."
130
95
  git.fetch(git_remote_name)
@@ -133,10 +98,6 @@ module Avm
133
98
  def git_repository_path
134
99
  instance.source_instance.read_entry(:fs_path)
135
100
  end
136
-
137
- def remote_branch(name)
138
- git_remote_hashs.key?("refs/heads/#{name}") ? "#{git_remote_name}/#{name}" : nil
139
- end
140
101
  end
141
102
  end
142
103
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/path_string'
4
+
5
+ module Avm
6
+ module Stereotypes
7
+ module EacWebappBase0
8
+ class Deploy
9
+ module AppendedDirectories
10
+ APPENDED_DIRECTORIES_ENTRY_KEY = 'deploy.appended_directories'
11
+
12
+ def appended_directories
13
+ appended_directories_from_instance_entry + appended_directories_from_options
14
+ end
15
+
16
+ def appended_directories_from_instance_entry
17
+ ::Avm::PathString.paths(instance.read_entry_optional(APPENDED_DIRECTORIES_ENTRY_KEY))
18
+ end
19
+
20
+ def appended_directories_from_options
21
+ options[:appended_directories] || []
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -4,7 +4,7 @@ module Avm
4
4
  module Stereotypes
5
5
  module EacWebappBase0
6
6
  class Deploy
7
- class FilesUnit < ::SimpleDelegator
7
+ class FileUnit < ::SimpleDelegator
8
8
  attr_reader :data_key, :fs_path_subpath
9
9
 
10
10
  def initialize(deploy, data_key, fs_path_subpath)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Stereotypes
5
+ module EacWebappBase0
6
+ class Deploy
7
+ module GitInfo
8
+ def commit_sha1_uncached
9
+ git_fetch
10
+ r = git.rev_parse(git_reference_found)
11
+ return r if r
12
+
13
+ raise ::Avm::Result::Error, "No commit SHA1 found for \"#{git_reference_found}\""
14
+ end
15
+
16
+ def git_reference
17
+ options[:reference] || DEFAULT_REFERENCE
18
+ end
19
+
20
+ def git_reference_found_uncached
21
+ %w[git_reference instance_branch master_branch].map { |b| send(b) }.find(&:present?) ||
22
+ raise(
23
+ ::Avm::Result::Error,
24
+ 'No git reference found (Searched for option, instance and master)'
25
+ )
26
+ end
27
+
28
+ def git_remote_hashs_uncached
29
+ git.remote_hashs(git_remote_name)
30
+ end
31
+
32
+ def git_remote_name
33
+ ::Avm::Git::DEFAULT_REMOTE_NAME
34
+ end
35
+
36
+ def instance_branch
37
+ remote_branch(instance.id)
38
+ end
39
+
40
+ def remote_branch(name)
41
+ git_remote_hashs.key?("refs/heads/#{name}") ? "#{git_remote_name}/#{name}" : nil
42
+ end
43
+
44
+ def master_branch
45
+ remote_branch('master')
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Stereotypes
5
+ module EacWebappBase0
6
+ class Deploy
7
+ module Version
8
+ VERSION_TARGET_PATH = 'VERSION'
9
+
10
+ def version
11
+ ([::Time.now, commit_sha1] + version_git_refs).join('|')
12
+ end
13
+
14
+ def version_git_refs
15
+ git_remote_hashs.select { |_name, sha1| sha1 == commit_sha1 }.keys
16
+ .map { |ref| ref.gsub(%r{\Arefs/}, '') }.reject { |ref| ref == 'HEAD' }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.54.2'
5
+ VERSION = '0.55.0'
6
6
  end
7
7
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/inflector'
4
+
3
5
  module EacRubyUtils
4
6
  class << self
5
7
  def require_sub(file, options = {})
@@ -26,6 +28,23 @@ module EacRubyUtils
26
28
 
27
29
  private
28
30
 
31
+ def active_support_require(path)
32
+ return false unless options[REQUIRE_DEPENDENCY_OPTION_KEY]
33
+
34
+ ::Kernel.require_dependency(path)
35
+ true
36
+ end
37
+
38
+ def autoload_require(path)
39
+ return false unless base?
40
+
41
+ basename = ::File.basename(path, '.*')
42
+ return false if basename.start_with?('_')
43
+
44
+ base.autoload ::ActiveSupport::Inflector.camelize(basename), path
45
+ true
46
+ end
47
+
29
48
  def include_modules
30
49
  return unless options[INCLUDE_MODULES_OPTION_KEY]
31
50
 
@@ -41,14 +60,22 @@ module EacRubyUtils
41
60
  options[BASE_OPTION_KEY] || raise('Option :base not setted')
42
61
  end
43
62
 
63
+ def base?
64
+ options[BASE_OPTION_KEY] ? true : false
65
+ end
66
+
67
+ def kernel_require(path)
68
+ ::Kernel.require(path)
69
+ end
70
+
44
71
  def require_sub_files
45
72
  Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort.each do |path|
46
- if options[REQUIRE_DEPENDENCY_OPTION_KEY]
47
- require_dependency path
48
- else
49
- require path
50
- end
73
+ require_sub_file(path)
51
74
  end
52
75
  end
76
+
77
+ def require_sub_file(path)
78
+ active_support_require(path) || autoload_require(path) || kernel_require(path)
79
+ end
53
80
  end
54
81
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.38.0'
4
+ VERSION = '0.39.0'
5
5
  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.54.2
4
+ version: 0.55.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-02 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -140,14 +140,14 @@ dependencies:
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: '0.38'
143
+ version: '0.39'
144
144
  type: :runtime
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '0.38'
150
+ version: '0.39'
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: filesize
153
153
  requirement: !ruby/object:Gem::Requirement
@@ -274,7 +274,13 @@ files:
274
274
  - lib/avm/git.rb
275
275
  - lib/avm/git/auto_commit_path.rb
276
276
  - lib/avm/git/commit.rb
277
+ - lib/avm/git/commit/class_methods.rb
277
278
  - lib/avm/git/commit/deploy.rb
279
+ - lib/avm/git/commit/deploy/appended.rb
280
+ - lib/avm/git/commit/deploy/appended/base.rb
281
+ - lib/avm/git/commit/deploy/appended/directory.rb
282
+ - lib/avm/git/commit/deploy/appended/file_content.rb
283
+ - lib/avm/git/commit/deploy_methods.rb
278
284
  - lib/avm/git/commit/diff_tree_line.rb
279
285
  - lib/avm/git/commit/file.rb
280
286
  - lib/avm/git/file_auto_fixup.rb
@@ -353,8 +359,10 @@ files:
353
359
  - lib/avm/stereotypes/eac_webapp_base0.rb
354
360
  - lib/avm/stereotypes/eac_webapp_base0/apache_host.rb
355
361
  - lib/avm/stereotypes/eac_webapp_base0/deploy.rb
356
- - lib/avm/stereotypes/eac_webapp_base0/deploy/_appended_directories.rb
362
+ - lib/avm/stereotypes/eac_webapp_base0/deploy/appended_directories.rb
357
363
  - lib/avm/stereotypes/eac_webapp_base0/deploy/file_unit.rb
364
+ - lib/avm/stereotypes/eac_webapp_base0/deploy/git_info.rb
365
+ - lib/avm/stereotypes/eac_webapp_base0/deploy/version.rb
358
366
  - lib/avm/stereotypes/eac_webapp_base0/instance.rb
359
367
  - lib/avm/stereotypes/eac_webapp_base0/runner/data.rb
360
368
  - lib/avm/stereotypes/eac_webapp_base0/runner/data/dump.rb
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/path_string'
4
-
5
- module Avm
6
- module Stereotypes
7
- module EacWebappBase0
8
- class Deploy
9
- APPENDED_DIRECTORIES_ENTRY_KEY = 'deploy.appended_directories'
10
-
11
- def appended_directories
12
- appended_directories_from_instance_entry + appended_directories_from_options
13
- end
14
-
15
- def appended_directories_from_instance_entry
16
- ::Avm::PathString.paths(instance.read_entry_optional(APPENDED_DIRECTORIES_ENTRY_KEY))
17
- end
18
-
19
- def appended_directories_from_options
20
- options[:appended_directories] || []
21
- end
22
- end
23
- end
24
- end
25
- end