Read more

Capistrano 3: assets:precompile only on one server

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


Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show 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 '', user: 'deploy-acme_s', roles: %w(app web cron db assets)
server '', user: 'deploy-acme_s', roles: %w(app web db)
Posted by Claus-Theodor Riegg to makandra Operations (2018-02-06 10:08)