capistrano-local-precompile 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
4
+ *.tmproj
5
+ *.tmproject
6
+ *.un~
7
+ *~
8
+ .DS_Store
9
+ .Spotlight-V100
10
+ .Trashes
11
+ ._*
12
+ .bundle
13
+ .config
14
+ .directory
15
+ .elc
16
+ .emacs.desktop
17
+ .emacs.desktop.lock
18
+ .redcar
19
+ .yardoc
20
+ Desktop.ini
21
+ Gemfile.lock
22
+ Icon?
23
+ InstalledFiles
24
+ Session.vim
25
+ Thumbs.db
26
+ \#*\#
27
+ _yardoc
28
+ auto-save-list
29
+ coverage
30
+ doc
31
+ lib/bundler/man
32
+ pkg
33
+ pkg/*
34
+ rdoc
35
+ spec/reports
36
+ test/tmp
37
+ test/version_tmp
38
+ tmp
39
+ tmtags
40
+ tramp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ bundler_args: --without development
2
+ language: ruby
3
+ rvm:
4
+ - jruby-19mode
5
+ - rbx-19mode
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - 2.0.0
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.md
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'yard'
5
+
6
+ group :development do
7
+ gem 'kramdown'
8
+ gem 'guard-rspec'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rspec'
13
+ gem 'capistrano-spec'
14
+ gem 'simplecov', :require => false
15
+ end
16
+
17
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Steve Agalloco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Capistrano Local Precompile
2
+
3
+ If your Rails apps are anything like mine, one of the slowest parts of your deployment is waiting for asset pipeline precompilation. It's sometimes so slow, it's painful. So I went searching for some solutions. [turbo-sprockets](https://github.com/ndbroadbent/turbo-sprockets-rails3) helped, but it's not a silver bullet. This gem isn't a silver bullet either, but it can help. Capistrano Local Precompile takes a different approach. It builds your assets locally and rsync's them to your web server(s).
4
+
5
+ ## Usage
6
+
7
+ Add capistrano-local-precompile to your Gemfile:
8
+
9
+ ```ruby
10
+ group :development do
11
+ gem 'capistrano-local-precompile', require: false
12
+ end
13
+ ```
14
+
15
+ Then add the following line to your `deploy.rb`:
16
+
17
+ ```ruby
18
+ require 'capistrano/local_precompile'
19
+ ```
20
+
21
+ If you are using turbo-sprockets, just set it to enabled. Your asset will still compile locally, but they'll use turbosprockets to do so:
22
+
23
+ ```ruby
24
+ set :turbosprockets_enabled, true
25
+ ```
26
+
27
+ Here's the full set of configurable options:
28
+
29
+ ```ruby
30
+ set :precompile_cmd # default: bundle exec rake assets:precompile
31
+ set :assets_dir # default: "public/assets"
32
+ set :rsync_cmd # default: "rsync -av"
33
+
34
+ set :turbosprockets_enabled # default: false
35
+ set :turbosprockets_backup_dir # default: "public/.assets"
36
+ set :cleanexpired_cmd # default: bundle exec rake assets:clean_expired
37
+ ```
38
+
39
+ ## Acknowledgement
40
+
41
+ This gem is derived from gists by [uhlenbrock][] and [keighl][].
42
+
43
+ [uhlenbrock]: https://gist.github.com/uhlenbrock/1477596
44
+ [keighl]: https://gist.github.com/keighl/4338134
45
+
46
+ ## Contributing
47
+
48
+ Pull requests welcome: fork, make a topic branch, commit (squash when possible) *with tests* and I'll happily consider.
49
+
50
+ ## Copyright
51
+
52
+ Copyright (c) 2013 Steve Agalloco. See [LICENSE](LICENSE.md) for detail
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ task :test => :spec
10
+
11
+ require 'yard'
12
+ namespace :doc do
13
+ YARD::Rake::YardocTask.new do |task|
14
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
15
+ task.options = ['--markup', 'markdown']
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano-local-precompile/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'capistrano-local-precompile'
8
+ gem.version = CapistranoLocalPrecompile::VERSION
9
+ gem.homepage = 'https://github.com/spagalloco/capistrano-local-precompile'
10
+
11
+ gem.author = "Steve Agalloco"
12
+ gem.email = 'steve.agalloco@gmail.com'
13
+ gem.description = 'Local asset-pipeline precompilation for Capstrano'
14
+ gem.summary = gem.description
15
+
16
+ gem.add_dependency 'capistrano'
17
+
18
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
19
+ gem.files = `git ls-files`.split("\n")
20
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+
22
+ gem.require_paths = ['lib']
23
+ end
@@ -0,0 +1 @@
1
+ require 'capistrano/local_precompile'
@@ -0,0 +1,3 @@
1
+ module CapistranoLocalPrecompile
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'capistrano'
2
+
3
+ module Capistrano
4
+ module LocalPrecompile
5
+
6
+ def self.load_into(configuration)
7
+ configuration.load do
8
+
9
+ set(:precompile_cmd) { "#{fetch(:bundle_cmd, "bundle")} exec rake assets:precompile" }
10
+ set(:cleanexpired_cmd) { "#{fetch(:bundle_cmd, "bundle")} exec rake assets:clean_expired" }
11
+ set(:assets_dir) { "public/assets" }
12
+
13
+ set(:turbosprockets_enabled) { false }
14
+ set(:turbosprockets_backup_dir) { "public/.assets" }
15
+ set(:rsync_cmd) { "rsync -av" }
16
+
17
+ before "deploy:assets:precompile", "deploy:assets:prepare"
18
+ after "deploy:assets:precompile", "deploy:assets:cleanup"
19
+
20
+ namespace :deploy do
21
+ namespace :assets do
22
+
23
+ task :cleanup, :on_no_matching_servers => :continue do
24
+ if fetch(:turbosprockets_enabled)
25
+ run_locally "mv #{fetch(:assets_dir)} #{fetch(:turbosprockets_backup_dir)}"
26
+ else
27
+ run_locally "rm -rf #{fetch(:assets_dir)}"
28
+ end
29
+ end
30
+
31
+ task :prepare, :on_no_matching_servers => :continue do
32
+ if fetch(:turbosprockets_enabled)
33
+ run_locally "mkdir -p #{fetch(:turbosprockets_backup_dir)}"
34
+ run_locally "mv #{fetch(:turbosprockets_backup_dir)} #{fetch(:assets_dir)}"
35
+ run_locally "#{fetch(:cleanexpired_cmd)}"
36
+ end
37
+ run_locally "#{fetch(:precompile_cmd)}"
38
+ end
39
+
40
+ desc "Precompile assets locally and then rsync to app servers"
41
+ task :precompile, :only => { :primary => true }, :on_no_matching_servers => :continue do
42
+ servers = find_servers :roles => assets_role, :except => { :no_release => true }
43
+ servers.each do |srvr|
44
+ run_locally "#{fetch(:rsync_cmd)} ./#{fetch(:assets_dir)} #{user}@#{srvr}:#{release_path}/#{fetch(:assets_dir)}"
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ if Capistrano::Configuration.instance
57
+ Capistrano::LocalPrecompile.load_into(Capistrano::Configuration.instance)
58
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capistrano::LocalPrecompile, "configuration" do
4
+ before do
5
+ @configuration = Capistrano::Configuration.new
6
+ Capistrano::LocalPrecompile.load_into(@configuration)
7
+ end
8
+
9
+ it "defines precompile_cmd" do
10
+ cmd = 'bundle exec rake assets:precompile'
11
+ expect(@configuration.fetch(:precompile_cmd)).to eq(cmd)
12
+ end
13
+
14
+ it "defines cleanexpired_cmd" do
15
+ cmd = 'bundle exec rake assets:clean_expired'
16
+ expect(@configuration.fetch(:cleanexpired_cmd)).to eq(cmd)
17
+ end
18
+
19
+ it "defines assets_dir" do
20
+ expect(@configuration.fetch(:assets_dir)).to eq('public/assets')
21
+ end
22
+
23
+ it "defines turbosprockets_enabled" do
24
+ expect(@configuration.fetch(:turbosprockets_enabled)).to be_false
25
+ end
26
+
27
+ it "defines turbosprockets_backup_dir" do
28
+ dir = 'public/.assets'
29
+ expect(@configuration.fetch(:turbosprockets_backup_dir)).to eq(dir)
30
+ end
31
+
32
+ it "defines rsync_cmd" do
33
+ expect(@configuration.fetch(:rsync_cmd)).to eq('rsync -av')
34
+ end
35
+
36
+ it "performs deploy:assets:prepare before deploy:assets:precompile" do
37
+ expect(@configuration).to callback('deploy:assets:prepare').
38
+ before('deploy:assets:precompile')
39
+ end
40
+
41
+ it "performs deploy:assets:cleanup after deploy:assets:precompile" do
42
+ expect(@configuration).to callback('deploy:assets:cleanup').
43
+ after('deploy:assets:precompile')
44
+ end
45
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capistrano::LocalPrecompile, "integration" do
4
+ before do
5
+ @configuration = Capistrano::Configuration.new
6
+ Capistrano::LocalPrecompile.load_into(@configuration)
7
+ end
8
+
9
+ describe 'cleanup task' do
10
+ it 'removes the asset files from public/assets' do
11
+ expect(@configuration).to receive(:run_locally).
12
+ with('rm -rf public/assets')
13
+
14
+ @configuration.find_and_execute_task('deploy:assets:cleanup')
15
+ end
16
+ end
17
+
18
+ describe 'prepare task' do
19
+ it 'invokes the precompile command' do
20
+ expect(@configuration).to receive(:run_locally).
21
+ with('bundle exec rake assets:precompile').once
22
+
23
+ @configuration.find_and_execute_task('deploy:assets:prepare')
24
+ end
25
+ end
26
+
27
+ describe 'precompile task' do
28
+ let(:servers) { %w(10.0.1.1 10.0.1.2) }
29
+
30
+ before do
31
+ allow(@configuration).to receive(:run_locally).
32
+ with('bundle exec rake assets:precompile').once
33
+ allow(@configuration).to receive(:run_locally).
34
+ with('rm -rf public/assets').once
35
+
36
+
37
+ allow(@configuration).to receive(:user).and_return('root')
38
+ allow(@configuration).to receive(:assets_role).and_return('app')
39
+ allow(@configuration).to receive(:find_servers).and_return(servers)
40
+ allow(@configuration).to receive(:release_path).and_return('/tmp')
41
+ end
42
+
43
+ it 'rsyncs the local asset files to the server' do
44
+ expect(@configuration).to receive(:run_locally).with(/rsync -av/).twice
45
+
46
+ @configuration.find_and_execute_task('deploy:assets:precompile')
47
+ end
48
+ end
49
+
50
+ context 'with turbosprockets enabled' do
51
+ before do
52
+ @configuration.set :turbosprockets_enabled, true
53
+ end
54
+
55
+ describe 'cleanup task' do
56
+ it 'moves assets to the configured turbosprockets backup dir' do
57
+ expect(@configuration).to receive(:run_locally).
58
+ with('mv public/assets public/.assets')
59
+
60
+ @configuration.find_and_execute_task('deploy:assets:cleanup')
61
+ end
62
+ end
63
+
64
+ describe 'prepare task' do
65
+ it 'invokes the precompile command' do
66
+ expect(@configuration).to receive(:run_locally).
67
+ with('mkdir -p public/.assets').once
68
+ expect(@configuration).to receive(:run_locally).
69
+ with('mv public/.assets public/assets').once
70
+ expect(@configuration).to receive(:run_locally).
71
+ with('bundle exec rake assets:clean_expired').once
72
+ expect(@configuration).to receive(:run_locally).
73
+ with('bundle exec rake assets:precompile').once
74
+
75
+ @configuration.find_and_execute_task('deploy:assets:prepare')
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ unless ENV['CI']
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_group 'Capistrano', 'lib/capistrano'
6
+ add_group 'Specs', 'spec/*'
7
+ add_filter '.bundle'
8
+ end
9
+ end
10
+
11
+ require 'capistrano-local-precompile'
12
+ require 'rspec'
13
+ require 'capistrano-spec'
14
+
15
+ RSpec.configure do |config|
16
+ config.include Capistrano::Spec::Matchers
17
+ config.include Capistrano::Spec::Helpers
18
+
19
+ config.expect_with :rspec do |c|
20
+ c.syntax = :expect
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-local-precompile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Agalloco
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Local asset-pipeline precompilation for Capstrano
31
+ email: steve.agalloco@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gemtest
37
+ - .gitignore
38
+ - .rspec
39
+ - .travis.yml
40
+ - .yardopts
41
+ - Gemfile
42
+ - Guardfile
43
+ - LICENSE.md
44
+ - README.md
45
+ - Rakefile
46
+ - capistrano-local-precompile.gemspec
47
+ - lib/capistrano-local-precompile.rb
48
+ - lib/capistrano-local-precompile/version.rb
49
+ - lib/capistrano/local_precompile.rb
50
+ - spec/configuration_spec.rb
51
+ - spec/integration_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: https://github.com/spagalloco/capistrano-local-precompile
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ segments:
66
+ - 0
67
+ hash: -3750338883934434309
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ segments:
75
+ - 0
76
+ hash: -3750338883934434309
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.23
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Local asset-pipeline precompilation for Capstrano
83
+ test_files:
84
+ - spec/configuration_spec.rb
85
+ - spec/integration_spec.rb
86
+ - spec/spec_helper.rb
87
+ has_rdoc: