capistrano-net_storage 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,148 +1,58 @@
1
- unless defined?(Capistrano::NetStorage::TASK_LOADED) # prevent multiple loads
2
- Capistrano::NetStorage::TASK_LOADED = true
3
-
1
+ # SEE: https://github.com/capistrano/capistrano/blob/31e142d56f8d894f28404fb225dcdbe7539bda18/lib/capistrano/scm/tasks/git.rake
4
2
  namespace :net_storage do
5
- # Tasks called by deploy.rake bundled in capistrano core:
6
- # - :check
7
- # - :create_release
8
- # - :set_current_revision
9
- desc %(Check all components' statuses)
10
- check_dependencies = %w(archiver transport bundler scm directories).map do |t|
11
- "net_storage:check:#{t}".to_sym
12
- end
13
- task check: check_dependencies
3
+ desc 'Check prerequisites and prepare directories'
4
+ task :check do
5
+ Capistrano::NetStorage.transport.check
6
+ Capistrano::NetStorage.archiver.check
7
+ Capistrano::NetStorage.scm.check
8
+ Capistrano::NetStorage.bundler.check
9
+ Capistrano::NetStorage.cleaner.check
10
+ Capistrano::NetStorage.config_uploader.check
14
11
 
15
- desc 'Create and deploy archives via remove storage'
16
- task create_release: :'net_storage:check' do
17
12
  config = Capistrano::NetStorage.config
18
- skip_upload = false
19
- if config.archive_on_missing?
20
- invoke 'net_storage:transport:find_uploaded'
21
- if fetch(:net_storage_uploaded_archive)
22
- skip_upload = true
23
- end
24
- end
25
- unless skip_upload
26
- invoke 'net_storage:upload_archive'
13
+ run_locally do
14
+ execute(:mkdir, '-p',
15
+ config.local_base_path,
16
+ config.local_mirror_path,
17
+ config.local_releases_path,
18
+ config.local_archives_path,
19
+ )
27
20
  end
28
- invoke 'net_storage:pull_deploy'
29
21
  end
30
22
 
31
- desc 'Set the revision to be deployed'
32
- task set_current_revision: :'net_storage:scm:update' do
33
- Capistrano::NetStorage.scm.set_current_revision
23
+ task :prepare_mirror_repository do
24
+ Capistrano::NetStorage.scm.clone
25
+ Capistrano::NetStorage.scm.update
26
+ Capistrano::NetStorage.scm.set_current_revision # :current_revision is set here, not in net_storage:set_current_revision
34
27
  end
35
28
 
36
- # Additional tasks for capistrano-net_storage
37
-
38
- desc 'Deploy config files'
39
- task :sync_config do
40
- config = Capistrano::NetStorage.config
41
- Capistrano::NetStorage.scm.sync_config
42
- Capistrano::NetStorage.bundler.sync_config unless config.skip_bundle?
43
- end
44
- after 'net_storage:create_release', 'net_storage:sync_config'
45
-
46
- desc 'Clean up old release directories on local'
47
- task :cleanup_local_releases do
48
- Capistrano::NetStorage.cleaner.cleanup_local_releases
49
- end
50
- after 'deploy:cleanup', 'net_storage:cleanup_local_releases'
51
-
52
- desc 'Clean up old archive files on remote storage'
53
- task :cleanup_archives_on_remote_storage do
54
- transport = Capistrano::NetStorage.transport
55
- next unless transport.respond_to?(:cleanup)
56
- transport.cleanup
57
- end
58
- after 'deploy:cleanup', 'net_storage:cleanup_archives_on_remote_storage'
59
-
60
- desc 'Clean up old archive files on remote servers'
61
- task :cleanup_archives do
62
- Capistrano::NetStorage.cleaner.cleanup_archives
63
- end
64
- after 'deploy:cleanup', 'net_storage:cleanup_archives'
65
-
66
- desc 'Clean up old archive files on local'
67
- task :cleanup_local_archives do
68
- Capistrano::NetStorage.cleaner.cleanup_local_archives
69
- end
70
- after 'deploy:cleanup', 'net_storage:cleanup_local_archives'
71
-
72
- task prepare_archive: %i(net_storage:scm:update net_storage:check:bundler) do
73
- config = Capistrano::NetStorage.config
29
+ desc 'Prepare archive (You can hook your own preparation after this)'
30
+ task :prepare_archive do
74
31
  Capistrano::NetStorage.scm.prepare_archive
75
- Capistrano::NetStorage.bundler.install unless config.skip_bundle?
32
+ Capistrano::NetStorage.bundler.install
76
33
  end
77
34
 
78
- desc 'Create archive to release on local'
79
- task create_archive: :'net_storage:prepare_archive' do
80
- Capistrano::NetStorage.archiver.archive
81
- end
35
+ desc 'Create and deploy archives via remove storage'
36
+ task create_release: :'net_storage:prepare_mirror_repository' do
37
+ config = Capistrano::NetStorage.config
82
38
 
83
- desc 'Upload archive onto remote storage'
84
- task upload_archive: :'net_storage:create_archive' do
85
- Capistrano::NetStorage.transport.upload
86
- end
39
+ if !config.reuse_archive? || !Capistrano::NetStorage.transport.archive_exists?
40
+ invoke 'net_storage:prepare_archive'
41
+ Capistrano::NetStorage.archiver.archive
42
+ Capistrano::NetStorage.transport.upload
43
+ end
87
44
 
88
- desc 'Deploy via remote storage using uploaded archive'
89
- task pull_deploy: :'net_storage:transport:find_uploaded' do
90
45
  Capistrano::NetStorage.transport.download
91
46
  Capistrano::NetStorage.archiver.extract
92
- end
93
-
94
- namespace :check do
95
- task :archiver do
96
- Capistrano::NetStorage.archiver.check
97
- end
98
-
99
- task :transport do
100
- Capistrano::NetStorage.transport.check
101
- end
102
-
103
- task :bundler do
104
- config = Capistrano::NetStorage.config
105
- Capistrano::NetStorage.bundler.check unless config.skip_bundle?
106
- end
107
47
 
108
- task :scm do
109
- Capistrano::NetStorage.scm.check
110
- end
111
-
112
- task :directories do
113
- config = Capistrano::NetStorage.config
114
- dirs = [
115
- config.local_base_path,
116
- config.local_mirror_path,
117
- config.local_releases_path,
118
- config.local_archives_path,
119
- ]
120
- dirs << config.local_bundle_path unless config.skip_bundle?
121
- run_locally do
122
- dirs.each { |dir| execute :mkdir, '-p', dir }
123
- end
124
- end
48
+ Capistrano::NetStorage.config_uploader.upload_config_files
125
49
  end
126
50
 
127
- namespace :scm do
128
- task clone: %i(net_storage:check:scm net_storage:check:directories) do
129
- Capistrano::NetStorage.scm.clone
130
- end
131
-
132
- task update: :'net_storage:scm:clone' do
133
- Capistrano::NetStorage.scm.update
134
- end
135
-
136
- task set_current_revision: :'net_storage:scm:update' do
137
- Capistrano::NetStorage.scm.set_current_revision
138
- end
139
- end
140
-
141
- namespace :transport do
142
- task find_uploaded: :'net_storage:scm:set_current_revision' do
143
- Capistrano::NetStorage.transport.find_uploaded
144
- end
51
+ desc 'Clean up old release directories on local'
52
+ task :cleanup do
53
+ Capistrano::NetStorage.cleaner.cleanup_local_releases
54
+ Capistrano::NetStorage.cleaner.cleanup_local_archives
55
+ Capistrano::NetStorage.cleaner.cleanup_archives
56
+ Capistrano::NetStorage.transport.cleanup
145
57
  end
146
58
  end
147
-
148
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-net_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - progrhyme
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-20 00:00:00.000000000 Z
11
+ date: 2023-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -16,42 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.3.3
19
+ version: '3.7'
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: 3.3.3
27
- - !ruby/object:Gem::Dependency
28
- name: parallel
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '3.7'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '2.1'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '2.1'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -97,15 +83,13 @@ dependencies:
97
83
  description: |2
98
84
  A Capistrano SCM Plugin to deploy application via remove storage.
99
85
  Logically, this enables O(1) deployment.
100
- email:
86
+ email:
101
87
  executables: []
102
88
  extensions: []
103
89
  extra_rdoc_files: []
104
90
  files:
105
- - ".github/PULL_REQUEST_TEMPLATE.md"
106
91
  - ".gitignore"
107
92
  - ".rspec"
108
- - ".travis.yml"
109
93
  - CHANGELOG.md
110
94
  - Gemfile
111
95
  - LICENSE.txt
@@ -114,28 +98,25 @@ files:
114
98
  - capistrano-net_storage.gemspec
115
99
  - lib/capistrano-net_storage.rb
116
100
  - lib/capistrano/net_storage.rb
117
- - lib/capistrano/net_storage/all.rb
118
101
  - lib/capistrano/net_storage/archiver/base.rb
119
102
  - lib/capistrano/net_storage/archiver/tar_gzip.rb
120
103
  - lib/capistrano/net_storage/archiver/zip.rb
121
- - lib/capistrano/net_storage/base.rb
122
- - lib/capistrano/net_storage/bundler.rb
104
+ - lib/capistrano/net_storage/bundler/default.rb
105
+ - lib/capistrano/net_storage/bundler/null.rb
123
106
  - lib/capistrano/net_storage/cleaner.rb
124
107
  - lib/capistrano/net_storage/config.rb
125
- - lib/capistrano/net_storage/coordinator.rb
126
- - lib/capistrano/net_storage/error.rb
108
+ - lib/capistrano/net_storage/config_uploader.rb
127
109
  - lib/capistrano/net_storage/plugin.rb
128
110
  - lib/capistrano/net_storage/scm/base.rb
129
111
  - lib/capistrano/net_storage/scm/git.rb
130
112
  - lib/capistrano/net_storage/transport/base.rb
131
- - lib/capistrano/net_storage/utils.rb
132
113
  - lib/capistrano/net_storage/version.rb
133
114
  - lib/capistrano/tasks/net_storage.rake
134
115
  homepage: https://github.com/DeNADev/capistrano-net_storage
135
116
  licenses:
136
117
  - MIT
137
118
  metadata: {}
138
- post_install_message:
119
+ post_install_message:
139
120
  rdoc_options: []
140
121
  require_paths:
141
122
  - lib
@@ -143,15 +124,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
124
  requirements:
144
125
  - - ">="
145
126
  - !ruby/object:Gem::Version
146
- version: '2.0'
127
+ version: '2.7'
147
128
  required_rubygems_version: !ruby/object:Gem::Requirement
148
129
  requirements:
149
130
  - - ">="
150
131
  - !ruby/object:Gem::Version
151
132
  version: '0'
152
133
  requirements: []
153
- rubygems_version: 3.0.3
154
- signing_key:
134
+ rubygems_version: 3.4.13
135
+ signing_key:
155
136
  specification_version: 4
156
137
  summary: Capistrano SCM Plugin for fast deployment via remote storage
157
138
  test_files: []
@@ -1,7 +0,0 @@
1
- ### Summary
2
-
3
- ### Other Information
4
-
5
- ### Checklist
6
-
7
- * [ ] By placing an "x" in the box, I hereby understand, accept and agree to be bound by the terms and conditions of the [Contribution License Agreement](https://dena.github.io/cla/).
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.6.3
5
- - 2.5.5
6
- - 2.4.6
7
-
8
- before_install: gem install bundler
9
- install: bundle install
10
- script: bundle exec rake spec
11
- notifications:
12
- slack:
13
- secure: lJCLJetpFwFujt467h250JgTyjF+7qU04Ef6FdwOBZwvjgYmyyZMBhdbL2JOAxrQd6XCWhZy56jCXr4ZdMbMLtzL+wEkQefiOLdpV/556xXK5qmkjLyRWoYOMFEhxSTqjk8hHZVYcLO6IYmwr9CHBWaVGOydADCkR4CYyqmSHtKIbznSs9Y4qrpsf6YC9QiSxoP7d5hayvnVUI8oFvxC8DfPuwrmWoO4WyVTJy2ODg/r/ZNGJCMzW3pvnXGK5oZqgwArlGIV7l3tOX2l24QilkhxhuX7QRCikYoGiIdXqkXdf1S/piaflFGXJ1C2PN5aWEv1/8EYcm7RgPm8I9Pol+7zkpUFUiSj3FDLc/TZZKP7OwPCpXOXZkDTLn0+96H5oWUR+2xwTwETQpW8Qz6ZMiu4EKAiAeU99YgSZOgc3fmonvsQREFwTV1n9AHPFsTHv8f3bzC8gUm3n7PIZX4/vR7Aa+vTVZ1QGW9T7OuWThdCMVVB7L7Q/5pRaE+gFLsN9MQBfbZ5uOOXYHd+yh9rC5qi/wRXPxQ4w1F8R+iKIhF32nUF96jwwCkd7O/LZKlmFRT43App6sfmQIAdPp7Oy/BZZD34u0k5aOciZ59h10+BHmA1E0kphXfbYcbXd53MUCEiYc4HC2xtC5yT+ko+PQ2T37VkkneZIIhjRf+WzXQ=
@@ -1,20 +0,0 @@
1
- require 'capistrano/net_storage/base'
2
- require 'capistrano/net_storage/error'
3
- require 'capistrano/net_storage/config'
4
- require 'capistrano/net_storage/coordinator'
5
- require 'capistrano/net_storage/utils'
6
- require 'capistrano/net_storage/bundler'
7
- require 'capistrano/net_storage/cleaner'
8
- require 'capistrano/net_storage/archiver/zip'
9
- require 'capistrano/net_storage/archiver/tar_gzip'
10
- require 'capistrano/net_storage/scm/git'
11
- require 'capistrano/net_storage/version'
12
-
13
- # See capistrano/net_storage/base.rb
14
- Capistrano::NetStorage.setup! do
15
- config = Capistrano::NetStorage::Config.new
16
- {
17
- config: config,
18
- coordinator: Capistrano::NetStorage::Coordinator.new(config),
19
- }
20
- end
@@ -1,18 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Capistrano
4
- module NetStorage
5
- class << self
6
- attr_reader :config, :coordinator
7
-
8
- extend Forwardable
9
- def_delegators :coordinator, :archiver, :scm, :cleaner, :bundler, :transport
10
- end
11
-
12
- def self.setup!(params = nil)
13
- params ||= yield
14
- @config = params[:config]
15
- @coordinator = params[:coordinator]
16
- end
17
- end
18
- end
@@ -1,70 +0,0 @@
1
- require 'bundler'
2
- require 'capistrano/net_storage/utils'
3
-
4
- module Capistrano
5
- module NetStorage
6
- class Bundler
7
- include Capistrano::NetStorage::Utils
8
-
9
- def check
10
- run_locally do
11
- execute :which, 'bundle'
12
- end
13
- end
14
-
15
- # Do bundle install locally. Installed gems are to be included to the release.
16
- def install
17
- c = config
18
- run_locally do
19
- local_release_bundle_path = c.local_release_path.join('vendor', 'bundle')
20
- execute :mkdir, '-p', local_release_bundle_path
21
- execute :mkdir, '-p', "#{c.local_release_path}/.bundle"
22
- # Copy shared gems to release bundle path beforehand to reuse installed previously
23
- execute :rsync, '-a', "#{c.local_bundle_path}/", "#{local_release_bundle_path}/"
24
-
25
- within c.local_release_path do
26
- ::Bundler.with_clean_env do
27
- install_options = %W(
28
- --gemfile #{c.local_release_path}/Gemfile --deployment --quiet
29
- --path #{local_release_bundle_path} --without development test
30
- )
31
- execute :bundle, 'install', *install_options
32
- execute :bundle, 'clean'
33
- # Sync installed gems to shared directory to reuse them next time
34
- rsync_options = %W(-a --delete #{local_release_bundle_path}/ #{c.local_bundle_path}/)
35
- execute :rsync, *rsync_options
36
- end
37
- end
38
- end
39
- end
40
-
41
- # Create +.bundle/config+ at release path on remote servers
42
- def sync_config
43
- c = config
44
-
45
- on c.servers, in: :groups, limit: c.max_parallels do
46
- within release_path do
47
- execute :mkdir, '-p', '.bundle'
48
- end
49
- end
50
-
51
- run_locally do
52
- execute :mkdir, '-p', "#{c.local_base_path}/.bundle"
53
- end
54
- bundle_config_path = "#{c.local_base_path}/.bundle/config"
55
- File.open(bundle_config_path, 'w') do |file|
56
- file.print(<<-EOS)
57
- ---
58
- BUNDLE_FROZEN: "1"
59
- BUNDLE_PATH: "#{release_path.join('vendor', 'bundle')}"
60
- BUNDLE_WITHOUT: "development:test"
61
- BUNDLE_DISABLE_SHARED_GEMS: "true"
62
- BUNDLE_BIN: "#{release_path.join('bin')}"
63
- EOS
64
- end
65
-
66
- upload_files([bundle_config_path], release_path.join('.bundle'))
67
- end
68
- end
69
- end
70
- end
@@ -1,38 +0,0 @@
1
- module Capistrano
2
- module NetStorage
3
- class Coordinator
4
- attr_reader :config
5
-
6
- def initialize(config)
7
- @config = config
8
- end
9
-
10
- def archiver
11
- load_executor(:archiver)
12
- end
13
-
14
- def transport
15
- load_executor(:transport)
16
- end
17
-
18
- def cleaner
19
- load_executor(:cleaner)
20
- end
21
-
22
- def bundler
23
- load_executor(:bundler)
24
- end
25
-
26
- def scm
27
- load_executor(:scm)
28
- end
29
-
30
- private
31
-
32
- def load_executor(type)
33
- @executors ||= {}
34
- @executors[type] ||= config.executor_class(type).new
35
- end
36
- end
37
- end
38
- end
@@ -1,6 +0,0 @@
1
- module Capistrano
2
- module NetStorage
3
- class Error < StandardError
4
- end
5
- end
6
- end
@@ -1,62 +0,0 @@
1
- require 'parallel'
2
-
3
- require 'capistrano/net_storage/base'
4
-
5
- module Capistrano
6
- module NetStorage
7
- # Common utility methods
8
- module Utils
9
- private
10
-
11
- # @see lib/capistrano/net_storage/base.rb
12
- def config
13
- Capistrano::NetStorage.config
14
- end
15
-
16
- # @param dest_dir [String, Pathname] Destination directory on remote to copy local files into
17
- def upload_files(files, dest_dir)
18
- c = config
19
- hosts = ::Capistrano::Configuration.env.filter(c.servers)
20
- if c.upload_files_by_rsync?
21
- Parallel.each(hosts, in_threads: c.max_parallels) do |host|
22
- ssh = build_ssh_command(host)
23
- run_locally do
24
- files.each do |src|
25
- execute :rsync, "-az --rsh='#{ssh}' #{src} #{host}:#{dest_dir}"
26
- end
27
- end
28
- end
29
- else
30
- on c.servers, in: :groups, limit: c.max_parallels do
31
- files.each do |src|
32
- upload! src, dest_dir
33
- end
34
- end
35
- end
36
- end
37
-
38
- # Build ssh command with options for rsync
39
- def build_ssh_command(host)
40
- user_opt = ''
41
- key_opt = ''
42
- port_opt = ''
43
- ssh_options = config.rsync_options
44
-
45
- if user = host.user || ssh_options[:user]
46
- user_opt = " -l #{user}"
47
- end
48
-
49
- if keys = (host.keys.empty? ? ssh_options[:keys] : host.keys)
50
- keys = keys.is_a?(Array) ? keys : [keys]
51
- key_opt = keys.map { |key| " -i #{key}" }.join('')
52
- end
53
-
54
- if port = host.port || ssh_options[:port]
55
- port_opt = " -p #{port}"
56
- end
57
-
58
- "ssh#{user_opt}#{key_opt}#{port_opt}"
59
- end
60
- end
61
- end
62
- end