Class: Capistrano::SCM::S3Archive
- Inherits:
-
Plugin
- Object
- Plugin
- Capistrano::SCM::S3Archive
- Defined in:
- lib/capistrano/scm/s3_archive.rb,
lib/capistrano/scm/s3_archive.rb,
lib/capistrano/scm/s3_archive/local_cache.rb,
lib/capistrano/scm/s3_archive/remote_cache.rb,
lib/capistrano/scm/s3_archive/archive_object.rb
Defined Under Namespace
Classes: ArchiveObject, LocalCache, RemoteCache
Instance Method Summary collapse
- #archive_object ⇒ Object
- #cleanup_local_cache ⇒ Object
- #cleanup_shared_path ⇒ Object
- #current_revision ⇒ Object
- #define_tasks ⇒ Object
- #deploy_to_release_path ⇒ Object
-
#download_to_local_cache ⇒ Object
for rsync.
-
#download_to_shared_path ⇒ Object
for direct.
- #local_cache ⇒ Object
- #local_check ⇒ Object
- #register_hooks ⇒ Object
- #remote_cache ⇒ Object
- #remote_check ⇒ Object
- #rsync_cache_dir ⇒ Object
- #set_defaults ⇒ Object
- #strategy ⇒ Object
- #transfer_sources(dest) ⇒ Object
Instance Method Details
#archive_object ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/capistrano/scm/s3_archive.rb', line 131 def archive_object @archive_object ||= ArchiveObject.new(repo_url: fetch(:repo_url), version_id: fetch(:s3_archive_object_version_id), sort_proc: fetch(:s3_archive_sort_proc), branch: fetch(:branch), client_options: fetch(:s3_archive_client_options)) end |
#cleanup_local_cache ⇒ Object
95 96 97 |
# File 'lib/capistrano/scm/s3_archive.rb', line 95 def cleanup_local_cache local_cache.cleanup(keep: fetch(:keep_releases)) end |
#cleanup_shared_path ⇒ Object
127 128 129 |
# File 'lib/capistrano/scm/s3_archive.rb', line 127 def cleanup_shared_path remote_cache.cleanup(keep: fetch(:keep_releases)) end |
#current_revision ⇒ Object
66 67 68 |
# File 'lib/capistrano/scm/s3_archive.rb', line 66 def current_revision archive_object.current_revision end |
#define_tasks ⇒ Object
17 18 19 |
# File 'lib/capistrano/scm/s3_archive.rb', line 17 def define_tasks eval_rakefile File.("tasks/s3_archive.rake", __dir__) end |
#deploy_to_release_path ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/capistrano/scm/s3_archive.rb', line 70 def deploy_to_release_path case strategy when :direct archive_file = remote_cache.target_file case archive_file when /\.zip\?.*\Z/ backend.execute :unzip, "-q -d", release_path, archive_file when /\.tar\.gz\?.*\Z|\.tar\.bz2\?.*\Z|\.tgz\?.*\Z/ backend.execute :tar, "xf", archive_file, "-C", release_path end when :rsync link_option = if fetch(:s3_archive_hardlink_release) && backend.test("[ `readlink #{current_path}` != #{release_path} ]") "--link-dest `readlink #{current_path}`" end create_release = %[rsync #{fetch(:s3_archive_remote_rsync_copy_option)} #{link_option} "#{rsync_cache_dir}/" "#{release_path}/"] backend.execute create_release end end |
#download_to_local_cache ⇒ Object
for rsync
90 91 92 93 |
# File 'lib/capistrano/scm/s3_archive.rb', line 90 def download_to_local_cache local_cache.download local_cache.extract end |
#download_to_shared_path ⇒ Object
for direct
123 124 125 |
# File 'lib/capistrano/scm/s3_archive.rb', line 123 def download_to_shared_path remote_cache.download end |
#local_cache ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/capistrano/scm/s3_archive.rb', line 147 def local_cache @local_cache ||= LocalCache.new( backend, File.join(fetch(:s3_archive_local_download_dir), fetch(:stage).to_s), File.join(fetch(:s3_archive_local_cache_dir), fetch(:stage).to_s), archive_object ) end |
#local_check ⇒ Object
49 50 51 |
# File 'lib/capistrano/scm/s3_archive.rb', line 49 def local_check archive_object.check_access! end |
#register_hooks ⇒ Object
21 22 23 24 25 |
# File 'lib/capistrano/scm/s3_archive.rb', line 21 def register_hooks after "deploy:new_release_path", "s3_archive:create_release" before "deploy:check", "s3_archive:check" before "deploy:set_current_revision", "s3_archive:set_current_revision" end |
#remote_cache ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/capistrano/scm/s3_archive.rb', line 139 def remote_cache @remote_cache ||= RemoteCache.new( backend, File.join(fetch(:s3_archive_remote_cache_dir), fetch(:stage).to_s), archive_object ) end |
#remote_check ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/capistrano/scm/s3_archive.rb', line 53 def remote_check case strategy when :direct backend.execute :aws, "s3", "ls", ["s3:/", archive_object.bucket, archive_object.key].join("/") when :rsync backend.execute :echo, "ssh connected" end end |
#rsync_cache_dir ⇒ Object
118 119 120 |
# File 'lib/capistrano/scm/s3_archive.rb', line 118 def rsync_cache_dir File.join(deploy_to, fetch(:s3_archive_rsync_cache_dir)) end |
#set_defaults ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/capistrano/scm/s3_archive.rb', line 27 def set_defaults set_if_empty :s3_archive_client_options, {} set_if_empty(:s3_archive_sort_proc, ->(new, old) { old.key <=> new.key }) set_if_empty :s3_archive_strategy, :rsync set_if_empty :s3_archive_object_version_id, nil # strategy direct (alpha) set_if_empty :s3_archive_remote_cache_dir, -> { File.join(shared_path, "archives") } # strategy rsync set_if_empty :s3_archive_skip_download, nil set_if_empty :s3_archive_local_download_dir, "tmp/archives" set_if_empty :s3_archive_local_cache_dir, "tmp/deploy" set_if_empty :s3_archive_remote_rsync_options, ['-az', '--delete'] set_if_empty :s3_archive_remote_rsync_ssh_options, [] set_if_empty :s3_archive_remote_rsync_runner_options, {} set_if_empty :s3_archive_rsync_cache_dir, "shared/deploy" set_if_empty :s3_archive_hardlink_release, false set_if_empty :s3_archive_remote_rsync_copy_option, "--archive --acls --xattrs" end |
#strategy ⇒ Object
62 63 64 |
# File 'lib/capistrano/scm/s3_archive.rb', line 62 def strategy @strategy ||= fetch(:s3_archive_strategy) end |
#transfer_sources(dest) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/capistrano/scm/s3_archive.rb', line 99 def transfer_sources(dest) = [] .concat fetch(:s3_archive_remote_rsync_options, []) << local_cache.cache_dir + "/" if dest.local? << '--no-compress' << rsync_cache_dir else = [] << dest.ssh_key_option unless dest.ssh_key_option.empty? .concat fetch(:s3_archive_remote_rsync_ssh_options) << "-e 'ssh #{.join(' ')}'" unless .empty? << "#{dest.login_user_at}#{dest.hostname}:#{rsync_cache_dir}" end backend.execute :rsync, * end |