capistrano-git-copy-bundle 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 279dec3ad87eb26598309202ae710e8d56a48168
4
+ data.tar.gz: d3264a4fa769f780137897833859e0b4b1a6142f
5
+ SHA512:
6
+ metadata.gz: 2b3d8d8c19d9f0271023175873a304d110574d3afa97d7927acabd665151f9c5827bcbe4d437cd7582eac1a89913fe090d1f8ca56c9439e4a6182ce371d4edb5
7
+ data.tar.gz: be90b7e6c971904055c0aeac706d9de87a16cf2434c57a0d8429ad361eea13dcc217df402d93555ee40145ed47a5f8f44cd8e99484b09a0477dfcc6f62a731d3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ ## 0.1.0 (2015-08-26)
4
+ ### Changes
5
+ - Package gems
6
+ - Check for changes to prevent uploading of all gems on every deploy
7
+ - Allow caching before actual deploy with standalone task
8
+ - Task to clear local and remote cache
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-git-copy-bundle.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Florian Schwab
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ [![Gem Version](https://img.shields.io/gem/v/capistrano-git-copy-bundle.svg)](https://rubygems.org/gems/capistrano-git-copy-bundle)
2
+ [![Dependencies](https://img.shields.io/gemnasium/ydkn/capistrano-git-copy-bundle.svg)](https://gemnasium.com/ydkn/capistrano-git-copy-bundle)
3
+ [![Code Climate](https://img.shields.io/codeclimate/github/ydkn/capistrano-git-copy-bundle.svg)](https://codeclimate.com/github/ydkn/capistrano-git-copy-bundle)
4
+
5
+ [![Join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ydkn/capistrano-git-copy-bundle)
6
+
7
+
8
+ # Capistrano::GitCopy::Bundle
9
+
10
+ Packages gems locally and uploads them to the remote server instead of fetching them on the remote server.
11
+
12
+ ## Setup
13
+
14
+ Add the library to your `Gemfile`:
15
+
16
+ ```ruby
17
+ group :development do
18
+ gem 'capistrano-git-copy-bundle', require: false, github: 'ydkn/capistrano-git-copy-bundle'
19
+ end
20
+ ```
21
+
22
+ And require it in your `Capfile`:
23
+
24
+ ```ruby
25
+ require 'capistrano/git_copy/bundle'
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Packaging and uploading will happen automatically.
31
+
32
+ If you are required to package your gems before the actual deploy (e.g. using a VPN without internet access) it is possible to run the following task to prefetch the gems so it won't run on deploy:
33
+
34
+ ```
35
+ $ cap production git_copy:bundle:cache
36
+ ```
37
+
38
+ If you want to clear the local and remote gem cache you can run:
39
+
40
+ ```
41
+ $ cap production git_copy:bundle:clear
42
+ ```
43
+
44
+ ## Known issues
45
+
46
+ * Currently it is not possible to package all platform versions of a gem (https://github.com/bundler/bundler-features/issues/4). However, gems can be added manually to `<shared_path>/bundle/cache`.
47
+
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/git_copy/bundle/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano-git-copy-bundle'
8
+ spec.version = Capistrano::GitCopy::Bundle::VERSION
9
+ spec.authors = ['Florian Schwab']
10
+ spec.email = ['me@ydkn.de']
11
+
12
+ spec.summary = %q{Packages gems locally and uploads them to the remote server instead of fetching them on the remote server.}
13
+ spec.description = %q{Packages gems locally and uploads them to the remote server instead of fetching them on the remote server.}
14
+ spec.homepage = 'https://github.com/ydkn/capistrano-git-copy-bundle'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'bundler', '~> 1.9'
22
+ spec.add_dependency 'capistrano-bundler', '~> 1.1'
23
+ spec.add_dependency 'capistrano-git-copy', '~> 1.0'
24
+
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'yard'
27
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/bundle.cap', __FILE__)
@@ -0,0 +1,39 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :bundle_flags, "#{fetch(:bundle_flags)} --local"
4
+ end
5
+ end
6
+
7
+ namespace :git_copy do
8
+ namespace :bundle do
9
+ def git_copy_bundle_utility
10
+ @git_copy_bundle_utility ||= Capistrano::GitCopy::Bundle::Utility.new(self)
11
+ end
12
+
13
+ task upload: :'git_copy:bundle:cache' do
14
+ on release_roles :all do
15
+ git_copy_bundle_utility.upload
16
+ end
17
+ end
18
+
19
+ task cache: :'git_copy:update' do
20
+ run_locally do
21
+ git_copy_bundle_utility.cache
22
+ end
23
+ end
24
+
25
+ desc 'Clear bundle cache'
26
+ task :clear do
27
+ run_locally do
28
+ git_copy_bundle_utility.clear_local
29
+ end
30
+
31
+ on release_roles :all do
32
+ git_copy_bundle_utility.clear_remote
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+
39
+ before 'bundler:install', 'git_copy:bundle:upload'
@@ -0,0 +1,112 @@
1
+ require 'capistrano/git_copy/utility'
2
+
3
+ module Capistrano
4
+ module GitCopy
5
+ module Bundle
6
+ # Utility stuff to avoid cluttering of bundle.cap
7
+ class Utility < ::Capistrano::GitCopy::Utility
8
+ # Cache used gems
9
+ #
10
+ # @return void
11
+ def cache
12
+ local_vendor_path = File.join(repo_path, 'vendor')
13
+
14
+ execute(:mkdir, '-p', local_cache_path) unless test!("[ -d #{local_cache_path} ]")
15
+ execute(:mkdir, '-p', local_vendor_path) unless test!("[ -d #{local_vendor_path} ]")
16
+
17
+ execute(:ln, '-s', local_cache_path, File.join(local_vendor_path, 'cache'))
18
+
19
+ if gems_changed?
20
+ Bundler.with_clean_env do
21
+ execute("bundle package --gemfile #{File.join(repo_path, 'Gemfile')} --all --all-platforms")
22
+ end
23
+
24
+ File.open(cached_gemfile_md5_path, 'w') { |f| f.write(gemfile_md5) } unless gemfile_md5.nil?
25
+ end
26
+ end
27
+
28
+ # Upload cached gems
29
+ #
30
+ # @return void
31
+ def upload
32
+ vendor_path = File.join(release_path, 'vendor')
33
+
34
+ execute(:mkdir, '-p', remote_cache_path) unless test!("[ -d #{remote_cache_path} ]")
35
+ execute(:mkdir, '-p', vendor_path) unless test!("[ -d #{vendor_path} ]")
36
+
37
+ execute(:ln, '-s', remote_cache_path, File.join(vendor_path, 'cache'))
38
+
39
+ remote_gems = capture(:ls, remote_cache_path).split(/\s+/)
40
+
41
+ (local_gems - remote_gems).each do |file|
42
+ upload!(File.join(local_cache_path, file), File.join(remote_cache_path, file), recursive: true)
43
+ end
44
+ end
45
+
46
+ # Clear local cached gems
47
+ #
48
+ # @return void
49
+ def clear_local
50
+ execute(:rm, '-rf', File.join(local_cache_path, '*')) if test!("[ -d #{local_cache_path} ]")
51
+ File.unlink(cached_gemfile_md5_path)
52
+ end
53
+
54
+ # Clear remote cached gems
55
+ #
56
+ # @return void
57
+ def clear_remote
58
+ execute(:rm, '-rf', File.join(remote_cache_path, '*')) if test!("[ -d #{remote_cache_path} ]")
59
+ end
60
+
61
+ # Path for remote bundle cache
62
+ #
63
+ # @return [String]
64
+ def remote_cache_path
65
+ File.join(shared_path, 'bundle', 'cache')
66
+ end
67
+
68
+ # Path for local bundle cache
69
+ #
70
+ # @return [String]
71
+ def local_cache_path
72
+ File.join(tmp_path, 'bundle_cache')
73
+ end
74
+
75
+ # MD5 sum of Gemfile.lock to deploy
76
+ #
77
+ # @return [String]
78
+ def gemfile_md5
79
+ @_gemfile_md5 ||= Digest::MD5.file(File.join(repo_path, 'Gemfile.lock')).hexdigest rescue nil
80
+ end
81
+
82
+ # MD5 sum of Gemfile.lock for local gem cache
83
+ #
84
+ # @return [String]
85
+ def cached_gemfile_md5
86
+ @_cached_gemfile_md5 ||= File.read(cached_gemfile_md5_path) rescue nil
87
+ end
88
+
89
+ # Path to cache for MD5 sum of Gemfile.lock
90
+ #
91
+ # @return [String]
92
+ def cached_gemfile_md5_path
93
+ File.join(tmp_path, 'git_copy_bundle_gemfile_lock.md5')
94
+ end
95
+
96
+ # Checks if Gemfile.lock has changed since last deploy
97
+ #
98
+ # @return [Boolean]
99
+ def gems_changed?
100
+ gemfile_md5.nil? || cached_gemfile_md5.nil? || gemfile_md5 != cached_gemfile_md5
101
+ end
102
+
103
+ # List of filenames for locally cached gems
104
+ #
105
+ # @return [Array]
106
+ def local_gems
107
+ %x(ls #{local_cache_path}).split(/\s+/)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,7 @@
1
+ module Capistrano
2
+ module GitCopy
3
+ module Bundle
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ require 'digest/md5'
2
+ require 'capistrano/bundler'
3
+ require 'capistrano/git_copy/bundle/utility'
4
+ require 'capistrano/git_copy/bundle/task'
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-git-copy-bundle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Schwab
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano-bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano-git-copy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Packages gems locally and uploads them to the remote server instead of
84
+ fetching them on the remote server.
85
+ email:
86
+ - me@ydkn.de
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - capistrano-git-copy-bundle.gemspec
98
+ - lib/capistrano/git_copy/bundle.rb
99
+ - lib/capistrano/git_copy/bundle/task.rb
100
+ - lib/capistrano/git_copy/bundle/tasks/bundle.cap
101
+ - lib/capistrano/git_copy/bundle/utility.rb
102
+ - lib/capistrano/git_copy/bundle/version.rb
103
+ homepage: https://github.com/ydkn/capistrano-git-copy-bundle
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.8
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Packages gems locally and uploads them to the remote server instead of fetching
126
+ them on the remote server.
127
+ test_files: []