Why does switchtower set variables _after_ loading the recipe files? I''d like to do something like: switchtower -r deploy -s rev=trunk@327 -a deploy and have deploy.rb specify: set :repository, "http://svn/app/trunk@#{rev}" But that doesn''t work because "rev" isn''t set until after the recipe (along w/ the call to set :repository) had already happened. Seems that it was intended that the above would work: http://jamis.jamisbuck.org/articles/2005/08/27/conditional-switchtower-configuration I do have an alternative approach, which is to just set the value in the environment. Ie., call instead: rev=trunk@327 switchtower -r deploy -a deploy and have deploy.rb specify: set :repository, "http://svn/app/trunk@#{ENV[''rev'']}" But my initial approach seems cleaner.
On Sep 20, 2005, at 6:12 PM, Michael Schoen wrote:> Why does switchtower set variables _after_ loading the recipe files?The reason is so that you can override variables specified in the recipe files. If the variables were set first, you couldn''t do that.> > I''d like to do something like: > > switchtower -r deploy -s rev=trunk@327 -a deploy > > and have deploy.rb specify: > > set :repository, "http://svn/app/trunk@#{rev}"You can do this if you use a proc: set :repository, Proc.new { "http://svn/app/trunk@#{rev}" } The proc is evaluated the first time the repository variable is referenced, which will be after your rev variable is set from the command-line. I''ve thought about having two switches, one for variables set "before" and one "after". Would this be useful? - Jamis
> The reason is so that you can override variables specified in the > recipe files. If the variables were set first, you couldn''t do that.I don''t understand the use case. Can you provide an example?> You can do this if you use a proc: > > set :repository, Proc.new { "http://svn/app/trunk@#{rev}" }Ah, that works just great for me.> I''ve thought about having two switches, one for variables set "before" > and one "after". Would this be useful?The Proc approach works for me.
On Sep 20, 2005, at 8:49 PM, Michael Schoen wrote:>> The reason is so that you can override variables specified in the >> recipe files. If the variables were set first, you couldn''t do that. >> > > I don''t understand the use case. Can you provide an example?Sure. Suppose by default you want to always deploy the latest revision on the trunk. So, to that end: set :repository, "http://svn/app/trunk" You put that right in your repository. Now, suppose there are times that you want to deploy the latest revision off of a tag instead. There are always multiple ways to do something like this, but one way would be to just specify the new repository as a variable on the command-line: switchtower -r deploy -s repository=http://svn/app/tags/foo -a deploy If variables were set first, you wouldn''t be able to do this, because the set() call in the recipe file would clobber your command-line changes.>> You can do this if you use a proc: >> set :repository, Proc.new { "http://svn/app/trunk@#{rev}" } >> > > Ah, that works just great for me. > >> I''ve thought about having two switches, one for variables set >> "before" and one "after". Would this be useful? > > The Proc approach works for me.Good to know. - Jamis
Ah, nice. I didn''t realize you already had :revision as a variable, defaulting to the latest. In that case my situation gets simple: <in deploy.rb> set :tag, "trunk" set :repository, Proc.new { "http://prodeng/svn/plp/pop/#{tag}" } Generally we''ll just run: switchtower -r deploy -s revision=321 -a deploy (which is clearly how easy you intended to make it), and on rare occasion where we need to deploy off a tag we''ll do switchtower -r deploy -s revision=321 -s tag=tags/1.0 -a deploy Ok, so that''s all great. My next question is about having different machines in each role in dev vs. production. In your blog post you use ENV[''STAGE''] to drive the switch. In keeping w/ the command line options above I''d prefer to specify "-s env=production" -- but I can''t see a way to work the Proc magic in this case.
On Sep 20, 2005, at 10:30 PM, Michael Schoen wrote:> Ok, so that''s all great. My next question is about having different > machines in each role in dev vs. production. In your blog post you > use ENV[''STAGE''] to drive the switch. In keeping w/ the command > line options above I''d prefer to specify "-s env=production" -- but > I can''t see a way to work the Proc magic in this case.Ugh, yah. :) Guess maybe I do need a ''before'' switch for setting variables before the recipes are loaded. Let me think on this one a bit. In the meantime, if you could file this as a feature request on the rails trac, I''d appreciate it. Assign it to jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org, and hopefully that way it won''t fall through the cracks. - Jamis
> bit. In the meantime, if you could file this as a feature request on > the rails trac, I''d appreciate it. Assign it to jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org, > and hopefully that way it won''t fall through the cracks.Will do. And btw, switchtower rocks. Thank you.