avm-eac_webapp_base0 0.8.0 → 0.9.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: c54900f40cbb246d07176ed3e482e002249df9a1f4253107d51c148bc8043c4e
4
- data.tar.gz: 35faefcc23749106207ec0e41a7cc032beea459f81bc152ea441481bb35762bc
3
+ metadata.gz: 5bc64f61d969d9fdbb1281a19617f4c16969e0f73181b9c71ee44ad3bee938b8
4
+ data.tar.gz: 16e1d12d41e15be64a51aa45fc18e34d0006d53462d844b0860a12b1cf1af73e
5
5
  SHA512:
6
- metadata.gz: b2a120a192f25621e2111037d53683635cee565f5fd9f4805d7b4ea1056d6e884421b82d6842df05b8644f76302b5a34598cd5647220e5e24e0c6f7329f2ea47
7
- data.tar.gz: 53add19e7a64aca1b4c244d9b6e4a1bc2b36918ae9364dfcd116b7aa914bc6fe173d1ccb304701cd212e767511bc4abc9dda4679b4074f105a66420e9f63b749
6
+ metadata.gz: e40a9ab319e19a3c559e3ce257a728703bf55cb6a36cda2ad530ca82ceb9396dc23bf7c212b79a7cc507f812c4fb1787f72676d2b699a7a2638930fc92e96ed6
7
+ data.tar.gz: d122474e3472dc4892c26f84b4c8e87d96e98ef6068f7c3eff7c468286bd7d28dc0844b62636514eaef0156a8322bac27d6f684b4af98918153da1dfa626b761
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/entries/jobs/base'
5
+ require 'avm/eac_ubuntu_base0/apache'
6
+ require 'eac_templates/core_ext'
7
+
8
+ module Avm
9
+ module EacWebappBase0
10
+ module Instances
11
+ class ApacheHost
12
+ APACHE_DIRECTORY_EXTRA_CONFIG_KEY = 'install.apache_directory_extra_config'
13
+ JOBS = %w[write_available_no_ssl_site enable_no_ssl_site remove_ssl_site reload_apache
14
+ run_certbot enable_ssl_site reload_apache].freeze
15
+ include ::Avm::Entries::Jobs::Base
16
+
17
+ def directory_extra_config
18
+ instance.entry(APACHE_DIRECTORY_EXTRA_CONFIG_KEY).value.if_present { |v| " #{v}\n" }
19
+ end
20
+
21
+ def no_ssl_site_content
22
+ ::Avm::EacWebappBase0::Instances::ApacheHost
23
+ .template.child('no_ssl.conf')
24
+ .apply(variables_source)
25
+ end
26
+
27
+ def ssl?
28
+ options[:certbot]
29
+ end
30
+
31
+ private
32
+
33
+ def apache_uncached
34
+ ::Avm::EacUbuntuBase0::Apache.new(instance.host_env)
35
+ end
36
+
37
+ def enable_no_ssl_site
38
+ infom 'Enabling no SSL site...'
39
+ no_ssl_site.enable
40
+ end
41
+
42
+ def enable_ssl_site
43
+ return unless ssl?
44
+
45
+ infom 'Enabling SSL site...'
46
+ ssl_site.enable
47
+ end
48
+
49
+ def no_ssl_site_uncached
50
+ apache.site(instance.id)
51
+ end
52
+
53
+ def reload_apache
54
+ infom 'Reloading Apache...'
55
+ apache.service('reload')
56
+ end
57
+
58
+ def remove_ssl_site
59
+ infom 'Removing SSL site...'
60
+ ssl_site.remove
61
+ end
62
+
63
+ def run_certbot
64
+ return unless ssl?
65
+
66
+ infom 'Running Certbot...'
67
+ instance.host_env.command(
68
+ 'sudo', 'certbot', '--apache', '--domain', instance.read_entry('web.hostname'),
69
+ '--redirect', '--non-interactive', '--agree-tos',
70
+ '--email', instance.install_email
71
+ ).system!
72
+ end
73
+
74
+ def ssl_site_uncached
75
+ apache.site(no_ssl_site.name + '-le-ssl')
76
+ end
77
+
78
+ def write_available_no_ssl_site
79
+ infom 'Writing no SSL site conf...'
80
+ no_ssl_site.write(no_ssl_site_content)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/entries/jobs/base'
4
+ require 'avm/eac_ubuntu_base0/apache'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module EacWebappBase0
9
+ module Instances
10
+ class ApachePath
11
+ JOBS = %w[write_available_conf enable_conf reload_apache].freeze
12
+ include ::Avm::Entries::Jobs::Base
13
+
14
+ def content
15
+ ::Avm::EacWebappBase0::Instances::ApachePath.template.child('default.conf')
16
+ .apply(variables_source)
17
+ end
18
+
19
+ def document_root
20
+ instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH)
21
+ end
22
+
23
+ def extra_content
24
+ ''
25
+ end
26
+
27
+ private
28
+
29
+ def apache_uncached
30
+ ::Avm::EacUbuntuBase0::Apache.new(instance.host_env)
31
+ end
32
+
33
+ def enable_conf
34
+ infom 'Enabling configuration...'
35
+ conf.enable
36
+ end
37
+
38
+ def reload_apache
39
+ infom 'Reloading Apache...'
40
+ apache.service('reload')
41
+ end
42
+
43
+ def conf_uncached
44
+ apache.conf(instance.id)
45
+ end
46
+
47
+ def write_available_conf
48
+ infom 'Writing available configuration...'
49
+ conf.write(content)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -4,7 +4,7 @@ require 'avm/instances/base'
4
4
  require 'avm/eac_postgresql_base0/instance_with'
