avm-tools 0.17.0 → 0.18.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: d6a03e86cba8b7cc3cefba9163e093176460fc22f9155414ad6cc113ebe3cd5d
4
- data.tar.gz: bd31ac49d42c4020a81543f099b5cdc693628821601ef196f185b675d03285ed
3
+ metadata.gz: 7aac25bb0c585e13aa100af2ab6ff42d830b575cfd423a873c99b799bd1cd58c
4
+ data.tar.gz: f2b38abd01c102a189b2f224c09e32a3738d7168be4aa3eff2fcfe6c2c1c9f5e
5
5
  SHA512:
6
- metadata.gz: 01b434bc5a5bc72b9de6ab1679886ef5587fba84e1095d114702dfae4d180b169fcc8c823df7adef6965a4c1a0b9c266649f0de86eb912bb0f5e3141663369a3
7
- data.tar.gz: ee37b11970672b1c90b313517807349381f93ae0fd892e6d85dd0c7dbcbd766efe7073351a5bf4f5dc316516983ca7368636acbd1e7154b8911a44e548831972
6
+ metadata.gz: b72bb22e2fa79eb43f6adeb6c7aeb3021167055c8d903cab131caa9aca00aed799ba1aa12b968f3382cec180b7954ea7ad89b5db0cced4f474e15e2d0182da4e
7
+ data.tar.gz: 76c35f6f8f8023356b47f2866ce9e38291dd8bb256b2faf0c4da0859cde0c63f7fea138377e9d3370549aa82d6bd305feacbcd3cd79cbeb66b64dce2c4d891bc
@@ -5,5 +5,6 @@ require 'eac_ruby_utils/require_sub'
5
5
 
6
6
  module Avm
7
7
  module Git
8
+ DEFAULT_REMOTE_NAME = 'origin'
8
9
  end
