質問

I must be missing something with Capistrano, because I've just started writing capfiles and I'm looking at tons of duplicated code. Consider this

role :dev, "dev1", "dev2"
role :prod, "prod1", "prod2"

desc "Deploy the app in dev"
task :deploy_dev, :roles => :dev do
    run "sudo install-stuff"
end

desc "Deploy the app in prod"
task :deploy_prod, :roles => :prod do
    run "sudo install-stuff"
end

IMO it's totally reasonable to want to run the exact same task in dev or prod, but from what I can tell, Capistrano would have me write 2 tasks just to specify the different nodes...

Seems like if you could refer to roles on the CLI like

cap deploy dev
cap deploy prod

there could be a single definition of the 'deploy' task in the capfile, as opposed to a duplicated one for each set of servers.

Is there a way to write a task once and specify the role dynamically?

役に立ちましたか?

解決

Have a look at the multistage extension. While fairly easy to set up the tasks you need yourself, the multistage extension will do it all for you.

If you'd rather do it yourself, see the calling tasks section of the handbook. The trick is that you can invoke different tasks in order from the command line.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top