Marius Schuller
5 years
Marius Schuller
5 years
Henning Koch
10 years
Andreas Herz
6 years
Claus-Theodor Riegg
6 years
Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
8 years
Marius Schuller
8 years
Claus-Theodor Riegg
8 years

Capistrano 3: assets:precompile only on one server

Posted . Visible to the public.

Disclaimer

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)
Claus-Theodor Riegg
Last edit
Claus-Theodor Riegg
License
Source code in this card is licensed under the MIT License.