staging and live app with capistrano
Asked Answered
P

1

5

I thought I'd do a simple yet potentially very useful thing, and create another symlink called live, that points to an arbitrary release, and leave current at the head where it usually is:

20120519235508 
20120521004833 
20120521024312 <-- live
20120521025150 
20120521030449 <-- current 

I then configured www.mysite.com to hit

live/public 

and stage.mysite.com to hit

current/public

Unfortunately both hosts seem to run the same app, and not 2 different apps. I've confirmed the httpd.conf has the correct settings and restarted it. However no change, they're both still running the same app, the app referenced by current/public to be exact.

I don't know if I have a setting wrong, or if something else needs to be restarted, or if this simply can't work as I imagined. I'm using passenger.

Can someone shed some light on this subject, because this configuration would be VERY useful to me for many projects.

Pannonia answered 21/5, 2012 at 4:17 Comment(0)
B
12

Instead of creating an other symlink in the releases directory, I suggest to use the multistage extension. With this extension you can define different stages and add custom configuration to them. So instead of using one deployment directory for both staging and production, use a separate one for each other.

Add these lines to deploy.rb:

require "capistrano/ext/multistage"

set :stages, ["staging", "production"]
set :default_stage, "staging"

Remove the deploy_to variable from deploy.rb. Then create a deploy directory inside config which has files with the stage names. In this case: deploy/staging.rb and deploy/production.rb. The content of staging.rb:

set :rails_env, "staging"
set :deploy_to, "staging/capistrano"

And similarly for production.rb:

set :rails_env, "production"
set :deploy_to, "production/capistrano"

Of course change the paths in deploy_to. Then point staging.example.com to staging/capistrano/current/public and www.example.com to production/capistrano/current/public.

To do a staging deploy, execute cap staging deploy or simple cap deploy (remember, staging was set to default in deploy.rb) and cap production deploy to deploy to production.

Braggart answered 21/5, 2012 at 9:21 Comment(3)
Gergo, this is totally the way to go. Thank you for this. I also did solve the problem above btw, it was because of the PassengerAppRoot in the .htaccess file.Pannonia
it seems you didn't mention that I have to install the capistrano-ext gem?Pannonia
Possible. It was already available on my system (OS X) when I started using it, I don't remember I had to install it manually.Braggart

© 2022 - 2024 — McMap. All rights reserved.