9
10
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
6
+ module Avm
7
+ module Stereotypes
8
+ module EacRailsBase0
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/stereotypes/eac_webapp_base0/deploy'
4
+
5
+ module Avm
6
+ module Stereotypes
7
+ module EacRailsBase0
8
+ class Deploy < ::Avm::Stereotypes::EacWebappBase0::Deploy
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/stereotypes/eac_webapp_base0/instance'
4
+
5
+ module Avm
6
+ module Stereotypes
7
+ module EacRailsBase0
8
+ class Instance < ::Avm::Stereotypes::EacWebappBase0::Instance
9
+ FILES_UNITS = { uploads: 'public/uploads' }.freeze
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
6
+ module Avm
7
+ module Stereotypes
8
+ module EacWebappBase0
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'delegate'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_launcher/git/base'
6
+ require 'avm/git'
7
+ require 'avm/patches/object/template'
8
+
9
+ module Avm
10
+ module Stereotypes
11
+ module EacWebappBase0
12
+ class Deploy
13
+ enable_console_speaker
14
+ enable_simple_cache
15
+
16
+ attr_reader :instance, :git_reference
17
+
18
+ def initialize(instance, git_reference)
19
+ @instance = instance
20
+ @git_reference = git_reference
21
+ end
22
+
23
+ def run
24
+ start_banner
25
+ git_deploy
26
+ setup_files_units
27
+ assert_instance_branch
28
+ ::Avm::Result.success('Deployed')
29
+ rescue ::Avm::Result::Error => e
30
+ e.to_result
31
+ end
32
+
33
+ def start_banner
34
+ infov 'Instance', instance
35
+ infov 'Git reference (User)', git_reference.if_present('- BLANK -')
36
+ infov 'Git remote name', git_remote_name
37
+ infov 'Git reference (Found)', git_reference_found
38
+ infov 'Git commit SHA1', commit_sha1
39
+ end
40
+
41
+ def git_deploy
42
+ infom 'Deploying source code and appended content...'
43
+ ::Avm::Git::Commit.new(git, commit_sha1).deploy_to_env_path(
44
+ instance.host_env,
45
+ instance.read_entry(:fs_path)
46
+ ).append_directory(template_path).variables_source_set(instance).run
47
+ end
48
+
49
+ def setup_files_units
50
+ instance.class.const_get('FILES_UNITS').each do |data_key, fs_path_subpath|
51
+ FilesUnit.new(self, data_key, fs_path_subpath).run
52
+ end
53
+ end
54
+
55
+ def assert_instance_branch
56
+ infom 'Setting instance branch...'
57
+ git.execute!('push', git_remote_name, "#{commit_sha1}:refs/heads/#{instance.id}", '-f')
58
+ end
59
+
60
+ def commit_sha1_uncached
61
+ git_fetch
62
+ r = git.rev_parse(git_reference_found)
63
+ return r if r
64
+
65
+ raise ::Avm::Result::Error, "No commit SHA1 found for \"#{git_reference_found}\""
66
+ end
67
+
68
+ def git_reference_found_uncached
69
+ %w[git_reference instance_branch master_branch].map { |b| send(b) }.find(&:present?) ||
70
+ raise(
71
+ ::Avm::Result::Error,
72
+ 'No git reference found (Searched for option, instance and master)'
73
+ )
74
+ end
75
+
76
+ def git_uncached
77
+ ::EacLauncher::Git::Base.new(git_repository_path)
78
+ end
79
+
80
+ def instance_branch
81
+ remote_branch(instance.id)
82
+ end
83
+
84
+ def master_branch
85
+ remote_branch('master')
86
+ end
87
+
88
+ def git_remote_name
89
+ ::Avm::Git::DEFAULT_REMOTE_NAME
90
+ end
91
+
92
+ def git_remote_hashs_uncached
93
+ git.remote_hashs(git_remote_name)
94
+ end
95
+
96
+ def git_fetch_uncached
97
+ infom "Fetching remote \"#{git_remote_name}\" from \"#{git_repository_path}\"..."
98
+ git.fetch(git_remote_name)
99
+ end
100
+
101
+ def git_repository_path
102
+ instance.source_instance.read_entry(:fs_path)
103
+ end
104
+
105
+ def remote_branch(name)
106
+ git_remote_hashs.key?("refs/heads/#{name}") ? "#{git_remote_name}/#{name}" : nil
107
+ end
108
+
109
+ class FilesUnit < ::SimpleDelegator
110
+ attr_reader :data_key, :fs_path_subpath
111
+
112
+ def initialize(deploy, data_key, fs_path_subpath)
113
+ super(deploy)
114
+ @data_key = data_key
115
+ @fs_path_subpath = fs_path_subpath
116
+ end
117
+
118
+ def run
119
+ assert_source_directory
120
+ link_source_target
121
+ end
122
+
123
+ def assert_source_directory
124
+ infom "Asserting \"#{data_key}\" source directory..."
125
+ instance.host_env.command('mkdir', '-p', source_path).execute!
126
+ end
127
+
128
+ def source_path
129
+ ::File.join(instance.read_entry(:data_fs_path), data_key.to_s)
130
+ end
131
+
132
+ def target_path
133
+ ::File.join(instance.read_entry(:fs_path), fs_path_subpath.to_s)
134
+ end
135
+
136
+ def link_source_target
137
+ infom "Linking \"#{data_key}\" directory..."
138
+ instance.host_env.command('rm', '-rf', target_path).execute!
139
+ instance.host_env.command('ln', '-s', source_path, target_path).execute!
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'avm/stereotypes/postgresql/instance_with'
5
+ require 'avm/data/instance/files_unit'
6
+ require 'avm/data/instance/package'
7
+
8
+ module Avm
9
+ module Stereotypes
10
+ module EacWebappBase0
11
+ class Instance < ::Avm::Instances::Base
12
+ include ::Avm::Stereotypes::Postgresql::InstanceWith
13
+
14
+ FILES_UNITS = { uploads: 'wp-content/uploads', themes: 'wp-content/themes' }.freeze
15
+
16
+ def stereotype_name
17
+ self.class.name.desconstantize.demodulize
18
+ end
19
+
20
+ def data_dump(argv = [])
21
+ run_subcommand(::Avm::Tools::Runner::EacWordpressBase0::Data::Dump, argv)
22
+ end
23
+
24
+ def data_dump_runner_class
25
+ "::Avm::Tools::Runner::#{stereotype_name}::Data::Dump".constantize
26
+ end
27
+
28
+ def run_subcommand(subcommand_class, argv)
29
+ parent = ::OpenStruct.new(instance: self)
30
+ subcommand_class.new(argv: argv, parent: parent).run
31
+ end
32
+
33
+ def data_package
34
+ @data_package ||= ::Avm::Data::Instance::Package.new(
35
+ self, units: { database: database_unit }.merge(files_units)
36
+ )
37
+ end
38
+
39
+ def database_unit
40
+ pg.data_unit
41
+ end
42
+
43
+ private
44
+
45
+ def files_units
46
+ FILES_UNITS.map do |data_key, fs_path_subpath|
47
+ [data_key, ::Avm::Data::Instance::FilesUnit.new(self, fs_path_subpath)]
48
+ end.to_h
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,147 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'delegate'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'eac_launcher/git/base'
6
- require 'avm/git/commit'
7
- require 'avm/patches/object/template'
3
+ require 'avm/stereotypes/eac_webapp_base0/deploy'
8
4
 
