Read more

Capistrano 3: assets:precompile only on one server

Claus-Theodor Riegg
February 06, 2018Software engineer at makandra GmbH

Disclaimer

Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

This should not be necessary in any case and is only for special cases, for e.g. if the assets directory is linked to a shared storage (for e.g. glusterfs). Please mind that it isn't wise to move your assets directory to a shared storage. The data in this directory should always be reproducible on all appservers when executing a assets precompile (so you don't need to sync this data). Other data should not be stored in the assets directory.
User uploads or files generated by requests should be stored in public/system.

Execute assets:precompile only on one server with Capistrano 3

If the assets directory is linked to glusterfs asset:precompile should only be executed on one of the appservers.

The asset precompile is by default executed on all Servers with the role web. You can overwrite this in deploy.rb:

set :assets_roles, [:assets]

This tells Capistrano that only the role :assets should precompile assets.

Now you need to add the :assets role to one of your servers in your deployment configuration (deploy/production.rb, `deploy/staging.rb, ...). If you miss this, no asset precompile will be executed when deploying:

server 'app01-stage.acme.makandra.de', user: 'deploy-acme_s', roles: %w(app web cron db assets)
server 'app02-stage.acme.makandra.de', user: 'deploy-acme_s', roles: %w(app web db)
Posted by Claus-Theodor Riegg to makandra Operations (2018-02-06 10:08)