views:

259

answers:

1

I'm starting to use vlad for new deployments and am wondering what's the best way to set it up so I can use the same tasks for my local development and remote production servers?

I thought about defining everything as remote tasks then having dev/prod methods which set the domain variable, then I can just call rake dev/prod vlad:do_something, but this just feels totally wrong.

Many of my tasks are useful to run on my local server and on my production server and I want to avoid repeating myself by having one 'task' for local and one 'remote_task' for remote. e.g.

def do_something run "echo something" end

task :do_something_dev do_something end

remote_task do_something_prod do_something end

Am I missing something or are these really the only options for using the same rake tasks on both the local and remote machine?

A: 

How about this:

[:development, :test, :production].each do |environment|
  namespace environment do
    task :do_something do
      echo "do something on #{environment}"
    end
  end
end

This will give you:

  • rake vlad:development:do_something
  • rake vlad:test:do_something
  • rake vlad:production:do_something

With just one method it is probably less verbose to do it your way. But as soon as you have 2 or three methods, the overhead can be neglected.

egarcia