Asset Precompile on development machine before capistrano deployment

I want the asset to be precompiled on my dev machine before the code is tarball'ed by capistrano and has the precompiled assets already included in the final deployment package.

When I try the built-in capistrano recipe, which in load 'deploy/assets' runs rake RAILS_GROUPS=assets assets:precompile on the server.

The reason I'm looking for this is because, at the moment, precompile has been migrating my EC2 instance for too long (and sometimes it just hangs) It would be great if assets could be compiled even before the deployment started, so that I could save the server from this heavy workload - so far, at least, I haven’t had better configured servers.

+4
source share
3 answers

The workflow is still a bit bumpy at the moment, but you can find some success using Guard-Rails-Assets . This is a bit slower, especially if you make a lot of changes in the assets, but they will compile the assets when they change, and you can just check them for your repo, which will be deployed later.

+3
source

I just wrote a stone to solve this problem inside Rails called turbo-sprockets-rails3 . It speeds up your assets:precompile by recompiling modified files and only compiling once to create all assets. It works out of the box for Capistrano, as your resource directory is shared between releases.

It would be really cool if you could help me test the turbo-sprockets-rails3 gem and let me know if you have any problems.

+3
source

Remove load 'deploy/assets' from Capfile or config/deploy.rb and add the following lines to config/deploy.rb :

  set: assets_role, [: web,: app]
 set: normalize_asset_timestamps, false
 set: assets_tar_path, "# {release_name} -assets.tar.gz"

 before "deploy: update" do
   run_locally "rake assets: precompile"
   run_locally "cd public; tar czf # {Dir.tmpdir} / # {assets_tar_path} assets"
 end

 before "deploy: finalize_update",: roles => assets_role,: except => {: no_release => true} do
   upload "# {Dir.tmpdir} / # {assets_tar_path}", "# {shared_path} / # {assets_tar_path}"
   run "cd # {shared_path}; / bin / tar xzf # {assets_tar_path}"
   run "/ bin / ln -s # {shared_path} / assets # {release_path} / public"
   run "/ bin / rm # {shared_path} / # {assets_tar_path}"
 end

If you are using turbo-sprockets-rails3 , add this to the last block:

  run "cd # {release_path}; # {rake} assets: clean_expired 2> / dev / null"
+1
source

Source: https://habr.com/ru/post/1382904/


All Articles