# Application cookbook w/ Rails app

**URL:** <https://discourse.chef.io/t/application-cookbook-w-rails-app/2942>\
**Category:** Chef Infra (archive)\
**Created:** [July 21, 2012, 5:09pm UTC](https://discourse.chef.io/t/application-cookbook-w-rails-app/2942 "2012-07-21T17:09:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wes\_Morgan](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@Wes\_Morgan](https://discourse.chef.io/u/Wes_Morgan)\
**Post date:** [July 21, 2012, 5:09pm UTC](https://discourse.chef.io/t/application-cookbook-w-rails-app/2942/1 "2012-07-21T17:09:30Z")

</div>

I’m trying to deploy a Rails app using the new application cookbook. According to the README, I’m supposed to declare a dependency on the application\_rails cookbook in the metadata.rb, but that doesn’t seem to exist. Earlier in the README, application\_ruby is mentioned, so I switched it to that. Do we need a documentation fix there?

Anyway, I can’t quite figure out how the rails-y portion of the cookbook is supposed to be invoked. Just declaring a “depends” line in metadata.rb doesn’t actually run anything, does it?

I see in the examples that there is a rails do … end block in the application’s block. Is that what triggers it?

Does anyone have a working example of deploying a Rails app w/ the new application cookbook?

Wes

---

<div class="post-metadata">

**Author:** ![Andrea\_Campi](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/andrea_campi/32/514_2.png) [@Andrea\_Campi](https://discourse.chef.io/u/Andrea_Campi)\
**Post date:** [July 21, 2012, 5:27pm UTC](https://discourse.chef.io/t/application-cookbook-w-rails-app/2942/2 "2012-07-21T17:27:07Z")

</div>

Did you read the README in application\_ruby?

On Jul 21, 2012, at 7:09 PM, Wes Morgan [cap10morgan@gmail.com](mailto:cap10morgan@gmail.com) wrote:

> I'm trying to deploy a Rails app using the new application cookbook. According to the README, I'm supposed to declare a dependency on the application\_rails cookbook in the metadata.rb, but that doesn't seem to exist. Earlier in the README, application\_ruby is mentioned, so I switched it to that. Do we need a documentation fix there?
> 
> Anyway, I can't quite figure out how the rails-y portion of the cookbook is supposed to be invoked. Just declaring a "depends" line in metadata.rb doesn't actually run anything, does it?
> 
> I see in the examples that there is a rails do ... end block in the application's block. Is that what triggers it?
> 
> Does anyone have a working example of deploying a Rails app w/ the new application cookbook?
> 
> Wes

---

<div class="post-metadata">

**Author:** ![Igor\_Afonov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/igor_afonov/32/686_2.png) [@Igor\_Afonov](https://discourse.chef.io/u/Igor_Afonov)\
**Post date:** [July 21, 2012, 5:58pm UTC](https://discourse.chef.io/t/application-cookbook-w-rails-app/2942/3 "2012-07-21T17:58:58Z")

</div>

Hi, take a look into [GitHub - iafonov/stacker: A convenient way to quickly setup & maintain web server infrastructure using chef](https://github.com/iafonov/stacker). This is  
boilerplate chef repository I'm using to deploy rails applications. It has  
working example and uses application and application\_ruby cookbooks.

Particulary you could be interested in the following things:  
Deploy recipe:  
[https://github.com/iafonov/stacker/blob/master/vendor-cookbooks/copycopter/recipes/deploy.rb](https://github.com/iafonov/stacker/blob/master/vendor-cookbooks/copycopter/recipes/deploy.rb)  
Application's cookbook:  
[https://github.com/iafonov/stacker/tree/master/vendor-cookbooks/copycopter](https://github.com/iafonov/stacker/tree/master/vendor-cookbooks/copycopter)

Also I've open sourced a cookbook for managing deployment of several rails  
applications, you can take a look into it here:

> **[GitHub - iafonov/rails\_ghetto: Chef cookbook intended for managing &...](https://github.com/iafonov/rails_ghetto)**
>
> Chef cookbook intended for managing & deployment of multiple rack-based applications living on one server behind nginx. Supports asset pipeline right from the box. - GitHub - iafonov/rails\_ghet...

Hope it helps!  
Igor

On Sat, Jul 21, 2012 at 8:09 PM, Wes Morgan [cap10morgan@gmail.com](mailto:cap10morgan@gmail.com) wrote:

> I'm trying to deploy a Rails app using the new application cookbook.  
> According to the README, I'm supposed to declare a dependency on the  
> application\_rails cookbook in the metadata.rb, but that doesn't seem to  
> exist. Earlier in the README, application\_ruby is mentioned, so I switched  
> it to that. Do we need a documentation fix there?
> 
> Anyway, I can't quite figure out how the rails-y portion of the cookbook  
> is supposed to be invoked. Just declaring a "depends" line in metadata.rb  
> doesn't actually run anything, does it?
> 
> I see in the examples that there is a rails do ... end block in the  
> application's block. Is that what triggers it?
> 
> Does anyone have a working example of deploying a Rails app w/ the new  
> application cookbook?
> 
> Wes

---

<div class="post-metadata">

**Author:** ![Denis\_Haskin1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/denis_haskin1/32/584_2.png) [@Denis\_Haskin1](https://discourse.chef.io/u/Denis_Haskin1)\
**Post date:** [July 21, 2012, 6:20pm UTC](https://discourse.chef.io/t/application-cookbook-w-rails-app/2942/4 "2012-07-21T18:20:43Z")

</div>

Correct, you need the ruby do block.

I have a cookbook for my application, which has

depends "application\_ruby"

in its metadata.rb, and then in its default recipe, has this (as an  
example):

application "zmx\_app" do  
path "/srv/zmx"  
owner 'nobody'  
group 'nogroup'

repository 'git@github.com:zmxmusic/zmx2.git'  
deploy\_key "-----BEGIN RSA PRIVATE KEY----- ...etc... -----END RSA  
PRIVATE KEY-----\n" # note embedded newlines  
if node.chef\_environment=='production'  
revision '2.26'  
action :deploy  
else  
revision 'master'  
action :force\_deploy  
end

db = "zmx\_#{node.chef\_environment}"

rails do  
gems ['bundler']  
precompile\_assets true  
database do  
reconnect true  
encoding 'utf8'  
username '...'  
adapter 'mysql2'  
password '...'  
database db  
end  
database\_master\_role "zmx\_database\_master"  
end

passenger\_apache2 do  
end  
end

There might well be better ways to do it; I migrated up from the old  
cookbook. My apache/passenger config is really done in other recipes; one  
of these days I'll take care of that and probably migrate to unicorn,  
nginx, etc.

Don't know what you're using for database. I had to wrestle mightily with  
the mysql (and database?) cookbooks to get a working set of  
cookbooks+recipes that would come up from scratch on AWS... I'm not even  
convinced I've actually got that, yet, but needed to move on and get stuff  
done.

--  
Denis Haskin

On Sat, Jul 21, 2012 at 1:09 PM, Wes Morgan [cap10morgan@gmail.com](mailto:cap10morgan@gmail.com) wrote:

> I'm trying to deploy a Rails app using the new application cookbook.  
> According to the README, I'm supposed to declare a dependency on the  
> application\_rails cookbook in the metadata.rb, but that doesn't seem to  
> exist. Earlier in the README, application\_ruby is mentioned, so I switched  
> it to that. Do we need a documentation fix there?
> 
> Anyway, I can't quite figure out how the rails-y portion of the cookbook  
> is supposed to be invoked. Just declaring a "depends" line in metadata.rb  
> doesn't actually run anything, does it?
> 
> I see in the examples that there is a rails do ... end block in the  
> application's block. Is that what triggers it?
> 
> Does anyone have a working example of deploying a Rails app w/ the new  
> application cookbook?
> 
> Wes

---

<div class="post-metadata">

**Author:** ![Wes\_Morgan](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@Wes\_Morgan](https://discourse.chef.io/u/Wes_Morgan)\
**Post date:** [July 21, 2012, 7:02pm UTC](https://discourse.chef.io/t/application-cookbook-w-rails-app/2942/5 "2012-07-21T19:02:23Z")

</div>

Thanks for the insight and examples, Denis & Igor. I think I was being thrown off by the documentation errors and all the deprecated code in the application cookbook. It's starting to come together now.

Wes

On Jul 21, 2012, at 12:20 PM, Denis Haskin wrote:

> Correct, you need the ruby do block.
> 
> I have a cookbook for my application, which has
> 
> depends "application\_ruby"
> 
> in its metadata.rb, and then in its default recipe, has this (as an example):
> 
> application "zmx\_app" do  
> path "/srv/zmx"  
> owner 'nobody'  
> group 'nogroup'
> 
> repository 'git@github.com:zmxmusic/zmx2.git'  
> deploy\_key "-----BEGIN RSA PRIVATE KEY----- ...etc... -----END RSA PRIVATE KEY-----\n" # note embedded newlines  
> if node.chef\_environment=='production'  
> revision '2.26'  
> action :deploy  
> else  
> revision 'master'  
> action :force\_deploy  
> end
> 
> db = "zmx\_#{node.chef\_environment}"
> 
> rails do  
> gems ['bundler']  
> precompile\_assets true  
> database do  
> reconnect true  
> encoding 'utf8'  
> username '...'  
> adapter 'mysql2'  
> password '...'  
> database db  
> end  
> database\_master\_role "zmx\_database\_master"  
> end
> 
> passenger\_apache2 do  
> end  
> end
> 
> There might well be better ways to do it; I migrated up from the old cookbook. My apache/passenger config is really done in other recipes; one of these days I'll take care of that and probably migrate to unicorn, nginx, etc.
> 
> Don't know what you're using for database. I had to wrestle mightily with the mysql (and database?) cookbooks to get a working set of cookbooks+recipes that would come up from scratch on AWS... I'm not even convinced I've actually got that, yet, but needed to move on and get stuff done.
> 
> --  
> Denis Haskin
> 
> On Sat, Jul 21, 2012 at 1:09 PM, Wes Morgan [cap10morgan@gmail.com](mailto:cap10morgan@gmail.com) wrote:  
> I'm trying to deploy a Rails app using the new application cookbook. According to the README, I'm supposed to declare a dependency on the application\_rails cookbook in the metadata.rb, but that doesn't seem to exist. Earlier in the README, application\_ruby is mentioned, so I switched it to that. Do we need a documentation fix there?
> 
> Anyway, I can't quite figure out how the rails-y portion of the cookbook is supposed to be invoked. Just declaring a "depends" line in metadata.rb doesn't actually run anything, does it?
> 
> I see in the examples that there is a rails do ... end block in the application's block. Is that what triggers it?
> 
> Does anyone have a working example of deploying a Rails app w/ the new application cookbook?
> 
> Wes

---

<div class="post-metadata">

**Author:** ![Denis\_Haskin1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/denis_haskin1/32/584_2.png) [@Denis\_Haskin1](https://discourse.chef.io/u/Denis_Haskin1)\
**Post date:** [July 21, 2012, 7:21pm UTC](https://discourse.chef.io/t/application-cookbook-w-rails-app/2942/6 "2012-07-21T19:21:20Z")

</div>

Good to hear. Fork, fix, and submit a pull request!

Sent from mobile  
On Jul 21, 2012 3:02 PM, "Wes Morgan" [cap10morgan@gmail.com](mailto:cap10morgan@gmail.com) wrote:

> Thanks for the insight and examples, Denis & Igor. I think I was being  
> thrown off by the documentation errors and all the deprecated code in the  
> application cookbook. It's starting to come together now.
> 
> Wes
> 
> On Jul 21, 2012, at 12:20 PM, Denis Haskin wrote:
> 
> Correct, you need the ruby do block.
> 
> I have a cookbook for my application, which has
> 
> depends "application\_ruby"
> 
> in its metadata.rb, and then in its default recipe, has this (as an  
> example):
> 
> application "zmx\_app" do  
> path "/srv/zmx"  
> owner 'nobody'  
> group 'nogroup'
> 
> repository 'git@github.com:zmxmusic/zmx2.git'  
> deploy\_key "-----BEGIN RSA PRIVATE KEY----- ...etc... -----END RSA  
> PRIVATE KEY-----\n" # note embedded newlines  
> if node.chef\_environment=='production'  
> revision '2.26'  
> action :deploy  
> else  
> revision 'master'  
> action :force\_deploy  
> end
> 
> db = "zmx\_#{node.chef\_environment}"
> 
> rails do  
> gems ['bundler']  
> precompile\_assets true  
> database do  
> reconnect true  
> encoding 'utf8'  
> username '...'  
> adapter 'mysql2'  
> password '...'  
> database db  
> end  
> database\_master\_role "zmx\_database\_master"  
> end
> 
> passenger\_apache2 do  
> end  
> end
> 
> There might well be better ways to do it; I migrated up from the old  
> cookbook. My apache/passenger config is really done in other recipes; one  
> of these days I'll take care of that and probably migrate to unicorn,  
> nginx, etc.
> 
> Don't know what you're using for database. I had to wrestle mightily with  
> the mysql (and database?) cookbooks to get a working set of  
> cookbooks+recipes that would come up from scratch on AWS... I'm not even  
> convinced I've actually got that, yet, but needed to move on and get stuff  
> done.
> 
> --  
> Denis Haskin
> 
> On Sat, Jul 21, 2012 at 1:09 PM, Wes Morgan [cap10morgan@gmail.com](mailto:cap10morgan@gmail.com) wrote:
> 
> > I'm trying to deploy a Rails app using the new application cookbook.  
> > According to the README, I'm supposed to declare a dependency on the  
> > application\_rails cookbook in the metadata.rb, but that doesn't seem to  
> > exist. Earlier in the README, application\_ruby is mentioned, so I switched  
> > it to that. Do we need a documentation fix there?
> > 
> > Anyway, I can't quite figure out how the rails-y portion of the cookbook  
> > is supposed to be invoked. Just declaring a "depends" line in metadata.rb  
> > doesn't actually run anything, does it?
> > 
> > I see in the examples that there is a rails do ... end block in the  
> > application's block. Is that what triggers it?
> > 
> > Does anyone have a working example of deploying a Rails app w/ the new  
> > application cookbook?
> > 
> > Wes
