-
-
Save basti/9232976 to your computer and use it in GitHub Desktop.
Local Rails 4 assets precompilation using Capistrano 3 and rsync
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
# Speed things up by not loading Rails env | |
config.assets.initialize_on_precompile = false |
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
# Updated to work with Capistrano 3 and Rails 4; compiles assets in given stage in order | |
# to use settings for that stage ... rm assets when we're done | |
namespace :deploy do | |
after :updated, "assets:precompile" | |
end | |
namespace :assets do | |
desc "Precompile assets locally and then rsync to web servers" | |
task :precompile do | |
on roles(:web) do | |
rsync_host = host.to_s # this needs to be done outside run_locally in order for host to exist | |
run_locally do | |
with rails_env: fetch(:stage) do | |
execute :bundle, "exec rake assets:precompile" | |
end | |
execute "rsync -av --delete ./public/assets/ #{fetch(:user)}@#{rsync_host}:#{shared_path}/public/assets/" | |
execute "rm -rf public/assets" | |
# execute "rm -rf tmp/cache/assets" # in case you are not seeing changes | |
end | |
end | |
end | |
end |
no, you don't need to require that since this task replaces it
I had to make some changes to get this working with Rails 4.1, Capistrano 3.2.1: https://gist.github.com/buntine/bf9d27ebbacba53e5c32
This docs https://devcenter.heroku.com/articles/rails-asset-pipeline says about
config.assets.initialize_on_precompile = false
In Rails 4.x this option has been removed and is no longer needed.
Someone indent that code it makes kittens cry 😄 and also rake assets:clobber
instead of rm -rf
maybe?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, do you
require 'capistrano/rails/assets'
?