5
5
  require 'avm/data/instance/files_unit'
6
6
  require 'avm/data/instance/package'
7
- require 'avm/eac_webapp_base0/deploy/file_unit'
7
+ require 'avm/eac_webapp_base0/instances/deploy/file_unit'
8
8
  require 'avm/eac_webapp_base0/instances/runners'
9
9
  require 'avm/eac_ubuntu_base0/instances/base'
10
10
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/path_string'
4
+
5
+ module Avm
6
+ module EacWebappBase0
7
+ module Instances
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[OPTION_APPENDED_DIRECTORIES] || []
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/files/appender'
4
+ require 'avm/files/deploy'
5
+ require 'eac_ruby_utils/envs'
6
+ require 'eac_ruby_utils/fs/temp'
7
+
8
+ module Avm
9
+ module EacWebappBase0
10
+ module Instances
11
+ class Deploy
12
+ module Build
13
+ private
14
+
15
+ attr_accessor :build_dir
16
+
17
+ def append_instance_content
18
+ ::Avm::Files::Appender
19
+ .new
20
+ .variables_source_set(variables_source)
21
+ .append_templatized_directory(template.path)
22
+ .append_templatized_directories(appended_directories)
23
+ .append_file_content(version_target_path, version)
24
+ .write_appended_on(build_dir)
25
+ end
26
+
27
+ def build_dir_env
28
+ ::EacRubyUtils::Envs.local
29
+ end
30
+
31
+ def create_build_dir
32
+ self.build_dir = ::EacRubyUtils::Fs::Temp.directory
33
+ end
34
+
35
+ def remove_build_dir
36
+ build_dir&.remove
37
+ end
38
+
39
+ def build_content
40
+ infom 'Writing Git source code...'
41
+ ::Avm::Git::Commit.new(git, commit_sha1).deploy_to_env_path(
42
+ build_dir_env,
43
+ build_dir
44
+ ).variables_source_set(variables_source).run
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module EacWebappBase0
5
+ module Instances
6
+ class Deploy
7
+ class FileUnit < ::SimpleDelegator
8
+ attr_reader :data_key, :fs_path_subpath
9
+
10
+ def initialize(deploy, data_key, fs_path_subpath)
11
+ super(deploy)
12
+ @data_key = data_key
13
+ @fs_path_subpath = fs_path_subpath
14
+ end
15
+
16
+ def run
17
+ assert_source_directory
18
+ link_source_target
19
+ end
20
+
21
+ def assert_source_directory
22
+ infom "Asserting \"#{data_key}\" source directory..."
23
+ instance.host_env.command('mkdir', '-p', source_path).execute!
24
+ end
25
+
26
+ def source_path
27
+ ::File.join(instance.install_data_path, data_key.to_s)
28
+ end
29
+
30
+ def target_path
31
+ ::File.join(instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH),
32
+ fs_path_subpath.to_s)
33
+ end
34
+
35
+ def link_source_target
36
+ infom "Linking \"#{data_key}\" directory..."
37
+ instance.host_env.command('rm', '-rf', target_path).execute!
38
+ instance.host_env.command('ln', '-s', source_path, target_path).execute!
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module EacWebappBase0
5
+ module Instances
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_fetch_uncached
17
+ infom "Fetching remote \"#{git_remote_name}\" from \"#{git_repository_path}\"..."
18
+ git.fetch(git_remote_name)
19
+ end
20
+
21
+ def git_reference
22
+ options[OPTION_REFERENCE] || DEFAULT_REFERENCE
23
+ end
24
+
25
+ def git_reference_found_uncached
26
+ %w[git_reference instance_branch master_branch].map { |b| send(b) }.find(&:present?) ||
27
+ raise(
28
+ ::Avm::Result::Error,
29
+ 'No git reference found (Searched for option, instance and master)'
30
+ )
31
+ end
32
+
33
+ def git_remote_hashs_uncached
34
+ git.remote_hashs(git_remote_name)
35
+ end
36
+
37
+ def git_remote_name
38
+ ::Avm::Git::DEFAULT_REMOTE_NAME
39
+ end
40
+
41
+ def git_repository_path
42
+ instance.source_instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH)
43
+ end
44
+
45
+ def git_uncached
46
+ ::Avm::Launcher::Git::Base.new(git_repository_path)
47
+ end
48
+
49
+ def instance_branch
50
+ remote_branch(instance.id)
51
+ end
52
+
53
+ def remote_branch(name)
54
+ git_remote_hashs.key?("refs/heads/#{name}") ? "#{git_remote_name}/#{name}" : nil
55
+ end
56
+
57
+ def master_branch
58
+ remote_branch('master')
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module EacWebappBase0
5
+ module Instances
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
+
19
+ def version_target_path
20
+ VERSION_TARGET_PATH
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacWebappBase0
7
+ module Instances
8
+ class Deploy
9
+ module WriteOnTarget
10
+ def write_on_target
11
+ ::Avm::Files::Deploy.new(
12
+ instance.host_env,
13
+ instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH)
14
+ ).append_plain_directory(build_dir).run
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/callbacks'
4
+ require 'avm/entries/jobs/base'
5
+ require 'avm/git'
6
+ require 'eac_ruby_utils/core_ext'
7
+ require 'eac_templates/core_ext'
8
+ require 'avm/launcher/git/base'
9
+ require 'net/http'
10
+
11
+ module Avm
12
+ module EacWebappBase0
13
+ module Instances
14
+ class Deploy
15
+ require_sub __FILE__, include_modules: true
16
+
17
+ DEFAULT_REFERENCE = 'HEAD'
18
+
19
+ REQUEST_TEST_JOB = 'request_test'
20
+ JOBS = (%w[create_build_dir build_content append_instance_content write_on_target
21
+ setup_files_units assert_instance_branch] + [REQUEST_TEST_JOB]).freeze
22
+
23
+ include ::Avm::Entries::Jobs::Base
24
+
25
+ lists.add_symbol :option, :appended_directories, :no_request_test, :reference
26
+
27
+ def option_list
28
+ ::Avm::EacWebappBase0::Instances::Deploy.lists.option
29
+ end
30
+
31
+ def run
32
+ super
33
+ ensure
34
+ remove_build_dir
35
+ end
36
+
37
+ def start_banner
38
+ infov 'Instance', instance
39
+ infov 'Git reference (User)', git_reference.if_present('- BLANK -')
40
+ infov 'Git remote name', git_remote_name
41
+ infov 'Git reference (Found)', git_reference_found
42
+ infov 'Git commit SHA1', commit_sha1
43
+ infov 'Appended directories', appended_directories
44
+ end
45
+
46
+ def setup_files_units
47
+ instance.class.const_get('FILES_UNITS').each do |data_key, fs_path_subpath|
48
+ FileUnit.new(self, data_key, fs_path_subpath).run
49
+ end
50
+ end
51
+
52
+ def assert_instance_branch
53
+ infom 'Setting instance branch...'
54
+ git.execute!('push', git_remote_name, "#{commit_sha1}:refs/heads/#{instance.id}", '-f')
55
+ end
56
+
57
+ def request_test
58
+ infom 'Requesting web interface...'
59
+ uri = URI(instance.read_entry('web.url'))
60
+ response = ::Net::HTTP.get_response(uri)
61
+ infov 'Response status', response.code
62
+ fatal_error "Request to #{uri} failed" unless response.code.to_i == 200
63
+ end
64
+
65
+ protected
66
+
67
+ def jobs
68
+ r = super
69
+ r.delete(REQUEST_TEST_JOB) if options[OPTION_NO_REQUEST_TEST]
70
+ r
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacWebappBase0
5
- VERSION = '0.8.0'
5
+ VERSION = '0.9.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-eac_webapp_base0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.42'
19
+ version: '0.45'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.42'
26
+ version: '0.45'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: avm-eac_generic_base0
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.103'
75
+ version: '0.104'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.103'
82
+ version: '0.104'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: eac_ruby_gem_support
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -101,17 +101,17 @@ extensions: []
101
101
  extra_rdoc_files: []
