Class: Capistrano::GitCopy::Bundle::Utility
- Inherits:
-
Utility
- Object
- Utility
- Capistrano::GitCopy::Bundle::Utility
- Defined in:
- lib/capistrano/git_copy/bundle/utility.rb
Overview
Utility stuff to avoid cluttering of bundle.cap
Instance Method Summary collapse
-
#cache ⇒ Object
Cache used gems.
-
#cached_gemfile_md5 ⇒ String
MD5 sum of Gemfile.lock for local gem cache.
-
#cached_gemfile_md5_path ⇒ String
Path to cache for MD5 sum of Gemfile.lock.
-
#clear_local ⇒ Object
Clear local cached gems.
-
#clear_remote ⇒ Object
Clear remote cached gems.
-
#gemfile_md5 ⇒ String
MD5 sum of Gemfile.lock to deploy.
-
#gems_changed? ⇒ Boolean
Checks if Gemfile.lock has changed since last deploy.
-
#local_cache_path ⇒ String
Path for local bundle cache.
-
#local_gems ⇒ Array
List of filenames for locally cached gems.
-
#remote_cache_path ⇒ String
Path for remote bundle cache.
-
#upload ⇒ Object
Upload cached gems.
Instance Method Details
#cache ⇒ Object
Cache used gems
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 11 def cache local_vendor_path = File.join(repo_path, 'vendor') execute(:mkdir, '-p', local_cache_path) unless test!("[ -d #{local_cache_path} ]") execute(:mkdir, '-p', local_vendor_path) unless test!("[ -d #{local_vendor_path} ]") execute(:ln, '-s', local_cache_path, File.join(local_vendor_path, 'cache')) if gems_changed? Bundler.with_clean_env do execute("bundle package --gemfile #{File.join(repo_path, 'Gemfile')} --all --all-platforms") end File.open(cached_gemfile_md5_path, 'w') { |f| f.write(gemfile_md5) } unless gemfile_md5.nil? end end |
#cached_gemfile_md5 ⇒ String
MD5 sum of Gemfile.lock for local gem cache
85 86 87 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 85 def cached_gemfile_md5 @_cached_gemfile_md5 ||= File.read(cached_gemfile_md5_path) rescue nil end |
#cached_gemfile_md5_path ⇒ String
Path to cache for MD5 sum of Gemfile.lock
92 93 94 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 92 def cached_gemfile_md5_path File.join(tmp_path, 'git_copy_bundle_gemfile_lock.md5') end |
#clear_local ⇒ Object
Clear local cached gems
49 50 51 52 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 49 def clear_local execute(:rm, '-rf', File.join(local_cache_path, '*')) if test!("[ -d #{local_cache_path} ]") File.unlink(cached_gemfile_md5_path) end |
#clear_remote ⇒ Object
Clear remote cached gems
57 58 59 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 57 def clear_remote execute(:rm, '-rf', File.join(remote_cache_path, '*')) if test!("[ -d #{remote_cache_path} ]") end |
#gemfile_md5 ⇒ String
MD5 sum of Gemfile.lock to deploy
78 79 80 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 78 def gemfile_md5 @_gemfile_md5 ||= Digest::MD5.file(File.join(repo_path, 'Gemfile.lock')).hexdigest rescue nil end |
#gems_changed? ⇒ Boolean
Checks if Gemfile.lock has changed since last deploy
99 100 101 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 99 def gems_changed? gemfile_md5.nil? || cached_gemfile_md5.nil? || gemfile_md5 != cached_gemfile_md5 end |
#local_cache_path ⇒ String
Path for local bundle cache
71 72 73 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 71 def local_cache_path File.join(tmp_path, 'bundle_cache') end |
#local_gems ⇒ Array
List of filenames for locally cached gems
106 107 108 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 106 def local_gems %x(ls #{local_cache_path}).split(/\s+/) end |
#remote_cache_path ⇒ String
Path for remote bundle cache
64 65 66 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 64 def remote_cache_path File.join(shared_path, 'bundle', 'cache') end |
#upload ⇒ Object
Upload cached gems
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/capistrano/git_copy/bundle/utility.rb', line 31 def upload vendor_path = File.join(release_path, 'vendor') execute(:mkdir, '-p', remote_cache_path) unless test!("[ -d #{remote_cache_path} ]") execute(:mkdir, '-p', vendor_path) unless test!("[ -d #{vendor_path} ]") execute(:ln, '-s', remote_cache_path, File.join(vendor_path, 'cache')) remote_gems = capture(:ls, remote_cache_path).split(/\s+/) (local_gems - remote_gems).each do |file| upload!(File.join(local_cache_path, file), File.join(remote_cache_path, file), recursive: true) end end |