capistrano-precompile-chooser 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d855d31f6a7e049a5d25c9db936bb4da6174c294790c7b534dbf4273436f8a3
4
+ data.tar.gz: 638620eca7b11bbfbf47a3caa164d1f7e70934f2e63e1b7253153c6fdbdecfa0
5
+ SHA512:
6
+ metadata.gz: 772370091f9a5ee1d7c0ffb656900673b557a3370cc30af9bbd977e3cf1e9602f9c09afe812517d79cd420fc43ab1ccfd066ff44a2901531241ac64c0501fca7
7
+ data.tar.gz: 0d3cbe1349b8024eaf349ff2e234c0df1ebf459429bf26934817deae05492f5665e640df654f9f61eca0472b362c40238136b819cc68674e2fd4a2024378afb5
@@ -0,0 +1,5 @@
1
+ CHANGELOG
2
+ ---------
3
+
4
+ - **0.9.0** - August 19, 2020
5
+ - Gem Initial Release
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2020 Weston Ganger
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # Capistrano Precompile Chooser
2
+
3
+ <a href="https://badge.fury.io/rb/capistrano-precompile-chooser" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/capistrano-precompile-chooser.svg" alt="Gem Version"></a>
4
+ <a href='https://travis-ci.org/westonganger/capistrano-precompile-chooser' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://travis-ci.org/westonganger/capistrano-precompile-chooser.svg?branch=master' border='0' alt='Build Status'></a>
5
+ <a href='https://rubygems.org/gems/capistrano-precompile-chooser' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/capistrano-precompile-chooser?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
6
+ <a href='https://ko-fi.com/A5071NK' target='_blank'><img height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee'></a>
7
+
8
+ Capistrano plugin to precompile your Rails assets locally, remotely, or not at all provided with a very convenient default terminal prompt.
9
+
10
+ By Default, on every deploy this plugin will prompt you on whether you want to precompile your assets locally, remotely, or not at all. Alternatively you can set some variable for fully automated deploys.
11
+
12
+ ```
13
+ $ cap production deploy
14
+
15
+ How do you want to compile assets? (local/remote/skip)
16
+ skip
17
+ ```
18
+
19
+ ## Precompile Modes
20
+
21
+ - `local` - Local Precompilation Mode (Improves Memory/Load Spikes on Server during Deploys)
22
+ - `remote` - Remote Precompilation Mode (Rails Default)
23
+ - `skip` - No Precompilation (Speeds up deployments with unchanged assets)
24
+
25
+ ## Installation
26
+
27
+ ```ruby
28
+ # Gemfile
29
+
30
+ group :development do
31
+ gem "capistrano-precompile-chooser"
32
+ end
33
+ ```
34
+
35
+ ```ruby
36
+ # Capfile
37
+
38
+ # require 'capistrano/rails' ### Comment Out or Remove this line
39
+ require 'capistrano/precompile_chooser'
40
+ ```
41
+
42
+ If you want to be able to safely use the `skip` option you must add `public/assets` to your capistrano `:shared_dirs` variable
43
+
44
+ ```ruby
45
+ # config/deploy.rb
46
+
47
+ set :linked_dirs, %w{ <other-dirs> public/assets }
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ Now when running a deployment:
53
+
54
+ ```
55
+ $ cap production deploy
56
+
57
+ How do you want to compile assets? (local/remote/skip)
58
+ skip
59
+ ```
60
+
61
+ You can also use the `$PRECOMPILE` environment variable
62
+
63
+ ```bash
64
+ $ PRECOMPILE_MODE="local" cap production deploy
65
+ ```
66
+
67
+ You can also set the capistrano `:precompile` variable for fully automated deploys
68
+
69
+ ```ruby
70
+ # config/deploy.rb
71
+
72
+ set :precompile_mode, "local"
73
+ ```
74
+
75
+ ## Configuration Options,
76
+ ```ruby
77
+ set :assets_dir, "public/assets"
78
+ set :packs_dir, "public/packs"
79
+ set :rsync_cmd, "rsync -av --delete"
80
+ set :assets_role, "web"
81
+ ```
82
+
83
+ ## Task Ordering, and Task Details
84
+
85
+ <a href="https://github.com/westonganger/capistrano-precompile-chooser/blob/master/lib/capistrano/precompile_chooser.rb">See Source</a>
86
+
87
+ # TODO
88
+
89
+ - Add Tests
90
+ - Optional Precompilation Based on Diff - **PR WANTED**
91
+
92
+ # Credits
93
+
94
+ Created & Maintained by [Weston Ganger](https://westonganger.com) - [@westonganger](https://github.com/westonganger)
95
+
96
+ For any consulting or contract work please contact me via my company website: [Solid Foundation Web Development](https://solidfoundationwebdev.com)
97
+
98
+ [![Solid Foundation Web Development Logo](https://solidfoundationwebdev.com/logo-sm.png)](https://solidfoundationwebdev.com)
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/lib/capistrano/precompile_chooser/version')
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task test: :spec
8
+
9
+ task :console do
10
+ require 'capistrano'
11
+ require 'capistrano/precompile_chooser'
12
+
13
+ require 'irb'
14
+ binding.irb
15
+ end
@@ -0,0 +1,22 @@
1
+ val = nil
2
+
3
+ opts = ['local','remote','skip']
4
+
5
+ until val && opts.include?(val)
6
+ puts
7
+ puts "How do you want to compile assets? (#{opts.join('/')})"
8
+ val = STDIN.gets.strip.downcase
9
+ end
10
+
11
+ puts
12
+
13
+ case val
14
+ when "local"
15
+ #import 'config/deploy/local_precompile.cap'
16
+ #import File.expand_path("../tasks/local_precompile.cap")
17
+ load File.expand_path("../tasks/local_precompile.cap")
18
+ when "remote"
19
+ require 'capistrano/rails/assets' ### Disable for local precompile
20
+ else
21
+ # Do nothing
22
+ end
@@ -0,0 +1,49 @@
1
+ set :assets_dir, "public/assets"
2
+ set :packs_dir, "public/packs"
3
+ set :rsync_cmd, "rsync -av --delete"
4
+ set :assets_role, "web"
5
+
6
+ namespace :deploy do
7
+ namespace :assets do
8
+ desc "Remove all local precompiled assets"
9
+ task :cleanup do
10
+ run_locally do
11
+ execute "rm", "-rf", fetch(:assets_dir)
12
+ execute "rm", "-rf", fetch(:packs_dir)
13
+ end
14
+ end
15
+
16
+ desc "Actually precompile the assets locally"
17
+ task :prepare do
18
+ run_locally do
19
+ execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:clean"
20
+ execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:precompile"
21
+ end
22
+ end
23
+
24
+ desc "Performs rsync to app servers"
25
+ task :rsync do
26
+ on roles(fetch(:assets_role)), in: :parallel do |server|
27
+ run_locally do
28
+ remote_shell = %(-e "ssh -p #{server.port}") if server.port
29
+
30
+ commands = []
31
+ commands << "#{fetch(:rsync_cmd)} #{remote_shell} ./#{fetch(:assets_dir)}/ #{server.user}@#{server.hostname}:#{release_path}/#{fetch(:assets_dir)}/" if Dir.exists?(fetch(:assets_dir))
32
+ commands << "#{fetch(:rsync_cmd)} #{remote_shell} ./#{fetch(:packs_dir)}/ #{server.user}@#{server.hostname}:#{release_path}/#{fetch(:packs_dir)}/" if Dir.exists?(fetch(:packs_dir))
33
+
34
+ commands.each do |command|
35
+ if dry_run?
36
+ SSHKit.config.output.info command
37
+ else
38
+ execute command
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ after "bundler:install", "deploy:assets:prepare"
48
+ after "deploy:assets:prepare", "deploy:assets:rsync"
49
+ after "deploy:assets:rsync", "deploy:assets:cleanup"
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module PrecompileChooser
3
+ VERSION = "0.9.0"
4
+ end
5
+ end
File without changes
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ # TODO
4
+
5
+ describe Capistrano::PrecompileChooser, "configuration" do
6
+ before do
7
+ @configuration = Capistrano::Configuration.new
8
+ @configuration.load do
9
+ def rails_env; 'production'; end
10
+ def rake; 'rake'; end
11
+ def asset_env; "RAILS_GROUPS=assets"; end
12
+ end
13
+ Capistrano::PrecompileChooser.load_into(@configuration)
14
+ end
15
+
16
+ it "defines precompile_env" do
17
+ expect(@configuration.fetch(:precompile_env)).to eq('production')
18
+ end
19
+
20
+ it "defines precompile_cmd" do
21
+ cmd = 'RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile'
22
+ expect(@configuration.fetch(:precompile_cmd)).to eq(cmd)
23
+ end
24
+
25
+ it "defines cleanexpired_cmd" do
26
+ cmd = 'RAILS_ENV=production RAILS_GROUPS=assets rake assets:clean_expired'
27
+ expect(@configuration.fetch(:cleanexpired_cmd)).to eq(cmd)
28
+ end
29
+
30
+ it "defines assets_dir" do
31
+ expect(@configuration.fetch(:assets_dir)).to eq('public/assets')
32
+ end
33
+
34
+ it "defines rsync_cmd" do
35
+ expect(@configuration.fetch(:rsync_cmd)).to eq('rsync -av --delete')
36
+ end
37
+
38
+ it "performs deploy:assets:prepare before deploy:assets:precompile" do
39
+ expect(@configuration).to callback('deploy:assets:prepare').
40
+ before('deploy:assets:precompile')
41
+ end
42
+
43
+ it "performs deploy:assets:remove before deploy:assets:precompile" do
44
+ expect(@configuration).to callback('deploy:assets:remove').
45
+ before('deploy:assets:symlink')
46
+ end
47
+
48
+ it "performs deploy:assets:cleanup after deploy:assets:precompile" do
49
+ expect(@configuration).to callback('deploy:assets:cleanup').
50
+ after('deploy:assets:precompile')
51
+ end
52
+
53
+ it "performs deploy:assets:remove_manifest before deploy:assets:symlink" do
54
+ expect(@configuration).to callback('deploy:assets:remove_manifest').
55
+ before('deploy:assets:symlink')
56
+ end
57
+ end
@@ -0,0 +1,68 @@
1
+ # TODO
2
+
3
+ describe Capistrano::PrecompileChooser, "integration" do
4
+ before do
5
+ @configuration = Capistrano::Configuration.new
6
+ @configuration.load do
7
+ def rails_env; 'production'; end
8
+ def rake; 'rake'; end
9
+ def asset_env; "RAILS_GROUPS=assets"; end
10
+ end
11
+ Capistrano::PrecompileChooser.load_into(@configuration)
12
+ end
13
+
14
+ describe 'cleanup task' do
15
+ it 'removes the asset files from public/assets' do
16
+ expect(@configuration).to receive(:run_locally).
17
+ with('rm -rf public/assets')
18
+
19
+ @configuration.find_and_execute_task('deploy:assets:cleanup')
20
+ end
21
+ end
22
+
23
+ describe 'prepare task' do
24
+ it 'invokes the precompile command' do
25
+ expect(@configuration).to receive(:run_locally).
26
+ with('RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile').once
27
+
28
+ @configuration.find_and_execute_task('deploy:assets:prepare')
29
+ end
30
+ end
31
+
32
+ describe 'remove manifest task' do
33
+ it 'invokes the precompile command' do
34
+ allow(@configuration).to receive(:shared_path).and_return('/tmp/shared')
35
+ allow(@configuration).to receive(:shared_assets_prefix).and_return('assets')
36
+
37
+ expect(@configuration).to receive(:run).
38
+ with('rm -f /tmp/shared/assets/manifest*').once
39
+
40
+ @configuration.find_and_execute_task('deploy:assets:remove_manifest')
41
+ end
42
+ end
43
+
44
+ describe 'precompile task' do
45
+ let(:servers) { %w(10.0.1.1 10.0.1.2) }
46
+
47
+ before do
48
+ allow(@configuration).to receive(:run_locally).
49
+ with("ls public/assets/manifest*").and_return("public/assets/manifest.yml").once
50
+ allow(@configuration).to receive(:run_locally).
51
+ with('RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile').once
52
+ allow(@configuration).to receive(:run_locally).
53
+ with('rm -rf public/assets').once
54
+
55
+
56
+ allow(@configuration).to receive(:user).and_return('root')
57
+ allow(@configuration).to receive(:assets_role).and_return('app')
58
+ allow(@configuration).to receive(:find_servers).and_return(servers)
59
+ allow(@configuration).to receive(:release_path).and_return('/tmp')
60
+ end
61
+
62
+ it 'rsyncs the local asset files to the server' do
63
+ expect(@configuration).to receive(:run_locally).with(/rsync -av/).exactly(4).times
64
+
65
+ @configuration.find_and_execute_task('deploy:assets:precompile')
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'capistrano-spec'
3
+ require "capistrano/precompile_chooser"
4
+
5
+ RSpec.configure do |config|
6
+ config.expect_with(:rspec) do |c|
7
+ c.syntax = [:should, :expect]
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-precompile-chooser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Weston Ganger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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: capistrano-spec
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: Capistrano plugin to precompile your Rails assets locally, remotely,
84
+ or not at all provided with a very convenient default terminal prompt.
85
+ email: weston@westonganger.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - lib/capistrano/precompile_chooser.rb
95
+ - lib/capistrano/precompile_chooser/local_precompile.cap
96
+ - lib/capistrano/precompile_chooser/version.rb
97
+ - lib/capistrano_precompile_chooser.rb
98
+ - spec/configuration_spec.rb
99
+ - spec/integration_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/westonganger/capistrano-precompile-chooser
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.9.3
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.1.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Capistrano plugin to precompile your Rails assets locally, remotely, or not
123
+ at all provided with a very convenient default terminal prompt.
124
+ test_files:
125
+ - spec/integration_spec.rb
126
+ - spec/configuration_spec.rb
127
+ - spec/spec_helper.rb