102
102
  files:
103
103
  - lib/avm/eac_webapp_base0.rb
104
- - lib/avm/eac_webapp_base0/apache_host.rb
105
- - lib/avm/eac_webapp_base0/apache_path.rb
106
- - lib/avm/eac_webapp_base0/deploy.rb
107
- - lib/avm/eac_webapp_base0/deploy/appended_directories.rb
108
- - lib/avm/eac_webapp_base0/deploy/build.rb
109
- - lib/avm/eac_webapp_base0/deploy/file_unit.rb
110
- - lib/avm/eac_webapp_base0/deploy/git_info.rb
111
- - lib/avm/eac_webapp_base0/deploy/version.rb
112
- - lib/avm/eac_webapp_base0/deploy/write_on_target.rb
104
+ - lib/avm/eac_webapp_base0/instances/apache_host.rb
105
+ - lib/avm/eac_webapp_base0/instances/apache_path.rb
113
106
  - lib/avm/eac_webapp_base0/instances/base.rb
114
107
  - lib/avm/eac_webapp_base0/instances/base/subcommand_parent.rb
108
+ - lib/avm/eac_webapp_base0/instances/deploy.rb
109
+ - lib/avm/eac_webapp_base0/instances/deploy/appended_directories.rb
110
+ - lib/avm/eac_webapp_base0/instances/deploy/build.rb
111
+ - lib/avm/eac_webapp_base0/instances/deploy/file_unit.rb
112
+ - lib/avm/eac_webapp_base0/instances/deploy/git_info.rb
113
+ - lib/avm/eac_webapp_base0/instances/deploy/version.rb
114
+ - lib/avm/eac_webapp_base0/instances/deploy/write_on_target.rb
115
115
  - lib/avm/eac_webapp_base0/instances/runners.rb