9
5
  module Avm
10
6
  module Stereotypes
11
7
  module EacWordpressBase0
12
- class Deploy
13
- enable_console_speaker
14
- enable_simple_cache
15
-
16
- attr_reader :instance, :git_reference
17
-
18
- DEFAULT_REMOTE_NAME = 'origin'
19
-
20
- def initialize(instance, git_reference)
21
- @instance = instance
22
- @git_reference = git_reference
23
- end
24
-
25
- def run
26
- start_banner
27
- git_deploy
28
- setup_files_units
29
- assert_instance_branch
30
- ::Avm::Result.success('Deployed')
31
- rescue ::Avm::Result::Error => e
32
- e.to_result
33
- end
34
-
35
- def start_banner
36
- infov 'Instance', instance
37
- infov 'Git reference (User)', git_reference.if_present('- BLANK -')
38
- infov 'Git remote name', git_remote_name
39
- infov 'Git reference (Found)', git_reference_found
40
- infov 'Git commit SHA1', commit_sha1
41
- end
42
-
43
- def git_deploy
44
- infom 'Deploying source code and appended content...'
45
- ::Avm::Git::Commit.new(git, commit_sha1).deploy_to_env_path(
46
- instance.host_env,
47
- instance.read_entry(:fs_path)
48
- ).append_directory(template_path).variables_source_set(instance).run
49
- end
50
-
51
- def setup_files_units
52
- ::Avm::Stereotypes::EacWordpressBase0::Instance::FILES_UNITS
53
- .each do |data_key, fs_path_subpath|
54
- FilesUnit.new(self, data_key, fs_path_subpath).run
55
- end
56
- end
57
-
58
- def assert_instance_branch
59
- infom 'Setting instance branch...'
60
- git.execute!('push', git_remote_name, "#{commit_sha1}:refs/heads/#{instance.id}", '-f')
61
- end
62
-
63
- def commit_sha1_uncached
64
- git_fetch
65
- r = git.rev_parse(git_reference_found)
66
- return r if r
67
-
68
- raise ::Avm::Result::Error, "No commit SHA1 found for \"#{git_reference_found}\""
69
- end
70
-
71
- def git_reference_found_uncached
72
- %w[git_reference instance_branch master_branch].map { |b| send(b) }.find(&:present?) ||
73
- raise(
74
- ::Avm::Result::Error,
75
- 'No git reference found (Searched for option, instance and master)'
76
- )
77
- end
78
-
79
- def git_uncached
80
- ::EacLauncher::Git::Base.new(git_repository_path)
81
- end
82
-
83
- def instance_branch
84
- remote_branch(instance.id)
85
- end
86
-
87
- def master_branch
88
- remote_branch('master')
89
- end
90
-
91
- def git_remote_name
92
- DEFAULT_REMOTE_NAME
93
- end
94
-
95
- def git_remote_hashs_uncached
96
- git.remote_hashs(git_remote_name)
97
- end
98
-
99
- def git_fetch_uncached
100
- infom "Fetching remote \"#{git_remote_name}\" from \"#{git_repository_path}\"..."
101
- git.fetch(git_remote_name)
102
- end
103
-
104
- def git_repository_path
105
- instance.source_instance.read_entry(:fs_path)
106
- end
107
-
108
- def remote_branch(name)
109
- git_remote_hashs.key?("refs/heads/#{name}") ? "#{git_remote_name}/#{name}" : nil
110
- end
111
-
112
- class FilesUnit < ::SimpleDelegator
113
- attr_reader :data_key, :fs_path_subpath
114
-
115
- def initialize(deploy, data_key, fs_path_subpath)
116
- super(deploy)
117
- @data_key = data_key
118
- @fs_path_subpath = fs_path_subpath
119
- end
120
-
121
- def run
122
- assert_source_directory
123
- link_source_target
124
- end
125
-
126
- def assert_source_directory
127
- infom "Asserting \"#{data_key}\" source directory..."
128
- instance.host_env.command('mkdir', '-p', source_path).execute!
129
- end
130
-
131
- def source_path
132
- ::File.join(instance.read_entry(:data_fs_path), data_key.to_s)
133
- end
134
-
135
- def target_path
136
- ::File.join(instance.read_entry(:fs_path), fs_path_subpath.to_s)
137
- end
138
-
139
- def link_source_target
140
- infom "Linking \"#{data_key}\" directory..."
141
- instance.host_env.command('rm', '-rf', target_path).execute!
142
- instance.host_env.command('ln', '-s', source_path, target_path).execute!
143
- end
144
- end
8
+ class Deploy < ::Avm::Stereotypes::EacWebappBase0::Deploy
145
9
  end
