mydrive / capistrano-deploytags

Add timestamped Git tags for each environment on deployment
BSD 2-Clause "Simplified" License
123 stars 20 forks source link

Documentation : Deploytags requires that :branch and :stage be defined #10

Closed sci-phi closed 10 years ago

sci-phi commented 10 years ago

I wanted to try this, so added it to my setup, and got this error :

"*** Capistrano Deploytags requires that :branch and :stage be defined."

There is no mention of additional configuration in the README.

I think it should be documented to at least mention "What?" needs to be defined, "Where?" it is done, and ideally including an example showing "How?" to do it.

relistan commented 10 years ago

Thanks for contributing! Actually the very first paragraph of the README does say this, but maybe there is something more you think we should add? Normally if you use this with the capistrano multistage setup it just works. If you don't, then you need to define branch and stage as it says. Happy to take a contribution of a better explanation if you wouldn't mind giving me your thoughts on what you think it should say.

sci-phi commented 10 years ago

It does, and I missed that in my haste. I expected it to work with a vanilla capistrano deploy, not just in multistage scenarios. I did get it working, but had to insert a delayed step, like so -

task :update_stage do
  set :stage, "foo"
end
before "git:prepare_tree", "update_stage"

Also, it was very frustrating trying to test a deploy script when you kept harping on my tree being dirty... so I hacked it, like so -

def pending?
  # Do we have any changes vs HEAD on deployment branch?
  !(`git fetch && git diff #{branch} --shortstat`.strip.empty?)
end
def deploy_rb?
  !!(`git status -s`.strip =~ /config\/deploy\.rb/)
end
def solo?
  !!(`git fetch && git diff #{branch} --shortstat`.strip =~ /1 file changed/)
end
def deployable?
  if pending? then
    return false if (solo? && deploy_rb?)
    return true
  end
end

I'm rethinking tagging every single deploy however, as I was deploying at lot for testing and it just looked noisy. Would like some way to only tag staging/production deploys.

FYI : the main reason I tried this was for the related migration detection plugin.

sci-phi commented 10 years ago

Ooops, that was pasted from a spike file (I've tossed my actual hack now) and it looks like I reversed the booleans initially

relistan commented 10 years ago

You don't have to run a task to update the stage. You can just put set :stage, 'foo' right up at the top of your deploy.rb. Or am I missing something about why you coudn't do that?

It sounds like your use case is pretty much how a lot of us use multi stage (despite the name). If you have different environments to deploy to, just make each one a stage and it will work out of the box. This opens a whole nice set of possibilities for defining different settings per stage in a clean way as well. Of course you know your environment best, but I think you might be fighting the framework a bit here given what little I understand about how you are using it. I recommend having a read of this explanation.

Design goals of capistrano-deploytags were to make it work right out of the box without configuration, and to tag every deployment. It would be pretty trivial to add the ability not to tag a particular stage, though. I would guess that's the easiest way to do it. The stage could define :no_tagging or similar, and that would then not git tag for test or whatever other environment you don't want to tag. I'll have a look at that.

relistan commented 10 years ago

Oops, forgot to respond to the second part of that. If you just commit the code (doesn't have to be pushed) you will find that it works fine for modifying your deploy scripts. I'll add that to the README since it should be obvious to anyone who wants to use it. Thanks for pointing out the shortcoming.

relistan commented 10 years ago

The README was updated in commit a24c306e6b8d7704fe2bce0dd707391e092fa9f3

relistan commented 10 years ago

Simple addition to prevent tagging when desited, added here: bb520be7e3f923a243a8c0e033c5bf2294e84f76 . The readme is updated here: 3c6fc4262330aee43f2be12290bbb08210cd1620 . I'll do a new release this afternoon.

sci-phi commented 10 years ago

Great stuff, thanks!