116
116
  - lib/avm/eac_webapp_base0/instances/runners/apache_host.rb
117
117
  - lib/avm/eac_webapp_base0/instances/runners/apache_path.rb
@@ -123,8 +123,8 @@ files:
123
123
  - lib/avm/eac_webapp_base0/sources.rb
124
124
  - lib/avm/eac_webapp_base0/sources/base.rb
125
125
  - lib/avm/eac_webapp_base0/version.rb
126
- - template/avm/eac_webapp_base0/apache_host/no_ssl.conf
127
- - template/avm/eac_webapp_base0/apache_path/default.conf
126
+ - template/avm/eac_webapp_base0/instances/apache_host/no_ssl.conf
127
+ - template/avm/eac_webapp_base0/instances/apache_path/default.conf
128
128
  homepage:
129
129
  licenses: []
130
130
  metadata: {}
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'avm/jobs/base'
5
- require 'avm/eac_ubuntu_base0/apache'
6
- require 'eac_templates/core_ext'
7
-
8
- module Avm
9
- module EacWebappBase0
10
- class ApacheHost
11
- APACHE_DIRECTORY_EXTRA_CONFIG_KEY = 'install.apache_directory_extra_config'
12
- JOBS = %w[write_available_no_ssl_site enable_no_ssl_site remove_ssl_site reload_apache
13
- run_certbot enable_ssl_site reload_apache].freeze
14
- include ::Avm::Jobs::Base
15
-
16
- def directory_extra_config
17
- instance.entry(APACHE_DIRECTORY_EXTRA_CONFIG_KEY).value.if_present { |v| " #{v}\n" }
18
- end
19
-
20
- def no_ssl_site_content
21
- ::Avm::EacWebappBase0::ApacheHost
22
- .template.child('no_ssl.conf')
23
- .apply(variables_source)
24
- end
25
-
26
- def ssl?
27
- options[:certbot]
28
- end
29
-
30
- private
31
-
32
- def apache_uncached
33
- ::Avm::EacUbuntuBase0::Apache.new(instance.host_env)
34
- end
35
-
36
- def enable_no_ssl_site
37
- infom 'Enabling no SSL site...'
38
- no_ssl_site.enable
39
- end
40
-
41
- def enable_ssl_site
42
- return unless ssl?
43
-
44
- infom 'Enabling SSL site...'
45
- ssl_site.enable
46
- end
47
-
48
- def no_ssl_site_uncached
49
- apache.site(instance.id)
50
- end
51
-
52
- def reload_apache
53
- infom 'Reloading Apache...'
54
- apache.service('reload')
55
- end
56
-
57
- def remove_ssl_site
58
- infom 'Removing SSL site...'
59
- ssl_site.remove
60
- end
61
-
62
- def run_certbot
63
- return unless ssl?
64
-
65
- infom 'Running Certbot...'
66
- instance.host_env.command(
67
- 'sudo', 'certbot', '--apache', '--domain', instance.read_entry('web.hostname'),
68
- '--redirect', '--non-interactive', '--agree-tos',
69
- '--email', instance.install_email
70
- ).system!
71
- end
72
-
73
- def ssl_site_uncached
74
- apache.site(no_ssl_site.name + '-le-ssl')
75
- end
76
-
77
- def write_available_no_ssl_site
78
- infom 'Writing no SSL site conf...'
79
- no_ssl_site.write(no_ssl_site_content)
80
- end
81
- end
82
- end
83
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/jobs/base'
4
- require 'avm/eac_ubuntu_base0/apache'
5
- require 'eac_ruby_utils/core_ext'
6
-
7
- module Avm
8
- module EacWebappBase0
9
- class ApachePath
10
- JOBS = %w[write_available_conf enable_conf reload_apache].freeze
11
- include ::Avm::Jobs::Base
12
-
13
- def content
14
- ::Avm::EacWebappBase0::ApachePath.template.child('default.conf').apply(variables_source)
15
- end
16
-
17
- def document_root
18
- instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH)
19
- end
20
-
21
- def extra_content
22
- ''
23
- end
24
-
25
- private
26
-
27
- def apache_uncached
28
- ::Avm::EacUbuntuBase0::Apache.new(instance.host_env)
29
- end
30
-
31
- def enable_conf
32
- infom 'Enabling configuration...'
33
- conf.enable
34
- end
35
-
36
- def reload_apache
37
- infom 'Reloading Apache...'
38
- apache.service('reload')
39
- end
40
-
41
- def conf_uncached
42
- apache.conf(instance.id)
43
- end
44
-
45
- def write_available_conf
46
- infom 'Writing available configuration...'
47
- conf.write(content)
48
- end
49
- end
50
- end
51
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/path_string'
4
-
5
- module Avm
6
- module EacWebappBase0
7
- class Deploy
8
- module AppendedDirectories
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[OPTION_APPENDED_DIRECTORIES] || []
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/files/appender'
4
- require 'avm/files/deploy'
5
- require 'eac_ruby_utils/envs'
6
- require 'eac_ruby_utils/fs/temp'
7
-
8
- module Avm
9
- module EacWebappBase0
10
- class Deploy
11
- module Build
12
- private
13
-
14
- attr_accessor :build_dir
15
-
16
- def append_instance_content
17
- ::Avm::Files::Appender
18
- .new
19
- .variables_source_set(variables_source)
20
- .append_templatized_directory(template.path)
21
- .append_templatized_directories(appended_directories)
22
- .append_file_content(version_target_path, version)
23
- .write_appended_on(build_dir)
24
- end
25
-
26
- def build_dir_env
27
- ::EacRubyUtils::Envs.local
28
- end
29
-
30
- def create_build_dir
31
- self.build_dir = ::EacRubyUtils::Fs::Temp.directory
32
- end
33
-
34
- def remove_build_dir
35
- build_dir&.remove
36
- end
37
-
38
- def build_content
39
- infom 'Writing Git source code...'
40
- ::Avm::Git::Commit.new(git, commit_sha1).deploy_to_env_path(
41
- build_dir_env,
42
- build_dir
43
- ).variables_source_set(variables_source).run
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module EacWebappBase0
5
- class Deploy
6
- class FileUnit < ::SimpleDelegator
7
- attr_reader :data_key, :fs_path_subpath
8
-
9
- def initialize(deploy, data_key, fs_path_subpath)
10
- super(deploy)
11
- @data_key = data_key
12
- @fs_path_subpath = fs_path_subpath
13
- end
14
-
15
- def run
16
- assert_source_directory
17
- link_source_target
18
- end
19
-
20
- def assert_source_directory
21
- infom "Asserting \"#{data_key}\" source directory..."
22
- instance.host_env.command('mkdir', '-p', source_path).execute!
23
- end
24
-
25
- def source_path
26
- ::File.join(instance.install_data_path, data_key.to_s)
27
- end
28
-
29
- def target_path
30
- ::File.join(instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH),
31
- fs_path_subpath.to_s)
32
- end
33
-
34
- def link_source_target
35
- infom "Linking \"#{data_key}\" directory..."
36
- instance.host_env.command('rm', '-rf', target_path).execute!
37
- instance.host_env.command('ln', '-s', source_path, target_path).execute!
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module EacWebappBase0
5
- class Deploy
6
- module GitInfo
7
- def commit_sha1_uncached
8
- git_fetch
9
- r = git.rev_parse(git_reference_found)
10
- return r if r
11
-
12
- raise ::Avm::Result::Error, "No commit SHA1 found for \"#{git_reference_found}\""
13
- end
14
-
15
- def git_fetch_uncached
16
- infom "Fetching remote \"#{git_remote_name}\" from \"#{git_repository_path}\"..."
17
- git.fetch(git_remote_name)
18
- end
19
-
20
- def git_reference
21
- options[OPTION_REFERENCE] || DEFAULT_REFERENCE
22
- end
23
-
24
- def git_reference_found_uncached
25
- %w[git_reference instance_branch master_branch].map { |b| send(b) }.find(&:present?) ||
26
- raise(
27
- ::Avm::Result::Error,
28
- 'No git reference found (Searched for option, instance and master)'
29
- )
30
- end
31
-
32
- def git_remote_hashs_uncached
33
- git.remote_hashs(git_remote_name)
34
- end
35
-
36
- def git_remote_name
37
- ::Avm::Git::DEFAULT_REMOTE_NAME
38
- end
39
-
40
- def git_repository_path
41
- instance.source_instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH)
42
- end
43
-
44
- def git_uncached
45
- ::Avm::Launcher::Git::Base.new(git_repository_path)
46
- end
47
-
48
- def instance_branch
49
- remote_branch(instance.id)
50
- end
51
-
52
- def remote_branch(name)
53
- git_remote_hashs.key?("refs/heads/#{name}") ? "#{git_remote_name}/#{name}" : nil
54
- end
55
-
56
- def master_branch
57
- remote_branch('master')
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module EacWebappBase0
5
- class Deploy
6
- module Version
7
- VERSION_TARGET_PATH = 'VERSION'
8
-
9
- def version
10
- ([::Time.now, commit_sha1] + version_git_refs).join('|')
11
- end
12
-
13
- def version_git_refs
14
- git_remote_hashs.select { |_name, sha1| sha1 == commit_sha1 }.keys
15
- .map { |ref| ref.gsub(%r{\Arefs/}, '') }.reject { |ref| ref == 'HEAD' }
16
- end
17
-
18
- def version_target_path
19
- VERSION_TARGET_PATH
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module EacWebappBase0
7
- class Deploy
8
- module WriteOnTarget
9
- def write_on_target
10
- ::Avm::Files::Deploy.new(
11
- instance.host_env,
12
- instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH)
13
- ).append_plain_directory(build_dir).run
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/callbacks'
4
- require 'avm/jobs/base'
5
- require 'avm/git'
6
- require 'eac_ruby_utils/core_ext'
7
- require 'eac_templates/core_ext'
8
- require 'avm/launcher/git/base'
9
- require 'net/http'
10
-
11
- module Avm
12
- module EacWebappBase0
13
- class Deploy
14
- require_sub __FILE__, include_modules: true
15
-
16
- DEFAULT_REFERENCE = 'HEAD'
17
-
18
- REQUEST_TEST_JOB = 'request_test'
19
- JOBS = (%w[create_build_dir build_content append_instance_content write_on_target
20
- setup_files_units assert_instance_branch] + [REQUEST_TEST_JOB]).freeze
21
-
22
- include ::Avm::Jobs::Base
23
-
24
- lists.add_symbol :option, :appended_directories, :no_request_test, :reference
25
-
26
- def option_list
27
- ::Avm::EacWebappBase0::Deploy.lists.option
28
- end
29
-
30
- def run
31
- super
32
- ensure
33
- remove_build_dir
34
- end
35
-
36
- def start_banner
37
- infov 'Instance', instance
38
- infov 'Git reference (User)', git_reference.if_present('- BLANK -')
39
- infov 'Git remote name', git_remote_name
40
- infov 'Git reference (Found)', git_reference_found
41
- infov 'Git commit SHA1', commit_sha1
42
- infov 'Appended directories', appended_directories
43
- end
44
-
45
- def setup_files_units
46
- instance.class.const_get('FILES_UNITS').each do |data_key, fs_path_subpath|
47
- FileUnit.new(self, data_key, fs_path_subpath).run
48
- end
49
- end
50
-
51
- def assert_instance_branch
52
- infom 'Setting instance branch...'
53
- git.execute!('push', git_remote_name, "#{commit_sha1}:refs/heads/#{instance.id}", '-f')
54
- end
55
-
56
- def request_test
57
- infom 'Requesting web interface...'
58
- uri = URI(instance.read_entry('web.url'))
59
- response = ::Net::HTTP.get_response(uri)
60
- infov 'Response status', response.code
61
- fatal_error "Request to #{uri} failed" unless response.code.to_i == 200
62
- end
63
-
64
- protected
65
-
66
- def jobs
67
- r = super
68
- r.delete(REQUEST_TEST_JOB) if options[OPTION_NO_REQUEST_TEST]
69
- r
70
- end
71
- end
72
- end
73
- end