146
10
  end
147
11
  end
@@ -1,36 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/instances/base'
4
- require 'avm/stereotypes/postgresql/instance_with'
5
- require 'avm/data/instance/files_unit'
6
- require 'avm/data/instance/package'
3
+ require 'avm/stereotypes/eac_webapp_base0/instance'
7
4
 
8
5
  module Avm
9
6
  module Stereotypes
10
7
  module EacWordpressBase0
11
- class Instance < ::Avm::Instances::Base
12
- include ::Avm::Stereotypes::Postgresql::InstanceWith
13
-
8
+ class Instance < ::Avm::Stereotypes::EacWebappBase0::Instance
14
9
  FILES_UNITS = { uploads: 'wp-content/uploads', themes: 'wp-content/themes' }.freeze
15
10
 
16
- def data_dump(argv = [])
17
- run_subcommand(::Avm::Tools::Runner::EacWordpressBase0::Data::Dump, argv)
18
- end
19
-
20
- def run_subcommand(subcommand_class, argv)
21
- parent = ::OpenStruct.new(instance: self)
22
- subcommand_class.new(argv: argv, parent: parent).run
23
- end
24
-
25
- def data_package
26
- @data_package ||= ::Avm::Data::Instance::Package.new(
27
- self, units: { database: database_unit }.merge(files_units)
28
- )
29
- end
30
-
31
11
  def database_unit
32
12
  self_instance = self
33
- pg.data_unit.after_load do
13
+ super.after_load do
34
14
  info 'Fixing web addresses...'
35
15
  run_sql(<<~SQL)
36
16
  update wp_options
@@ -39,14 +19,6 @@ module Avm
39
19
  SQL
40
20
  end
41
21
  end
42
-
43
- private
44
-
45
- def files_units
46
- FILES_UNITS.map do |data_key, fs_path_subpath|
47
- [data_key, ::Avm::Data::Instance::FilesUnit.new(self, fs_path_subpath)]
48
- end.to_h
49
- end
50
22
  end
51
23
  end
