Capistrano 2: How to deploy a single server

Posted . Visible to the public.

When you have a multi-server setup, you'll be adding a new server from time to time. Before doing a full deploy, you might want to test that server in an isolated deploy. There is a single way to do this: the HOSTFILTER env variable.

Commenting out "server" lines in the Capistrano deploy config will raise a Capistrano::NoMatchingServersError with <task> is only run for servers matching {:roles=> <role>}, but no servers matched. Instead, specify the server-under-test like this:

HOSTFILTER=separate-sidekiq.makandra.de cap production deploy

Capistrano is aware of this env variable and will only deploy that single server, skipping any tasks that do not apply. Profit!


As a side note, there is a secret Capistrano task option that will also silence the above exception. Generally it is a good idea that Capistrano complains when it doesn't have a server to run a (presumably important) task on. If you want it optional, define it like this:

task :my_task, on_no_matching_server: :continue do
  # Do stuff
end
Profile picture of Dominik Schöler
Dominik Schöler
Last edit
Dominik Schöler
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2017-06-13 15:35)