railsware / capistrano-multiconfig

Capistrano extension that allows to use multiple configurations
MIT License
65 stars 19 forks source link

Enable setting of properties on tasks generated automatically from capistrano-multiconfig #3

Closed gmacid closed 12 years ago

gmacid commented 12 years ago

Hi,

capistrano-multiconfig looks great, and i wanted to use it in conjunction with the staging functionality in newer versions of capistrano so I can deploy multiple apps but to different environments.

In my individual project Cap deploy scripts I defined a task like this:

role :app, 'some-app-server.mydomain.com' task :foo, :roles => :app

however when I use the excellent capistrano-multiconfig, it sets the task up in a lambda block without any options. I looked at ways to set the options which is impossible because Capistrano::TaskDefinition makes it an attr_reader only. I looked at ways to override roles through environment variables but to be honest that sucked a bit.

So unless there was another way to do it, I created the following patch which provides a simple solution to the problem. In addition I wanted to fix my task "descriptions" which I thought should be more verbose than the generic version that capistrano-multiconfig gives you.

The patch allows you to define a json file alongside your task file containing options and description (and can be extended later to other things), so they can be passed into the task that is automatically generated.

E.g. if I have config/deploy/some_app/some_task.rb I can now also have:

config/deploy/some_app/some_task.json

{ "description": "this is the real description for some_task" "options": { "roles": [ "app" ] } }

And everything seems to work fine again.

In this way I have created a battery of different cap scripts for different apps, all on different environments all in one place.

I didnt rebuild the Gemfile so if you're interested in the above patch you'll need to do that yourselves.

Alternatively if you have a different and more elegant way of doing the above (not using ENV variables), please do let me know, I couldnt find one!

However I normall

ayanko commented 12 years ago

What about to try CapHub Concept ?

I don't see how your layout differs from it.

gmacid commented 12 years ago

Hi,

That's actually exactly what I'm using. I just can't get the roles stuff to work with it and thought it would be pretty nice to have it working too. Obviously Caphub depends on capistrano-multiconfig so the fix/feature needed to happen here

thanks

ayanko commented 12 years ago

Then main goal of capistrano-multiconfig is dynamically create configuration tasks (like multistage extension from capistrano-ext).

Each configuration is task loads some specific configuration that itself contains definitions of roles, servers etc. That's why there is no sense to specify task options in this case, because there is no roles yet defined anyway :)

Normal regular capistrano task should NOT be put in the same directory where configuration tasks are located. It can be located in recipes or any other directory. (As you know CapHup is only concept and you are free to use your own layout)

So I still don't understand why you need to specify role to configuration task that will load actual configuration where role is defined :)

Probably you just not use it as it should be used? Could you provide link to gist with real example?

ayanko commented 12 years ago

Ah you want use capistrano/ext/multistage + capistrano_multiconfig ?

E.g.:

$ cap production apps:blog deploy

I don't think that this mix is good.
Is it not possible to rewrite it to use only multiconfig?

You may create layout like:

config/deploy/apps/blog/production.rb
config/deploy/apps/blog/qa.rb
config/deploy/apps/wiki/production.rb
config/deploy/apps/wiki/qa.rb
config/deploy/all/production.rb
config/deploy/all/qa.rb

Then u will be able to deploy either both apps at once:

$ cap all:production deploy

or specific one:

$ cap apps:wiki:production deploy
gmacid commented 12 years ago

Thanks!

I can see now I was using multiconfig in the wrong capacity… and yes I was trying to use it with multistage.

Regards Geoff

On 11 Apr 2012, at 14:46, Andriy Yanko wrote:

Ah you want use capistrano/ext/multistage + capistrano_multiconfig ?

E.g.:

$ cap production apps:blog deploy

I don't think that's this mix is good.
Is it not possible to rewrite it to use only multiconfig?

You may create layout like:

config/deploy/apps/blog/production.rb
config/deploy/apps/blog/qa.rb
config/deploy/apps/wiki/production.rb
config/deploy/apps/wiki/qa.rb
config/deploy/all/production.rb
config/deploy/all/qa.rb

Then u will be able to deploy either both apps at once:

$ cap all:production deploy

or specific one:

$ cap apps:wiki:production deploy

Reply to this email directly or view it on GitHub: https://github.com/railsware/capistrano-multiconfig/pull/3#issuecomment-5068980

gbirke commented 12 years ago

Can you give an example for the "all" configurations? You'd have to set different deployment paths/servers and run the deploy task for each of them. How is this done?

ayanko commented 12 years ago

Hm... "All" case is not easy. Just right now I see only wrapper implementation.

$ cat config/deploy/all/production.rb
task :deploy do
  system "bundle exec cap blog:production deploy"
  system "bundle exec cap blog:wiki deploy"
end

But it's not so nice.