# Unique Capistrano Deployment

**URL:** <https://www.ruby-forum.com/t/unique-capistrano-deployment/67135>\
**Category:** Rails\
**Created:** [August 31, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/unique-capistrano-deployment/67135 "2006-08-31T23:15:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [August 31, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/unique-capistrano-deployment/67135/1 "2006-08-31T23:15:13Z")

</div>

I know, everyone’s Capistrano deployment is unique, however, mine may  
be like one I have never seen before.

1. The app is contained on 1 server. I do not have multiple servers.
2. The app is actually deployed twice into two different directories.

Now, #2 is causing me my problems. I can handle the database.yml,  
environment.rb, etc… just fine. The reason I need to deploy the  
application into two different locations is one application is our  
production server, the other application is a training environment.  
Obviously they have different database backends.

Anyone have an idea on how to accomplish this task?

Jeremy

---

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [August 31, 2006, 11:39pm UTC](https://www.ruby-forum.com/t/unique-capistrano-deployment/67135/2 "2006-08-31T23:39:18Z")

</div>

Just saw something cool on jamis’ blog, for handling this, credit goes  
to  
Ben B.:

1. 

nuke[http://jamis.jamisbuck.org/articles/2006/08/30/the-future-of-capistrano#](http://jamis.jamisbuck.org/articles/2006/08/30/the-future-of-capistrano#)  
edit[http://jamis.jamisbuck.org/admin/comments/article/7791/edit/7795](http://jamis.jamisbuck.org/admin/comments/article/7791/edit/7795)  
_Ben B. [http://blog.bleything.net/](http://blog.bleything.net/)_ said about 3 hours  
later:

Another (and IMHO, better) option for staging is to simply create new  
tasks that changes whatever you need to change and then calls the  
deploy  
action:

task :stage, :roles =\> [:app, :db, :web] do  
set :deploy\_to, “/var/www/staging”

```
 deploy

```

end

It’s not as flexible as the env var method, but it’s hard to argue  
with cap stage 🙂

See:

[http://jamis.jamisbuck.org/articles/2006/08/30/the-future-of-capistrano#comments](http://jamis.jamisbuck.org/articles/2006/08/30/the-future-of-capistrano#comments)

So, I imagine you could have a normal deploy task but named something  
different,

do your normal deploy stuff  
and then set the new :deploy\_to dir, and call deploy again.

cheers! good luck

On 8/31/06, Jeremy C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> application into two different locations is one application is our  
> production server, the other application is a training environment.  
> Obviously they have different database backends.
> 
> Anyone have an idea on how to accomplish this task?
> 
> Jeremy
> 
> >

–  
Charles Brian Q.  
self-promotion: [www.seebq.com](http://www.seebq.com)  
highgroove studios: [www.highgroove.com](http://www.highgroove.com)  
slingshot rails hosting: [www.slingshothosting.com](http://www.slingshothosting.com)

---

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [August 31, 2006, 11:41pm UTC](https://www.ruby-forum.com/t/unique-capistrano-deployment/67135/3 "2006-08-31T23:41:18Z")

</div>

On Thu, Aug 31, 2006, Jeremy C. wrote:

> 1. The app is actually deployed twice into two different directories.

I have a similar situation where I have a staging environment and a  
production environment on the same server in different directories. The  
way I got around it was to write a couple of wrapper tasks that change  
deploy\_to and then call the deployment task:

task :stage, :roles =\> [:app, :db, :web] do  
set :deploy\_to, “/var/www/staging”

deploy  
end

Of course, you could do both at the same time:

task :mydeploy, :roles =\> [:app, :db, :web] do  
set :deploy\_to, “/var/www/staging”  
deploy

set :deploy\_to, “/var/www/production”  
deploy  
end

Hope that helps!

Ben

---

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [September 1, 2006, 12:09am UTC](https://www.ruby-forum.com/t/unique-capistrano-deployment/67135/4 "2006-09-01T00:09:21Z")

</div>

On Aug 31, 2006, at 2:29 PM, Ben B. wrote:

> Set up another environment in your app… add a new section to your  
> database.yml, copy your production.rb in config/environments, etc for  
> your training environment.

desc “Set training environment”  
task : training do  
role :app, “app server” # possibly the same as production  
role :web, “web server” # ditto  
set :rails\_env, :training  
set :deploy\_to, “/opt/rails/#{application}/training”  
end

desc “Set production environment”  
task :production do  
role :app, “[app1.whatever.com](http://app1.whatever.com)”, “[app1.whatever.com](http://app1.whatever.com)”  
role :web, “[web1.whatever.com](http://web1.whatever.com)”, [web2.whatever.com](http://web2.whatever.com)  
set :rails\_env, :production  
set :deploy\_to, “/opt/rails/#{application}/production”  
end

Now:

$ cap production deploy  
$ cap training deploy

$ cap \<production/training\>

Etc.

–  
Chris W.

> **[err.the\_blog](http://errtheblog.com)**
>
> Err the Blog: Ruby and Rails from the front.

---

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [August 31, 2006, 11:47pm UTC](https://www.ruby-forum.com/t/unique-capistrano-deployment/67135/5 "2006-08-31T23:47:19Z")

</div>

On Thu, Aug 31, 2006, Jeremy C. wrote:

> 1. The app is contained on 1 server. I do not have multiple servers.
> 2. The app is actually deployed twice into two different directories.

Another option just occurred to me, that (if possible) is probably a  
much cleaner solution.

Set up another environment in your app… add a new section to your  
database.yml, copy your production.rb in config/environments, etc for  
your training environment.

Then, set up your webserver to fire up two instances of the same  
codebase, one in the training environment and one in production.

I can’t think of any reason why this wouldn’t work, but I also haven’t  
tried it, so grain of salt and all that.

Ben

---

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [September 1, 2006, 12:41am UTC](https://www.ruby-forum.com/t/unique-capistrano-deployment/67135/6 "2006-09-01T00:41:23Z")

</div>

On Thu, Aug 31, 2006, Chris W. wrote:

> $ cap production deploy  
> $ cap training deploy
> 
> $ cap \<production/training\>

Ahh, I see the difference now. I didn’t know you could chain tasks like  
that. Very nice!

Ben

---

<div class="post-metadata">

**Author:** ![jcanady](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@jcanady](https://www.ruby-forum.com/u/jcanady)\
**Post date:** [September 1, 2006, 12:39am UTC](https://www.ruby-forum.com/t/unique-capistrano-deployment/67135/7 "2006-09-01T00:39:23Z")

</div>

On Thu, Aug 31, 2006, Chris W. wrote:

> role :app, “[app1.whatever.com](http://app1.whatever.com)”, “[app1.whatever.com](http://app1.whatever.com)”  
> role :web, “[web1.whatever.com](http://web1.whatever.com)”, [web2.whatever.com](http://web2.whatever.com)  
> set :rails\_env, :production  
> set :deploy\_to, “/opt/rails/#{application}/production”  
> end

Isn’t that what I said in my first email? 🙂

I was trying to come up with a way to not require one’s code to be in  
two places at once.

Ben
