capistrano-precompile-chooser 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +6 -12
- data/Rakefile +2 -1
- data/lib/capistrano/precompile_chooser.rb +70 -18
- data/lib/capistrano/precompile_chooser/local_precompile.rake +53 -0
- data/lib/capistrano/precompile_chooser/version.rb +4 -2
- data/spec/spec_helper.rb +6 -1
- metadata +3 -7
- data/lib/capistrano/precompile_chooser/local_precompile.cap +0 -49
- data/spec/configuration_spec.rb +0 -57
- data/spec/integration_spec.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be1933acbb7586aa59fe92a8ffe27dc748ccb800113ff45a236d299e9be246aa
|
4
|
+
data.tar.gz: 4f659770779050b4cafefd3e4cd63549d3d64f27f24b673363ee57de5c966f8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18016eb1d4d5cd04b476b722118cef5dc14793ccf7e76035fa9d5ae0890e13b9c8a6d260c30ecf9dc3871d2fb85f655baabfda62463ca1d85ce3c578e5a3a4e8
|
7
|
+
data.tar.gz: c58aafd79591034e3a17f545c763b8c28450ffe81ca2ce66024a13dce6b993c330ef2619c5948f537ba417a1d5e18ad2a3d507c8e3c3e15e31df99875a0e8476
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -64,31 +64,25 @@ You can also use the `$PRECOMPILE` environment variable
|
|
64
64
|
$ PRECOMPILE_MODE="local" cap production deploy
|
65
65
|
```
|
66
66
|
|
67
|
-
|
67
|
+
Or for fully automated deploys
|
68
68
|
|
69
69
|
```ruby
|
70
|
-
#
|
70
|
+
# Capfile
|
71
71
|
|
72
|
-
|
72
|
+
ENV['PRECOMPILE_MODE'] = 'local'
|
73
|
+
require 'capistrano/precompile_chooser'
|
73
74
|
```
|
74
75
|
|
75
76
|
## Configuration Options,
|
77
|
+
|
76
78
|
```ruby
|
79
|
+
### For Local Precompile Only
|
77
80
|
set :assets_dir, "public/assets"
|
78
81
|
set :packs_dir, "public/packs"
|
79
82
|
set :rsync_cmd, "rsync -av --delete"
|
80
83
|
set :assets_role, "web"
|
81
84
|
```
|
82
85
|
|
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
86
|
# Credits
|
93
87
|
|
94
88
|
Created & Maintained by [Weston Ganger](https://westonganger.com) - [@westonganger](https://github.com/westonganger)
|
data/Rakefile
CHANGED
@@ -1,22 +1,74 @@
|
|
1
|
-
|
1
|
+
require "capistrano/plugin"
|
2
|
+
require "capistrano/precompile_chooser/version"
|
2
3
|
|
3
|
-
|
4
|
+
module Capistrano
|
5
|
+
class PrecompileChooser < Capistrano::Plugin
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# ### Currently using `namespace :load` in rake file instead
|
8
|
+
# def set_defaults
|
9
|
+
# case precompile_mode
|
10
|
+
# when "local"
|
11
|
+
# # set_if_empty :foo, :bar
|
12
|
+
# when "remote"
|
13
|
+
# # Do nothing
|
14
|
+
# else
|
15
|
+
# # Do nothing
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
|
19
|
+
def define_tasks
|
20
|
+
case precompile_mode
|
21
|
+
when "local"
|
22
|
+
eval_rakefile File.expand_path("../precompile_chooser/local_precompile.rake", __FILE__)
|
23
|
+
when "remote"
|
24
|
+
require 'capistrano/rails/assets' ### Disable for local precompile
|
25
|
+
else
|
26
|
+
# Do nothing
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def register_hooks
|
31
|
+
case precompile_mode
|
32
|
+
when "local"
|
33
|
+
after "bundler:install", "deploy:assets:local_precompile:prepare"
|
34
|
+
after "deploy:assets:local_precompile:prepare", "deploy:assets:local_precompile:rsync"
|
35
|
+
after "deploy:assets:local_precompile:rsync", "deploy:assets:local_precompile:cleanup"
|
36
|
+
else
|
37
|
+
# Do nothing
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def precompile_mode
|
42
|
+
@precompile_mode ||= begin
|
43
|
+
if ENV['PRECOMPILE_MODE']
|
44
|
+
if !valid_mode?(ENV['PRECOMPILE_MODE'])
|
45
|
+
raise "Invalid Precompile Mode"
|
46
|
+
end
|
47
|
+
else
|
48
|
+
val = nil
|
49
|
+
|
50
|
+
until valid_mode?(val)
|
51
|
+
puts
|
52
|
+
puts "How do you want to compile assets? (#{PRECOMPILE_MODES.join('/')})"
|
53
|
+
val = STDIN.gets.strip.downcase
|
54
|
+
end
|
55
|
+
|
56
|
+
puts
|
57
|
+
end
|
10
58
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
59
|
+
val
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def valid_mode?(mode)
|
66
|
+
mode && PRECOMPILE_MODES.include?(mode)
|
67
|
+
end
|
68
|
+
|
69
|
+
PRECOMPILE_MODES = ['local','remote','skip'].freeze
|
70
|
+
|
71
|
+
end
|
22
72
|
end
|
73
|
+
|
74
|
+
install_plugin Capistrano::PrecompileChooser
|
@@ -0,0 +1,53 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set_if_empty :assets_dir, "public/assets"
|
4
|
+
set_if_empty :packs_dir, "public/packs"
|
5
|
+
set_if_empty :rsync_cmd, "rsync -av --delete"
|
6
|
+
set_if_empty :assets_role, "web"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :deploy do
|
11
|
+
namespace :assets do
|
12
|
+
namespace :local_precompile do
|
13
|
+
|
14
|
+
desc "Remove all local precompiled assets"
|
15
|
+
task :cleanup do
|
16
|
+
run_locally do
|
17
|
+
execute "rm", "-rf", fetch(:assets_dir)
|
18
|
+
execute "rm", "-rf", fetch(:packs_dir)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Actually precompile the assets locally"
|
23
|
+
task :prepare do
|
24
|
+
run_locally do
|
25
|
+
execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:clean"
|
26
|
+
execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:precompile"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Performs rsync to app servers"
|
31
|
+
task :rsync do
|
32
|
+
on roles(fetch(:assets_role)), in: :parallel do |server|
|
33
|
+
run_locally do
|
34
|
+
remote_shell = %(-e "ssh -p #{server.port}") if server.port
|
35
|
+
|
36
|
+
commands = []
|
37
|
+
commands << "#{fetch(:rsync_cmd)} #{remote_shell} ./#{fetch(:assets_dir)}/ #{server.user}@#{server.hostname}:#{release_path}/#{fetch(:assets_dir)}/" if Dir.exists?(fetch(:assets_dir))
|
38
|
+
commands << "#{fetch(:rsync_cmd)} #{remote_shell} ./#{fetch(:packs_dir)}/ #{server.user}@#{server.hostname}:#{release_path}/#{fetch(:packs_dir)}/" if Dir.exists?(fetch(:packs_dir))
|
39
|
+
|
40
|
+
commands.each do |command|
|
41
|
+
if dry_run?
|
42
|
+
SSHKit.config.output.info command
|
43
|
+
else
|
44
|
+
execute command
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
require 'rake'
|
1
2
|
require 'rspec'
|
2
|
-
require
|
3
|
+
require "capistrano/all"
|
3
4
|
require "capistrano/precompile_chooser"
|
5
|
+
require 'capistrano-spec'
|
4
6
|
|
5
7
|
RSpec.configure do |config|
|
8
|
+
config.include Capistrano::Spec::Matchers
|
9
|
+
config.include Capistrano::Spec::Helpers
|
10
|
+
|
6
11
|
config.expect_with(:rspec) do |c|
|
7
12
|
c.syntax = [:should, :expect]
|
8
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-precompile-chooser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weston Ganger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -92,11 +92,9 @@ files:
|
|
92
92
|
- README.md
|
93
93
|
- Rakefile
|
94
94
|
- lib/capistrano/precompile_chooser.rb
|
95
|
-
- lib/capistrano/precompile_chooser/local_precompile.
|
95
|
+
- lib/capistrano/precompile_chooser/local_precompile.rake
|
96
96
|
- lib/capistrano/precompile_chooser/version.rb
|
97
97
|
- lib/capistrano_precompile_chooser.rb
|
98
|
-
- spec/configuration_spec.rb
|
99
|
-
- spec/integration_spec.rb
|
100
98
|
- spec/spec_helper.rb
|
101
99
|
homepage: https://github.com/westonganger/capistrano-precompile-chooser
|
102
100
|
licenses: []
|
@@ -122,6 +120,4 @@ specification_version: 4
|
|
122
120
|
summary: Capistrano plugin to precompile your Rails assets locally, remotely, or not
|
123
121
|
at all provided with a very convenient default terminal prompt.
|
124
122
|
test_files:
|
125
|
-
- spec/integration_spec.rb
|
126
|
-
- spec/configuration_spec.rb
|
127
123
|
- spec/spec_helper.rb
|
@@ -1,49 +0,0 @@
|
|
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"
|
data/spec/configuration_spec.rb
DELETED
@@ -1,57 +0,0 @@
|
|
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
|
data/spec/integration_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
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
|