David Resnick
David Resnick

Reputation: 4991

How to set different deploy_to values in capistrano 3 based on roles?

I'd like to deploy multiple applications with the same deploy.rb using roles. The different applications should have different values for various options, e.g. deploy_to and scm. Like I described in this email to the Capistrano google group:

https://groups.google.com/d/msg/capistrano/LQpWkHr9h18/FQS8jl8-DQAJ

I'm new to Capistrano and am trying to figure something out.

I have a codebase that until now has been a Ruby on Rails application (using Ruby 2.1.2), using Capistrano to deploy.

Now I'd also like to run the codebase as a Ruby script based service (no Rails and not listening for HTTP requests). This version of the service will run using JRuby.

Both applications use the same Gemfile, with lot's of code in common between the 2 apps.

I'm trying to figure out how to expand the Capfile to support the additional deployment configuration.

A direction I'm looking at is to deploy using a new role in the Capfile. This new role will have quite a few differences from the existing one, e.g. how it restarts the service, where the service is installed.

My questions are: does this approach make any sense? Can anyone point out a more complex Capfile that shows some part of what I've described?

In the meantime, I’m looking at adding the new role in a new namespace.

Thanks, David

Versions: Ruby ruby 2.1.2 + jruby 9.0.4.0 Capistrano 3.4.0

Upvotes: 3

Views: 645

Answers (2)

will_in_wi
will_in_wi

Reputation: 2653

The purpose of roles is to define which tasks to run, when the majority are common. For example, you may want to run the database migrations on one server, restart the application on another server, and kick some background processes on yet another server. But all of these roles will copy the same code to the same location on the server.

If you want to deploy multiple distinct applications, you should probably use multiple Capistrano configurations.

Upvotes: 1

David Resnick
David Resnick

Reputation: 4991

Unfortunately, the conclusion I reached is that this is not possible.

Configuration settings like deploy_to are global and cannot be overridden per role.

Upvotes: 1

Related Questions