-
Notifications
You must be signed in to change notification settings - Fork 81
/
local_precompile.rb
45 lines (41 loc) · 1.43 KB
/
local_precompile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace :load do
task :defaults do
set :precompile_env, fetch(:rails_env) || 'production'
set :assets_dir, "public/assets"
set :packs_dir, "public/packs"
set :rsync_cmd, "rsync -av --delete"
set :assets_role, "web"
after "bundler:install", "deploy:assets:prepare"
after "deploy:assets:prepare", "deploy:assets:rsync"
after "deploy:assets:rsync", "deploy:assets:cleanup"
end
end
namespace :deploy do
namespace :assets 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
with rails_env: fetch(:precompile_env) do
execute "rake", "assets:clean"
execute "rake", "assets:precompile"
end
end
end
desc "Performs rsync to app servers"
task :rsync do
on roles(fetch(:assets_role)) do |server|
run_locally do
execute "#{fetch(:rsync_cmd)} ./#{fetch(:assets_dir)}/ #{server.user}@#{server.hostname}:#{release_path}/#{fetch(:assets_dir)}/" if Dir.exists?(fetch(:assets_dir))
execute "#{fetch(:rsync_cmd)} ./#{fetch(:packs_dir)}/ #{server.user}@#{server.hostname}:#{release_path}/#{fetch(:packs_dir)}/" if Dir.exists?(fetch(:packs_dir))
end
end
end
end
end