52
24
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'avm/stereotypes/eac_rails_base0/instance'
6
+ require 'eac_ruby_utils/require_sub'
7
+ ::EacRubyUtils.require_sub(__FILE__)
8
+
9
+ module Avm
10
+ module Tools
11
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
12
+ class EacRailsBase0 < ::EacRubyUtils::Console::DocoptRunner
13
+ include ::EacRubyUtils::SimpleCache
14
+
15
+ DOC = <<~DOCOPT
16
+ Utilities for EacRailsBase0 instances.
17
+
18
+ Usage:
19
+ __PROGRAM__ [options] <instance_id> __SUBCOMMANDS__
20
+ __PROGRAM__ -h | --help
21
+
22
+ Options:
23
+ -h --help Show this screen.
24
+ DOCOPT
25
+
26
+ private
27
+
28
+ def instance_uncached
29
+ ::Avm::Stereotypes::EacRailsBase0::Instance.by_id(options['<instance_id>'])
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/console/speaker'
5
+ require 'avm/stereotypes/eac_rails_base0/deploy'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class EacRailsBase0 < ::EacRubyUtils::Console::DocoptRunner
11
+ class Deploy < ::EacRubyUtils::Console::DocoptRunner
12
+ include ::EacRubyUtils::Console::Speaker
13
+
14
+ DOC = <<~DOCOPT
15
+ Deploy for EacRailsBase0 instance.
16
+
17
+ Usage:
18
+ __PROGRAM__ [options]
19
+ __PROGRAM__ -h | --help
20
+
21
+ Options:
22
+ -h --help Show this screen.
23
+ -r --reference=<git-reference> Git reference to deploy.
24
+ DOCOPT
25
+
26
+ def run
27
+ result = ::Avm::Stereotypes::EacRailsBase0::Deploy.new(
28
+ context(:instance),
29
+ options.fetch('--reference')
30
+ ).run
31
+ if result.error?
32
+ fatal_error result.to_s
33
+ else
34
+ infov 'Result', result.label
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -40,6 +40,7 @@ module Avm
40
40
  infov 'Repository', git
41
41
  infov 'Reference', reference
42
42
  infov 'Instance ID', instance_id.if_present('- BLANK -')
43
+ infov 'Appended directories', appended_directories
43
44
  end
44
45
 
45
46
  def validate
@@ -67,7 +68,7 @@ module Avm
67
68
  def deploy
68
69
  ::Avm::Git::Commit.new(git, reference_sha1)
69
70
  .deploy_to_url(options.fetch('<target-url>'))
70
- .append_directories(options.fetch('<append-directories>'))
71
+ .append_directories(appended_directories)
71
72
  .variables_source_set(variables_source)
72
73
  .run
73
74
  end
@@ -83,6 +84,10 @@ module Avm
83
84
  def instance_id
84
85
  options.fetch('--instance')
85
86
  end
87
+
88
+ def appended_directories
89
+ options.fetch('<append-directories>')
90
+ end
86
91
  end
87
92
  end
88
93
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.17.0'
5
+ VERSION = '0.18.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
@@ -214,6 +214,12 @@ files:
214
214
  - lib/avm/patches/object/template.rb
215
215
  - lib/avm/result.rb
216
216
  - lib/avm/stereotypes.rb
217
+ - lib/avm/stereotypes/eac_rails_base0.rb
218
+ - lib/avm/stereotypes/eac_rails_base0/deploy.rb
219
+ - lib/avm/stereotypes/eac_rails_base0/instance.rb
220
+ - lib/avm/stereotypes/eac_webapp_base0.rb
221
+ - lib/avm/stereotypes/eac_webapp_base0/deploy.rb
222
+ - lib/avm/stereotypes/eac_webapp_base0/instance.rb
217
223
  - lib/avm/stereotypes/eac_wordpress_base0/deploy.rb
218
224
  - lib/avm/stereotypes/eac_wordpress_base0/instance.rb
219
225
  - lib/avm/stereotypes/postgresql.rb
@@ -226,6 +232,8 @@ files:
226
232
  - lib/avm/tools.rb
227
233
  - lib/avm/tools/git.rb
228
234
  - lib/avm/tools/runner.rb
235
+ - lib/avm/tools/runner/eac_rails_base0.rb
236
+ - lib/avm/tools/runner/eac_rails_base0/deploy.rb
229
237
  - lib/avm/tools/runner/eac_wordpress_base0.rb
230
238
  - lib/avm/tools/runner/eac_wordpress_base0/data.rb
231
239
  - lib/avm/tools/runner/eac_wordpress_base0/data/dump.rb