-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9906e69
commit bfeb0a1
Showing
10 changed files
with
143 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
CHANGELOG | ||
--------- | ||
|
||
- Unreleased | ||
- Refractor into a `Capistrano::Plugin` | ||
|
||
- **0.9.0** - August 19, 2020 | ||
- Gem Initial Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,74 @@ | ||
val = nil | ||
require "capistrano/plugin" | ||
require "capistrano/precompile_chooser/version" | ||
|
||
opts = ['local','remote','skip'] | ||
module Capistrano | ||
class PrecompileChooser < Capistrano::Plugin | ||
|
||
until val && opts.include?(val) | ||
puts | ||
puts "How do you want to compile assets? (#{opts.join('/')})" | ||
val = STDIN.gets.strip.downcase | ||
end | ||
# ### Currently using `namespace :load` in rake file instead | ||
# def set_defaults | ||
# case precompile_mode | ||
# when "local" | ||
# # set_if_empty :foo, :bar | ||
# when "remote" | ||
# # Do nothing | ||
# else | ||
# # Do nothing | ||
# end | ||
# end | ||
|
||
def define_tasks | ||
case precompile_mode | ||
when "local" | ||
eval_rakefile File.expand_path("../precompile_chooser/local_precompile.rake", __FILE__) | ||
when "remote" | ||
require 'capistrano/rails/assets' ### Disable for local precompile | ||
else | ||
# Do nothing | ||
end | ||
end | ||
|
||
def register_hooks | ||
case precompile_mode | ||
when "local" | ||
after "bundler:install", "deploy:assets:local_precompile:prepare" | ||
after "deploy:assets:local_precompile:prepare", "deploy:assets:local_precompile:rsync" | ||
after "deploy:assets:local_precompile:rsync", "deploy:assets:local_precompile:cleanup" | ||
else | ||
# Do nothing | ||
end | ||
end | ||
|
||
def precompile_mode | ||
@precompile_mode ||= begin | ||
if ENV['PRECOMPILE_MODE'] | ||
if !valid_mode?(ENV['PRECOMPILE_MODE']) | ||
raise "Invalid Precompile Mode" | ||
end | ||
else | ||
val = nil | ||
|
||
until valid_mode?(val) | ||
puts | ||
puts "How do you want to compile assets? (#{PRECOMPILE_MODES.join('/')})" | ||
val = STDIN.gets.strip.downcase | ||
end | ||
|
||
puts | ||
end | ||
|
||
puts | ||
|
||
case val | ||
when "local" | ||
#import 'config/deploy/local_precompile.cap' | ||
#import File.expand_path("../tasks/local_precompile.cap") | ||
load File.expand_path("../tasks/local_precompile.cap") | ||
when "remote" | ||
require 'capistrano/rails/assets' ### Disable for local precompile | ||
else | ||
# Do nothing | ||
val | ||
end | ||
end | ||
|
||
private | ||
|
||
def valid_mode?(mode) | ||
mode && PRECOMPILE_MODES.include?(mode) | ||
end | ||
|
||
PRECOMPILE_MODES = ['local','remote','skip'].freeze | ||
|
||
end | ||
end | ||
|
||
install_plugin Capistrano::PrecompileChooser |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace :load do | ||
task :defaults do | ||
set_if_empty :assets_dir, "public/assets" | ||
set_if_empty :packs_dir, "public/packs" | ||
set_if_empty :rsync_cmd, "rsync -av --delete" | ||
set_if_empty :assets_role, "web" | ||
end | ||
end | ||
|
||
namespace :deploy do | ||
namespace :assets do | ||
namespace :local_precompile do | ||
|
||
desc "Remove all local precompiled assets" | ||
task :cleanup do | ||
run_locally do | ||
execute "rm", "-rf", fetch(:assets_dir) | ||
execute "rm", "-rf", fetch(:packs_dir) | ||
end | ||
end | ||
|
||
desc "Actually precompile the assets locally" | ||
task :prepare do | ||
run_locally do | ||
execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:clean" | ||
execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:precompile" | ||
end | ||
end | ||
|
||
desc "Performs rsync to app servers" | ||
task :rsync do | ||
on roles(fetch(:assets_role)), in: :parallel do |server| | ||
run_locally do | ||
remote_shell = %(-e "ssh -p #{server.port}") if server.port | ||
|
||
commands = [] | ||
commands << "#{fetch(:rsync_cmd)} #{remote_shell} ./#{fetch(:assets_dir)}/ #{server.user}@#{server.hostname}:#{release_path}/#{fetch(:assets_dir)}/" if Dir.exists?(fetch(:assets_dir)) | ||
commands << "#{fetch(:rsync_cmd)} #{remote_shell} ./#{fetch(:packs_dir)}/ #{server.user}@#{server.hostname}:#{release_path}/#{fetch(:packs_dir)}/" if Dir.exists?(fetch(:packs_dir)) | ||
|
||
commands.each do |command| | ||
if dry_run? | ||
SSHKit.config.output.info command | ||
else | ||
execute command | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
require "capistrano/plugin" | ||
|
||
module Capistrano | ||
module PrecompileChooser | ||
class PrecompileChooser < Capistrano::Plugin | ||
VERSION = "0.9.0" | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.