Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added nginx to recipes and added roles (closer to production)

  • Loading branch information...
commit d415adc6c7807156b564a4850d99ef1777485d19 1 parent 63fb92d
@truepattern authored
Showing with 8,350 additions and 9 deletions.
  1. +26 −7 Vagrantfile
  2. +2 −2 app/server.js
  3. +40 −0 cookbooks/application/CHANGELOG.md
  4. +29 −0 cookbooks/application/CONTRIBUTING
  5. +201 −0 cookbooks/application/LICENSE
  6. +230 −0 cookbooks/application/README.md
  7. +67 −0 cookbooks/application/examples/data_bags/apps/django_app.json
  8. +61 −0 cookbooks/application/examples/data_bags/apps/java_app.json
  9. +63 −0 cookbooks/application/examples/data_bags/apps/php_app.json
  10. +75 −0 cookbooks/application/examples/data_bags/apps/rails_app.json
  11. +2 −0  cookbooks/application/examples/environments
  12. +101 −0 cookbooks/application/examples/templates/default/LocalSettings.php.erb
  13. +76 −0 cookbooks/application/examples/templates/default/wp-config.php.erb
  14. +183 −0 cookbooks/application/libraries/default.rb
  15. +22 −0 cookbooks/application/metadata.rb
  16. +182 −0 cookbooks/application/providers/default.rb
  17. +30 −0 cookbooks/application/recipes/default.rb
  18. +196 −0 cookbooks/application/recipes/django.rb
  19. +57 −0 cookbooks/application/recipes/gunicorn.rb
  20. +110 −0 cookbooks/application/recipes/java_webapp.rb
  21. +55 −0 cookbooks/application/recipes/mod_php_apache2.rb
  22. +54 −0 cookbooks/application/recipes/passenger_apache2.rb
  23. +146 −0 cookbooks/application/recipes/php.rb
  24. +218 −0 cookbooks/application/recipes/rails.rb
  25. +41 −0 cookbooks/application/recipes/tomcat.rb
  26. +60 −0 cookbooks/application/recipes/unicorn.rb
  27. +133 −0 cookbooks/application/resources/default.rb
  28. +9 −0 cookbooks/application/templates/default/context.xml.erb
  29. +10 −0 cookbooks/application/templates/default/database.yml.erb
  30. +8 −0 cookbooks/application/templates/default/deploy-ssh-wrapper.erb
  31. +10 −0 cookbooks/application/templates/default/memcached.yml.erb
  32. +13 −0 cookbooks/application/templates/default/myproj.conf.erb
  33. +34 −0 cookbooks/application/templates/default/php.conf.erb
  34. +13 −0 cookbooks/application/templates/default/rails_nginx_passenger.conf.erb
  35. +19 −0 cookbooks/application/templates/default/settings.py.erb
  36. +2 −0  cookbooks/application/templates/default/sv-gunicorn-log-run.erb
  37. +10 −0 cookbooks/application/templates/default/sv-gunicorn-run.erb
  38. +3 −0  cookbooks/application/templates/default/sv-unicorn-log-run.erb
  39. +7 −0 cookbooks/application/templates/default/sv-unicorn-run.erb
  40. +3 −0  cookbooks/application_nginx/CHANGELOG.md
  41. +29 −0 cookbooks/application_nginx/CONTRIBUTING
  42. +201 −0 cookbooks/application_nginx/LICENSE
  43. +122 −0 cookbooks/application_nginx/README.md
  44. +9 −0 cookbooks/application_nginx/metadata.rb
  45. +68 −0 cookbooks/application_nginx/providers/nginx_load_balancer.rb
  46. +28 −0 cookbooks/application_nginx/resources/nginx_load_balancer.rb
  47. +18 −0 cookbooks/application_nginx/templates/default/load_balancer.conf.erb
  48. +4 −0 cookbooks/nginx/.gitignore
  49. +59 −0 cookbooks/nginx/CHANGELOG.md
  50. +29 −0 cookbooks/nginx/CONTRIBUTING
  51. +3 −0  cookbooks/nginx/Gemfile
  52. +201 −0 cookbooks/nginx/LICENSE
  53. +210 −0 cookbooks/nginx/README.md
  54. +70 −0 cookbooks/nginx/attributes/default.rb
  55. +3 −0  cookbooks/nginx/attributes/echo.rb
  56. +30 −0 cookbooks/nginx/attributes/geoip.rb
  57. +24 −0 cookbooks/nginx/attributes/naxsi.rb
  58. +7 −0 cookbooks/nginx/attributes/passenger.rb
  59. +37 −0 cookbooks/nginx/attributes/source.rb
  60. +23 −0 cookbooks/nginx/attributes/upload_progress.rb
  61. +35 −0 cookbooks/nginx/definitions/nginx_site.rb
  62. +73 −0 cookbooks/nginx/files/default/mime.types
  63. +70 −0 cookbooks/nginx/files/default/naxsi_core.rules
  64. +12 −0 cookbooks/nginx/files/default/tests/minitest/default_test.rb
  65. +7 −0 cookbooks/nginx/files/default/tests/minitest/helpers.rb
  66. +9 −0 cookbooks/nginx/files/default/tests/minitest/source_test.rb
  67. +95 −0 cookbooks/nginx/metadata.rb
  68. +41 −0 cookbooks/nginx/recipes/authorized_ips.rb
  69. +67 −0 cookbooks/nginx/recipes/commons.rb
  70. +42 −0 cookbooks/nginx/recipes/default.rb
  71. +46 −0 cookbooks/nginx/recipes/http_echo_module.rb
  72. +103 −0 cookbooks/nginx/recipes/http_geoip_module.rb
  73. +23 −0 cookbooks/nginx/recipes/http_gzip_static_module.rb
  74. +46 −0 cookbooks/nginx/recipes/http_realip_module.rb
  75. +23 −0 cookbooks/nginx/recipes/http_ssl_module.rb
  76. +36 −0 cookbooks/nginx/recipes/http_stub_status_module.rb
  77. +53 −0 cookbooks/nginx/recipes/naxsi_module.rb
  78. +32 −0 cookbooks/nginx/recipes/ohai_plugin.rb
  79. +51 −0 cookbooks/nginx/recipes/passenger.rb
  80. +189 −0 cookbooks/nginx/recipes/source.rb
  81. +47 −0 cookbooks/nginx/recipes/upload_progress_module.rb
  82. +97 −0 cookbooks/nginx/templates/debian/nginx.init.erb
  83. +11 −0 cookbooks/nginx/templates/default/default-site.erb
  84. +6 −0 cookbooks/nginx/templates/default/modules/authorized_ip.erb
  85. +4 −0 cookbooks/nginx/templates/default/modules/http_geoip.conf.erb
  86. +4 −0 cookbooks/nginx/templates/default/modules/http_realip.conf.erb
  87. +14 −0 cookbooks/nginx/templates/default/modules/nginx_status.erb
  88. +3 −0  cookbooks/nginx/templates/default/modules/passenger.conf.erb
  89. +48 −0 cookbooks/nginx/templates/default/nginx.conf.erb
  90. +92 −0 cookbooks/nginx/templates/default/nginx.init.erb
  91. +15 −0 cookbooks/nginx/templates/default/nginx.pill.erb
  92. +1 −0  cookbooks/nginx/templates/default/nginx.sysconfig.erb
  93. +29 −0 cookbooks/nginx/templates/default/nxdissite.erb
  94. +38 −0 cookbooks/nginx/templates/default/nxensite.erb
  95. +66 −0 cookbooks/nginx/templates/default/plugins/nginx.rb.erb
  96. +2 −0  cookbooks/nginx/templates/default/sv-nginx-log-run.erb
  97. +3 −0  cookbooks/nginx/templates/default/sv-nginx-run.erb
  98. +97 −0 cookbooks/nginx/templates/ubuntu/nginx.init.erb
  99. +5 −0 cookbooks/nginx/test/kitchen/Kitchenfile
  100. +12 −0 cookbooks/ohai/CHANGELOG.md
  101. +29 −0 cookbooks/ohai/CONTRIBUTING
  102. +201 −0 cookbooks/ohai/LICENSE
  103. +49 −0 cookbooks/ohai/README.md
  104. +24 −0 cookbooks/ohai/attributes/default.rb
  105. +1 −0  cookbooks/ohai/files/default/plugins/README
  106. +22 −0 cookbooks/ohai/metadata.rb
  107. +52 −0 cookbooks/ohai/recipes/default.rb
  108. +3 −0  cookbooks/runit/CHANGELOG.md
  109. +29 −0 cookbooks/runit/CONTRIBUTING
  110. +201 −0 cookbooks/runit/LICENSE
  111. +226 −0 cookbooks/runit/README.md
  112. +31 −0 cookbooks/runit/attributes/default.rb
  113. +164 −0 cookbooks/runit/definitions/runit_service.rb
  114. +1 −0  cookbooks/runit/files/default/runit.seed
  115. 0  cookbooks/runit/files/default/runsvdir
  116. +6 −0 cookbooks/runit/files/ubuntu-6.10/runsvdir
  117. +7 −0 cookbooks/runit/files/ubuntu-7.04/runsvdir
  118. +7 −0 cookbooks/runit/files/ubuntu-7.10/runsvdir
  119. +7 −0 cookbooks/runit/files/ubuntu-8.04/runsvdir
  120. +37 −0 cookbooks/runit/metadata.rb
  121. +72 −0 cookbooks/runit/recipes/default.rb
  122. +32 −0 cookbooks/runit/templates/gentoo/runit-start.sh.erb
  123. +7 −0 cookbooks/sudo/CHANGELOG.md
  124. +29 −0 cookbooks/sudo/CONTRIBUTING
  125. +201 −0 cookbooks/sudo/LICENSE
  126. +155 −0 cookbooks/sudo/README.md
  127. +23 −0 cookbooks/sudo/attributes/default.rb
  128. +4 −0 cookbooks/sudo/files/default/README.sudoers
  129. +45 −0 cookbooks/sudo/metadata.rb
  130. +143 −0 cookbooks/sudo/providers/default.rb
  131. +52 −0 cookbooks/sudo/recipes/default.rb
  132. +37 −0 cookbooks/sudo/resources/default.rb
  133. +24 −0 cookbooks/sudo/templates/default/sudoers.erb
  134. +7 −0 cookbooks/users/CHANGELOG.md
  135. +29 −0 cookbooks/users/CONTRIBUTING
  136. +201 −0 cookbooks/users/LICENSE
  137. +129 −0 cookbooks/users/README.md
  138. +10 −0 cookbooks/users/metadata.rb
  139. +115 −0 cookbooks/users/providers/manage.rb
  140. +26 −0 cookbooks/users/recipes/sysadmins.rb
  141. +37 −0 cookbooks/users/resources/manage.rb
  142. +4 −0 cookbooks/users/templates/default/authorized_keys.erb
  143. +3 −0  cookbooks/vim/CHANGELOG.md
  144. +29 −0 cookbooks/vim/CONTRIBUTING
  145. +201 −0 cookbooks/vim/LICENSE
  146. +43 −0 cookbooks/vim/README.md
  147. +20 −0 cookbooks/vim/attributes/default.rb
  148. +11 −0 cookbooks/vim/metadata.rb
  149. +35 −0 cookbooks/vim/recipes/default.rb
  150. +3 −0  readme.md
  151. +20 −0 roles/base.rb
  152. +18 −0 roles/db_master.rb
  153. +16 −0 roles/webserver.rb
  154. +1 −0  site-cookbooks/mysite/README.md
  155. +25 −0 site-cookbooks/mysite/recipes/default.rb
  156. +23 −0 site-cookbooks/mysite/templates/default/nginx/mysite.conf.erb
View
33 Vagrantfile
@@ -8,31 +8,50 @@ Vagrant::Config.run do |config|
# Forward a port from the guest to the host, which allows for outside
# computers to access the VM, whereas host only networking does not.
- config.vm.forward_port 8080, 8080
+ config.vm.forward_port 80, 8080
# Share an additional folder to the guest VM. The first argument is
# an identifier, the second is the path on the guest to mount the
# folder, and the third is the path on the host to the actual folder.
+ #config.vm.share_folder "v-root", "/vagrant", "."
config.vm.share_folder "app", "/home/vagrant/app", "app"
+ config.vm.host_name = "dev-nodejs"
+
# allow for symlinks in the app folder
config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/app", "1"]
+ config.vm.customize do |vm|
+ vm.memory_size = 1024
+ end
# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
# some recipes and/or roles.
-
config.vm.provision :chef_solo do |chef|
- chef.cookbooks_path = "cookbooks"
- chef.add_recipe "apt"
- chef.add_recipe "git"
+
+ # chef config
+ chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
+ chef.roles_path = "roles"
+ chef.data_bags_path = "data_bags"
+ chef.log_level = :info
+ #chef.log_level = :debug
+
+ # add roles
+ chef.add_role("db_master")
+ chef.add_role("webserver")
+
+ # add mysite to webserver
+ chef.add_recipe("mysite")
+
+ # add node.js
chef.add_recipe "nodejs"
- chef.add_recipe "mongodb::10gen_repo"
- chef.add_recipe "mongodb::default"
+
+ # receipe config
chef.json = {
"nodejs" => {
:install_method => "package"
}
}
+
end
end
View
4 app/server.js
@@ -3,6 +3,6 @@ var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!\n');
-}).listen(8080);
+}).listen(3000);
-console.log('Server running on port 8080');
+console.log('Server running on port 3000');
View
40 cookbooks/application/CHANGELOG.md
@@ -0,0 +1,40 @@
+## v1.0.2:
+
+* [COOK-1312] - string callbacks fail with method not found (really
+ included this time)
+* [COOK-1332] - add `release_path` and `shared_path` methods
+* [COOK-1333] - add example for running migrations
+* [COOK-1360] - fix minor typos in README
+* [COOK-1374] - use runit attributes in unicorn run script
+
+## v1.0.0:
+
+This release introduces the LWRP for application deployment, as well
+as other improvements. The recipes will be deprecated in August 2012
+as indicated by their warning messages and in the README.md.
+
+* [COOK-634] - Implement LWRP for application deployment
+* [COOK-1116] - use other SCMs than git
+* [COOK-1252] - add :force_deploy that maps to corresponding action of
+ deploy resource
+* [COOK-1253] - fix rollback error
+* [COOK-1312] - string callbacks fail with method not found
+* [COOK-1313] - implicit file based hooks aren't invoked
+* [COOK-1318] - Create to_ary method to resolve issue in resources()
+ lookup on "application[foo]" resources
+
+## v0.99.14:
+
+* [COOK-1065] - use pip in virtualenv during deploy
+
+## v0.99.12:
+
+* [COOK-606] application cookbook deployment recipes should use ipaddress instead of fqdn
+
+## v0.99.11:
+
+* make the _default chef_environment look like production rails env
+
+## v0.99.10:
+
+* Use Chef 0.10's `node.chef_environment` instead of `node['app_environment']`.
View
29 cookbooks/application/CONTRIBUTING
@@ -0,0 +1,29 @@
+If you would like to contribute, please open a ticket in JIRA:
+
+* http://tickets.opscode.com
+
+Create the ticket in the COOK project and use the cookbook name as the
+component.
+
+For all code contributions, we ask that contributors sign a
+contributor license agreement (CLA). Instructions may be found here:
+
+* http://wiki.opscode.com/display/chef/How+to+Contribute
+
+When contributing changes to individual cookbooks, please do not
+modify the version number in the metadata.rb. Also please do not
+update the CHANGELOG.md for a new version. Not all changes to a
+cookbook may be merged and released in the same versions. Opscode will
+handle the version updates during the release process. You are welcome
+to correct typos or otherwise make updates to documentation in the
+README.
+
+If a contribution adds new platforms or platform versions, indicate
+such in the body of the commit message(s), and update the relevant
+COOK ticket. When writing commit messages, it is helpful for others if
+you indicate the COOK ticket. For example:
+
+ git commit -m '[COOK-1041] Updated pool resource to correctly delete.'
+
+In the ticket itself, it is also helpful if you include log output of
+a successful Chef run, but this is not absolutely required.
View
201 cookbooks/application/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
View
230 cookbooks/application/README.md
@@ -0,0 +1,230 @@
+Application cookbook
+====================
+
+This cookbook is designed to be able to describe and deploy web applications. It provides the basic infrastructure; other cookbooks are required to support specific combinations of frameworks and application servers. The following cookbooks are available at this time:
+
+* application\_java (Java and Tomcat)
+* application\_nginx (nginx reverse proxy)
+* application\_php (PHP with mod\_php\_apache2)
+* application\_python (Django with Gunicorn)
+* application\_ruby (Rails with Passenger or Unicorn)
+
+Backward compatibility
+----------------------
+
+Previous versions of this cookbook used a set of recipes, with the configuration stored in an `apps` data bag.
+
+This mode of operation has been DEPRECATED. The existing recipes will keep working for 3 months, and will then be removed. You are advised to upgrade your applications as soon as possible.
+
+Requirements
+============
+
+Chef 0.10.0 or higher required (for Chef environment use).
+
+The following Opscode cookbooks are dependencies, as this cookbook supports automating a large number of web application stacks.
+
+* runit
+* unicorn
+* passenger_apache2
+* tomcat
+* python
+* gunicorn
+* apache2
+* php
+
+Deprecated Recipes
+==================
+
+The following recipes are deprecated:
+
+* `default`
+* `django`
+* `gunicorn`
+* `java_webapp`
+* `mod_php_apache2`
+* `passenger_apache2`
+* `php`
+* `rails`
+* `tomcat`
+* `unicorn`
+
+Resources/Providers
+===================
+
+The `application` LWRP configures the basic properties of most applications, regardless of the framework or application server they use. These include:
+
+* SCM information for the deployment, such as the repository URL and branch name;
+* deployment destination, including the filesystem path to deploy to;
+* any OS packages to install as dependencies;
+* optional callback to control the deployment.
+
+This LWRP uses the `deploy_revision` LWRP to perform the bulk of its tasks, and many concepts and parameters map directly to it. Check the documentation for `deploy_revision` for more information.
+
+Configuration of framework-specific aspects of the application are performed by invoking a sub-resource; see the appropriate cookbook for more documentation.
+
+# Actions
+
+- :deploy: deploy an application, including any necessary configuration, restarting the associated service if necessary
+- :force_deploy: same as :deploy, but it will send a :force\_deploy action to the deploy resource, directing it to deploy the application even if the same revision is already deployed
+
+# Attribute Parameters
+
+- name: name attribute. The name of the application you are setting up. This will be used to derive the default value for other attribute
+- packages: an Array or Hash of packages to be installed before starting the deployment
+- path: target path of the deployment; it will be created if it does not exist
+- owner: the user that shall own the target path
+- group: the group that shall own the target path
+- strategy: the underlying LWRP that will be used to perform the deployment. The default is `:deploy_revision`, and it should never be necessary to change it
+- scm_provider: the provider class to use for the deployment. It defaults to `Chef::Provider::Git`, you can set it to `Chef::Provider::Subversion` to deploy from an SVN repository
+- repository: the URL of the repository the application should be checked out from
+- revision: an identifier pointing to the revision that should be checkout out
+- deploy_key: the private key to use to access the repository via SSH
+- rollback\_on\_error: if true, exceptions during a deployment will be caught and a clean rollback to the previous version will be attempted; the exception will then be re-raised. Defaults to true; change it only if you know what you are doing
+- environment: a Hash of environment variables to set while running migrations
+- purge\_before\_symlink: an Array of paths (relative to the checkout) to remove before creating symlinks
+- create\_dirs\_before\_symlink: an Array paths (relative to the checkout) pointing to directories to create before creating symlinks
+- symlinks: a Hash of shared/dir/path => release/dir/path. It determines which files and dirs in the shared directory get symlinked to the current release directory
+- symlink\_before\_migrate: similar to symlinks, except that they will be linked before any migration is run
+- migrate: if `true` then migrations will be run; defaults to false
+- migration_command: a command to run to migrate the application from the previous to the current state
+- restart_command: a command to run when restarting the application
+- environment_name: the name of a framework-specific "environment" (for example the Rails environment). By default it is the same as the Chef environment, unless it is `_default`, in which case it is set to `production`
+
+# Callback Attributes
+
+You can also set a few attributes on this LWRP that are interpreted as callback to be called at specific points during a deployment.
+If you pass a block, it will be evaluated within a new context. If you pass a string, it will be interpreted as a path (relative to the release directory) to a file; if it exists, it will be loaded and evaluated as though it were a Chef recipe.
+
+The following callback attributes are available:
+
+- before\_deploy: invoked immediately after initial setup and before the deployment proper is started. This callback will be invoked on every Chef run
+- before\_migrate
+- before\_symlink
+- before\_restart
+- after\_restart
+
+# Sub-resources
+
+Anything that is not a known attribute will be interpreted as the name of a sub-resource; the resource will be looked up, and any nested attribute will be passed to it. More than one sub-resource can be added to an application; the order is significant, with the latter sub-resources overriding any sub-resource that comes before.
+
+Sub-resources can set their own values for some attributes; if they do, they will be merged together with the attribute set on the main resource. The attributes that support this behavior are the following:
+
+- environment: environment variables from the application and from sub-resources will be merged together, with later resources overriding values set in the application or previous resources
+- migration_command: commands from the application and from sub-resources will be concatenated together joined with '&&' and run as a single shell command. The migration will only succeed if all the commands succeed
+- restart_command: commands from the application and from sub-resources will be evaluated in order
+- symlink\_before\_migrate: will be concatenated as a single array
+- callbacks: sub-resources callbacks will be invoked first, followed by the application callbacks
+
+Usage
+=====
+
+To use the application cookbook we recommend creating a cookbook named after the application, e.g. `my_app`. In `metadata.rb` you should declare a dependency on this cookbook and any framework cookbook the application may need. For example a Rails application may include:
+
+ depends "application"
+ depends "application_rails"
+
+The default recipe should describe your application using the `application` LWRP; you may also include additional recipes, for example to set up a database, queues, search engines and other components of your application.
+
+A recipe using this LWRP may look like this:
+
+ application "my_app" do
+ path "/deploy/to/dir"
+ owner "app-user"
+ group "app-group"
+
+ repository "http://git.example.com/my-app.git"
+ revision "production"
+
+ rails do
+ # Rails-specific configuration
+ end
+
+ passenger_apache2 do
+ # Passenger-specific configuration
+ end
+ end
+
+You can of course use any code necessary to determine the value of attributes:
+
+ application "my_app" do
+ repository "http://git.example.com/my-app.git"
+ revision node.chef_environment == "production" ? "production" : "develop"
+ end
+
+Attributes from the application and from sub-resources are merged together:
+
+ application "my_app" do
+ restart_command "kill -1 `cat /var/run/one.pid`"
+ environment "LC_ALL" => "en", "FOO" => "bar"
+
+ rails do
+ restart_command "touch /tmp/something"
+ environment "LC_ALL" => "en_US"
+ end
+
+ passenger_apache2 do
+ environment "FOO" => "baz"
+ end
+ end
+
+ # at the end, you will have:
+ #
+ # restart_command #=> kill -1 `cat /var/run/one.pid` && touch /tmp/something
+ # environment #=> LC_ALL=en_US FOO=baz
+
+Most databases have the concept of migrations (or you can just use your own):
+
+ application "my_app" do
+ path "/deploy/to/dir"
+ owner "app-user"
+ group "app-group"
+
+ repository "http://git.example.com/my-app.git"
+ revision "production"
+
+ php do
+ migrate true
+ migration_command "your-applications-migrate-command"
+ end
+ end
+
+This will run `your-applications-migrate-command`, with the current directory set to the directory of the current checkout.
+
+To use the application cookbook, we recommend creating a role named after the application, e.g. `my_app`. Create a Ruby DSL role in your chef-repo, or create the role directly with knife.
+
+ % knife role show my_app -Fj
+ {
+ "name": "my_app",
+ "chef_type": "role",
+ "json_class": "Chef::Role",
+ "default_attributes": {
+ },
+ "description": "",
+ "run_list": [
+ "recipe[my_app]"
+ ],
+ "override_attributes": {
+ }
+ }
+
+License and Author
+==================
+
+Author:: Adam Jacob (<adam@opscode.com>)
+Author:: Andrea Campi (<andrea.campi@zephirworks.com.com>)
+Author:: Joshua Timberman (<joshua@opscode.com>)
+Author:: Seth Chisamore (<schisamo@opscode.com>)
+
+Copyright 2009-2012, Opscode, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
View
67 cookbooks/application/examples/data_bags/apps/django_app.json
@@ -0,0 +1,67 @@
+{
+ "id": "my_app",
+ "server_roles": [
+ "application specific role(s), typically the name of the app, e.g., my_app",
+ "my_app"
+ ],
+ "type": {
+ "my_app": [
+ "recipes in this application cookbook to run for this role",
+ "django",
+ "gunicorn"
+ ]
+ },
+ "database_slave_role": [
+ "name of the role used by database slaves, typically named after the app, 'my_app_database_slave'",
+ "my_app_database_slave"
+ ],
+ "database_master_role": [
+ "name of the role used by database master, typically named after the app 'my_app_database_master'",
+ "my_app_database_master"
+ ],
+ "repository": "git@github.com:company/my_app.git",
+ "revision": {
+ "production": "commit hash, branch or tag to deploy"
+ },
+ "force": {
+ "production": "true or false w/o quotes to force deployment, see the rails.rb recipe"
+ },
+ "migrate": {
+ "production": "true or false boolean to force migration, see rails.rb recipe"
+ },
+ "databases": {
+ "production": {
+ "encoding": "utf8",
+ "username": "db_user",
+ "adapter": "mysql",
+ "port": "3306",
+ "password": "awesome_password",
+ "database": "db_name_production"
+ }
+ },
+ "mysql_root_password": {
+ "production": "password for the root user in mysql"
+ },
+ "mysql_debian_password": {
+ "production": "password for the debian-sys-maint user on ubuntu/debian"
+ },
+ "mysql_repl_password": {
+ "production": "password for the 'repl' user for replication."
+ },
+ "snapshots_to_keep": {
+ "production": "if using EBS, integer of the number of snapshots we're going to keep for this environment."
+ },
+ "deploy_key": "SSH private key used to deploy from a private git repository",
+ "deploy_to": "path to deploy, e.g. /srv/my_app",
+ "owner": "owner for the application files when deployed",
+ "group": "group for the application files when deployed",
+ "packages": {
+ "package_name": "specific packages required for installation at the OS level to run the app like libraries and specific version, e.g.",
+ "curl": "7.19.5-1ubuntu2"
+ },
+ "pips": {
+ "pip_name": "specific gems required for installation to run the application, and if a specific version is required, e.g.",
+ "django": "1.2"
+ },
+ "local_settings_file":"local_settings.py"
+}
View
61 cookbooks/application/examples/data_bags/apps/java_app.json
@@ -0,0 +1,61 @@
+{
+ "id": "my_app",
+ "server_roles": [
+ "application specific role(s), typically the name of the app, e.g., my_app",
+ "my_app"
+ ],
+ "type": {
+ "my_app": [
+ "recipes in this application cookbook to run for this role",
+ "java_webapp",
+ "tomcat"
+ ]
+ },
+ "database_slave_role": [
+ "name of the role used by database slaves, typically named after the app, 'my_app_database_slave'",
+ "my_app_database_slave"
+ ],
+ "database_master_role": [
+ "name of the role used by database master, typically named after the app 'my_app_database_master'",
+ "my_app_database_master"
+ ],
+ "repository": "git@github.com:company/my_app.git",
+ "revision": {
+ "production": "commit hash, branch or tag to deploy"
+ },
+ "force": {
+ "production": "true or false w/o quotes to force deployment, see the rails.rb recipe"
+ },
+ "databases": {
+ "production": {
+ "max_active": "100",
+ "max_idle": "30",
+ "max_wait": "10000",
+ "username": "db_user",
+ "adapter": "mysql",
+ "driver": "com.mysql.jdbc.Driver",
+ "port": "3306",
+ "password": "awesome_password",
+ "database": "db_name_production"
+ }
+ },
+ "mysql_root_password": {
+ "production": "password for the root user in mysql"
+ },
+ "mysql_debian_password": {
+ "production": "password for the debian-sys-maint user on ubuntu/debian"
+ },
+ "mysql_repl_password": {
+ "production": "password for the 'repl' user for replication."
+ },
+ "snapshots_to_keep": {
+ "production": "if using EBS, integer of the number of snapshots we're going to keep for this environment."
+ },
+ "deploy_to": "path to deploy, e.g. /srv/my_app",
+ "owner": "owner for the application files when deployed",
+ "group": "group for the application files when deployed",
+ "packages": {
+ "package_name": "specific packages required for installation at the OS level to run the app like libraries and specific version, e.g.",
+ "curl": "7.19.5-1ubuntu2"
+ }
+}
View
63 cookbooks/application/examples/data_bags/apps/php_app.json
@@ -0,0 +1,63 @@
+{
+ "id": "my_app",
+ "server_roles": [
+ "application specific role(s), typically the name of the app, e.g., my_app",
+ "my_app"
+ ],
+ "type": {
+ "my_app": [
+ "recipes in this application cookbook to run for this role",
+ "php",
+ "mod_php_apache2"
+ ]
+ },
+ "database_slave_role": [
+ "name of the role used by database slaves, typically named after the app, 'my_app_database_slave'",
+ "my_app_database_slave"
+ ],
+ "database_master_role": [
+ "name of the role used by database master, typically named after the app 'my_app_database_master'",
+ "my_app_database_master"
+ ],
+ "repository": "git@github.com:company/my_app.git",
+ "revision": {
+ "production": "commit hash, branch or tag to deploy"
+ },
+ "force": {
+ "production": "true or false w/o quotes to force deployment, see the rails.rb recipe"
+ },
+ "databases": {
+ "production": {
+ "reconnect": "true",
+ "encoding": "utf8",
+ "username": "db_user",
+ "adapter": "mysql",
+ "password": "awesome_password",
+ "database": "db_name_production"
+ }
+ },
+ "mysql_root_password": {
+ "production": "password for the root user in mysql"
+ },
+ "mysql_debian_password": {
+ "production": "password for the debian-sys-maint user on ubuntu/debian"
+ },
+ "mysql_repl_password": {
+ "production": "password for the 'repl' user for replication."
+ },
+ "snapshots_to_keep": {
+ "production": "if using EBS, integer of the number of snapshots we're going to keep for this environment."
+ },
+ "deploy_to": "path to deploy, e.g. /srv/my_app",
+ "owner": "owner for the application files when deployed",
+ "group": "group for the application files when deployed",
+ "packages": {
+ "package_name": "specific packages required for installation at the OS level to run the app like libraries and specific version, e.g.",
+ "curl": "7.19.5-1ubuntu2"
+ },
+ "pears": {
+ "pear_name": "specific gems required for installation to run the application, and if a specific version is required, e.g.",
+ "mongo": "1.1.4"
+ },
+ "local_settings_file": "some/realative/path/LocalSettings.php"
+}
View
75 cookbooks/application/examples/data_bags/apps/rails_app.json
@@ -0,0 +1,75 @@
+{
+ "id": "my_app",
+ "server_roles": [
+ "application specific role(s), typically the name of the app, e.g., my_app",
+ "my_app"
+ ],
+ "type": {
+ "my_app": [
+ "recipes in this application cookbook to run for this role",
+ "rails",
+ "unicorn"
+ ]
+ },
+ "memcached_role": [
+ "name of the role used for the app-specific memcached server",
+ "my_app_memcached"
+ ],
+ "database_slave_role": [
+ "name of the role used by database slaves, typically named after the app, 'my_app_database_slave'",
+ "my_app_database_slave"
+ ],
+ "database_master_role": [
+ "name of the role used by database master, typically named after the app 'my_app_database_master'",
+ "my_app_database_master"
+ ],
+ "repository": "git@github.com:company/my_app.git",
+ "revision": {
+ "production": "commit hash, branch or tag to deploy"
+ },
+ "force": {
+ "production": "true or false w/o quotes to force deployment, see the rails.rb recipe"
+ },
+ "migrate": {
+ "production": "true or false boolean to force migration, see rails.rb recipe"
+ },
+ "databases": {
+ "production": {
+ "reconnect": "true",
+ "encoding": "utf8",
+ "username": "db_user",
+ "adapter": "mysql",
+ "password": "awesome_password",
+ "database": "db_name_production"
+ }
+ },
+ "mysql_root_password": {
+ "production": "password for the root user in mysql"
+ },
+ "mysql_debian_password": {
+ "production": "password for the debian-sys-maint user on ubuntu/debian"
+ },
+ "mysql_repl_password": {
+ "production": "password for the 'repl' user for replication."
+ },
+ "snapshots_to_keep": {
+ "production": "if using EBS, integer of the number of snapshots we're going to keep for this environment."
+ },
+ "deploy_key": "SSH private key used to deploy from a private git repository",
+ "deploy_to": "path to deploy, e.g. /srv/my_app",
+ "owner": "owner for the application files when deployed",
+ "group": "group for the application files when deployed",
+ "packages": {
+ "package_name": "specific packages required for installation at the OS level to run the app like libraries and specific version, e.g.",
+ "curl": "7.19.5-1ubuntu2"
+ },
+ "gems": {
+ "gem_name": "specific gems required for installation to run the application, and if a specific version is required, e.g.",
+ "rails": "2.3.5"
+ },
+ "memcached": {
+ "production": {
+ "namespace": "specify the memcache namespace, ie my_app_environment"
+ }
+ }
+}
View
2  cookbooks/application/examples/environments
@@ -0,0 +1,2 @@
+name "production"
+description "Production environment"
View
101 cookbooks/application/examples/templates/default/LocalSettings.php.erb
@@ -0,0 +1,101 @@
+<?php
+# This file was automatically generated by Chef.
+#
+# See includes/DefaultSettings.php for all configurable settings
+# and their default values, but don't forget to make changes in _this_
+# file, not there.
+#
+# Further documentation for configuration settings may be found at:
+# http://www.mediawiki.org/wiki/Manual:Configuration_settings
+
+# Protect against web entry
+if ( !defined( 'MEDIAWIKI' ) ) {
+ exit;
+}
+
+## Uncomment this to disable output compression
+# $wgDisableOutputCompression = true;
+
+## Basics
+$IP = "<%= @path %>";
+
+## The URL base path to the directory containing the wiki;
+## defaults for all runtime URL paths are based off of this.
+## For more information on customizing the URLs please see:
+## http://www.mediawiki.org/wiki/Manual:Short_URL
+$wgScriptPath = "";
+$wgScriptExtension = ".php";
+
+## The relative URL path to the skins directory
+$wgStylePath = "$wgScriptPath/skins";
+
+$wgLogo ="http://chef-quick-starts.s3.amazonaws.com/mediawiki_opscode.png";
+
+## Database settings
+$wgDBtype = "<%= @database['adapter'] %>";
+$wgDBserver = "<%= @host %>";
+$wgDBname = "<%= @database['database'] %>";
+$wgDBuser = "<%= @database['username'] %>";
+$wgDBpassword = "<%= @database['password'] %>";
+
+## Shared memory settings
+$wgMainCacheType = CACHE_NONE;
+$wgMemCachedServers = array();
+
+## To enable image uploads, make sure the 'images' directory
+## is writable, then set this to true:
+$wgEnableUploads = false;
+$wgUseImageMagick = true;
+$wgImageMagickConvertCommand = "/usr/bin/convert";
+
+# InstantCommons allows wiki to use images from http://commons.wikimedia.org
+$wgUseInstantCommons = false;
+
+## If you use ImageMagick (or any other shell command) on a
+## Linux server, this will need to be set to the name of an
+## available UTF-8 locale
+$wgShellLocale = "en_US.utf8";
+
+## If you want to use image uploads under safe mode,
+## create the directories images/archive, images/thumb and
+## images/temp, and make them all writable. Then uncomment
+## this, if it's not already uncommented:
+#$wgHashedUploadDirectory = false;
+
+## If you have the appropriate support software installed
+## you can enable inline LaTeX equations:
+$wgUseTeX = false;
+
+## Set $wgCacheDirectory to a writable directory on the web server
+## to make your wiki go slightly faster. The directory should not
+## be publically accessible from the web.
+#$wgCacheDirectory = "$IP/cache";
+
+# Site language code, should be one of ./languages/Language(.*).php
+$wgLanguageCode = "en";
+
+$wgSecretKey = "5bcf0c2322863d3ad09a001528c4a14492859a623bf574cdc773cd75ed7ce055";
+
+# Site upgrade key. Must be set to a string (default provided) to turn on the
+# web installer while LocalSettings.php is in place
+$wgUpgradeKey = "db81965ebefdff41";
+
+## Default skin: you can change the default skin. Use the internal symbolic
+## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector':
+$wgDefaultSkin = "vector";
+
+## For attaching licensing metadata to pages, and displaying an
+## appropriate copyright notice / icon. GNU Free Documentation
+## License and Creative Commons licenses are supported so far.
+#$wgEnableCreativeCommonsRdf = true;
+$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
+$wgRightsUrl = "";
+$wgRightsText = "";
+$wgRightsIcon = "";
+# $wgRightsCode = ""; # Not yet used
+
+# Path to the GNU diff3 utility. Used for conflict resolution.
+$wgDiff3 = "/usr/bin/diff3";
+
+# Enabled Extensions. Most extensions are enabled by including the base extension file here
+# but check specific extension documentation for more details
View
76 cookbooks/application/examples/templates/default/wp-config.php.erb
@@ -0,0 +1,76 @@
+<?php
+/**
+ * The base configurations of the WordPress.
+ *
+ * This file has the following configurations: MySQL settings, Table Prefix,
+ * Secret Keys, WordPress Language, and ABSPATH. You can find more information by
+ * visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
+ * wp-config.php} Codex page. You can get the MySQL settings from your web host.
+ *
+ * This file is used by the wp-config.php creation script during the
+ * installation. You don't have to use the web site, you can just copy this file
+ * to "wp-config.php" and fill in the values.
+ *
+ * @package WordPress
+ */
+
+// ** MySQL settings - You can get this info from your web host ** //
+/** The name of the database for WordPress */
+define('DB_NAME', '<%= @database['database'] %>');
+
+/** MySQL database username */
+define('DB_USER', '<%= @database['username'] %>');
+
+/** MySQL database password */
+define('DB_PASSWORD', '<%= @database['password'] %>');
+
+/** MySQL hostname */
+define('DB_HOST', '<%= @host %>');
+
+/** Database Charset to use in creating database tables. */
+define('DB_CHARSET', 'utf8');
+
+/** The Database Collate type. Don't change this if in doubt. */
+define('DB_COLLATE', '');
+
+/**#@+
+ * Authentication Unique Keys.
+ *
+ * Change these to different unique phrases!
+ * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service}
+ * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
+ *
+ * @since 2.6.0
+ */
+define('AUTH_KEY', '<%= @app['wordpress']['auth_key'] %>');
+define('SECURE_AUTH_KEY', '<%= @app['wordpress']['secure_auth_key'] %>');
+define('LOGGED_IN_KEY', '<%= @app['wordpress']['logged_in_key'] %>');
+define('NONCE_KEY', '<%= @app['wordpress']['nonce_key'] %>');
+/**#@-*/
+
+/**
+ * WordPress Database Table prefix.
+ *
+ * You can have multiple installations in one database if you give each a unique
+ * prefix. Only numbers, letters, and underscores please!
+ */
+$table_prefix = 'wp_';
+
+/**
+ * WordPress Localized Language, defaults to English.
+ *
+ * Change this to localize WordPress. A corresponding MO file for the chosen
+ * language must be installed to wp-content/languages. For example, install
+ * de.mo to wp-content/languages and set WPLANG to 'de' to enable German
+ * language support.
+ */
+define ('WPLANG', '');
+
+/* That's all, stop editing! Happy blogging. */
+
+/** WordPress absolute path to the Wordpress directory. */
+if ( !defined('ABSPATH') )
+ define('ABSPATH', dirname(__FILE__) . '/');
+
+/** Sets up WordPress vars and included files. */
+require_once(ABSPATH . 'wp-settings.php');
View
183 cookbooks/application/libraries/default.rb
@@ -0,0 +1,183 @@
+#
+# Author:: Noah Kantrowitz <noah@opscode.com>
+# Cookbook Name:: application
+# Library:: default
+#
+# Copyright:: 2011-2012, Opscode, Inc <legal@opscode.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "chef/mixin/from_file"
+
+class Chef
+ class Resource
+ # Globally update the blocklists to prevent infinite recursion in #to_json and similar
+ FORBIDDEN_IVARS.concat [:@application, :@application_provider]
+ HIDDEN_IVARS.concat [:@application, :@application_provider]
+
+ class Application
+ module OptionsCollector
+ def options
+ @options ||= {}
+ end
+
+ def method_missing(method_sym, value=nil, &block)
+ super
+ rescue NameError
+ value ||= block
+ method_sym = method_sym.to_s.chomp('=').to_sym
+ options[method_sym] = value if value
+ options[method_sym] ||= nil
+ end
+ end
+ end
+
+ module ApplicationBase
+ def self.included(klass)
+ klass.actions :before_compile, :before_deploy, :before_migrate, :before_symlink, :before_restart, :after_restart
+ klass.attribute :id, :kind_of => String, :name_attribute => true
+ klass.attribute :environment, :kind_of => Hash, :default => {}
+ klass.attribute :purge_before_symlink, :kind_of => Array, :default => []
+ klass.attribute :create_dirs_before_symlink, :kind_of => Array, :default => []
+ klass.attribute :symlinks, :kind_of => Hash, :default => {}
+ klass.attribute :symlink_before_migrate, :kind_of => Hash, :default => {}
+ klass.attribute :migration_command, :kind_of => [String, NilClass], :default => nil
+ klass.attribute :application
+ klass.attribute :application_provider
+ klass.attribute :type
+ end
+
+ def restart_command(arg=nil, &block)
+ arg ||= block
+ raise "Invalid restart command" unless !arg || arg.is_a?(String) || arg.is_a?(Proc)
+ @restart_command = arg if arg
+ @restart_command
+ end
+
+ def method_missing(name, *args)
+ if application.respond_to? name
+ application.send(name, *args)
+ else
+ super
+ end
+ end
+
+ class OptionsBlock
+ include Chef::Resource::Application::OptionsCollector
+ end
+
+ def options_block(options=nil, &block)
+ options ||= {}
+ if block
+ collector = OptionsBlock.new
+ collector.instance_eval(&block)
+ options.update(collector.options)
+ end
+ options
+ end
+
+ def find_matching_role(role, single=true, &block)
+ return nil if !role
+ nodes = []
+ if node['roles'].include? role
+ nodes << node
+ end
+ if !single || nodes.empty?
+ search(:node, "role:#{role} AND chef_environment:#{node.chef_environment}") do |n|
+ nodes << n
+ end
+ end
+ if block
+ nodes.each do |n|
+ yield n
+ end
+ else
+ if single
+ nodes.first
+ else
+ nodes
+ end
+ end
+ end
+
+ def find_database_server(role)
+ dbm = find_matching_role(role)
+ Chef::Log.warn("No node with role #{role}") if role && !dbm
+
+ if respond_to?(:database) && database.has_key?('host')
+ database['host']
+ elsif dbm && dbm.attribute?('cloud')
+ dbm['cloud']['local_ipv4']
+ elsif dbm
+ dbm['ipaddress']
+ end
+ end
+ end
+ end
+
+ class Provider
+ module ApplicationBase
+
+ def self.included(klass)
+ klass.send(:include, Chef::Mixin::FromFile)
+ end
+
+ def deploy_provider
+ @deploy_provider ||= begin
+ deploy_provider = Chef::Platform.provider_for_resource(@deploy_resource)
+ deploy_provider.load_current_resource
+ deploy_provider
+ end
+ end
+
+ def release_path
+ deploy_provider.release_path
+ end
+
+ def shared_path
+ @deploy_resource.shared_path
+ end
+
+ def callback(what, callback_code=nil)
+ Chef::Log.debug("Got callback #{what}: #{callback_code.inspect}")
+ @collection = Chef::ResourceCollection.new
+ case callback_code
+ when Proc
+ Chef::Log.info "#{@new_resource} running callback #{what}"
+ recipe_eval(&callback_code)
+ when String
+ callback_file = "#{release_path}/#{callback_code}"
+ unless ::File.exist?(callback_file)
+ raise RuntimeError, "Can't find your callback file #{callback_file}"
+ end
+ run_callback_from_file(callback_file)
+ when nil
+ nil
+ else
+ raise RuntimeError, "You gave me a callback I don't know what to do with: #{callback_code.inspect}"
+ end
+ end
+
+ def run_callback_from_file(callback_file)
+ if ::File.exist?(callback_file)
+ Dir.chdir(release_path) do
+ Chef::Log.info "#{@new_resource} running deploy hook #{callback_file}"
+ recipe_eval { from_file(callback_file) }
+ end
+ end
+ end
+
+ end
+ end
+end
View
22 cookbooks/application/metadata.rb
@@ -0,0 +1,22 @@
+maintainer "Opscode, Inc."
+maintainer_email "cookbooks@opscode.com"
+license "Apache 2.0"
+description "Deploys and configures a variety of applications"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version "1.0.3"
+recipe "application", "Loads application databags and selects recipes to use"
+recipe "application::django", "Deploys a Django application specified in a data bag with the deploy_revision resource"
+recipe "application::gunicorn", "Sets up the deployed Django application with Gunicorn as the web server"
+recipe "application::java_webapp", "Deploys a Java web application WAR specified in a data bag with the remote_file resource"
+recipe "application::mod_php_apache2", "Sets up a deployed PHP application as a mod_php virtual host in Apache2"
+recipe "application::passenger_apache2", "Sets up a deployed Rails application as a Passenger virtual host in Apache2"
+recipe "application::php", "Deploys a PHP application specified in a data bag with the deploy_revision resource"
+recipe "application::rails", "Deploys a Rails application specified in a data bag with the deploy_revision resource"
+recipe "application::tomcat", "Sets up the deployed Java application with Tomcat as the servlet container"
+recipe "application::unicorn", "Sets up the deployed Rails application with Unicorn as the web server"
+
+%w{ runit unicorn apache2 passenger_apache2 tomcat python gunicorn php }.each do |cb|
+ depends cb
+end
+
+depends "python", ">= 1.0.6"
View
182 cookbooks/application/providers/default.rb
@@ -0,0 +1,182 @@
+#
+# Author:: Noah Kantrowitz <noah@opscode.com>
+# Cookbook Name:: application
+# Provider:: default
+#
+# Copyright:: 2011-2012, Opscode, Inc <legal@opscode.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include Chef::Provider::ApplicationBase
+
+action :deploy do
+
+ before_compile
+
+ before_deploy
+
+ run_deploy
+
+end
+
+action :force_deploy do
+
+ before_compile
+
+ before_deploy
+
+ run_deploy(true)
+
+end
+
+action :restart do
+
+ before_compile
+
+ run_actions_with_context(:before_restart, @run_context)
+
+ run_restart
+
+ run_actions_with_context(:after_restart, @run_context)
+
+ @new_resource.updated_by_last_action(true)
+
+end
+
+protected
+
+def before_compile
+ new_resource.application_provider self
+ new_resource.sub_resources.each do |resource|
+ resource.application_provider self
+ resource.run_action :before_compile
+ end
+end
+
+def before_deploy
+ new_resource.packages.each do |pkg,ver|
+ package pkg do
+ action :install
+ version ver if ver && ver.length > 0
+ end
+ end
+
+ directory new_resource.path do
+ owner new_resource.owner
+ group new_resource.group
+ mode '0755'
+ recursive true
+ end
+
+ directory "#{new_resource.path}/shared" do
+ owner new_resource.owner
+ group new_resource.group
+ mode '0755'
+ recursive true
+ end
+
+ if new_resource.deploy_key
+ file "#{new_resource.path}/id_deploy" do
+ content new_resource.deploy_key
+ owner new_resource.owner
+ group new_resource.group
+ mode '0600'
+ end
+
+ template "#{new_resource.path}/deploy-ssh-wrapper" do
+ source "deploy-ssh-wrapper.erb"
+ cookbook "application"
+ owner new_resource.owner
+ group new_resource.group
+ mode "0755"
+ variables :id => new_resource.name, :deploy_to => new_resource.path
+ end
+ end
+
+ ruby_block "#{new_resource.name} before_deploy" do
+ block do
+ new_resource.sub_resources.each do |resource|
+ resource.run_action :before_deploy
+ end
+ callback(:before_deploy, new_resource.before_deploy)
+ end
+ end
+end
+
+def run_deploy(force = false)
+ # Alias to a variable so I can use in sub-resources
+ new_resource = @new_resource
+ app_provider = self
+
+ @deploy_resource = send(new_resource.strategy.to_sym, new_resource.name) do
+ action force ? :force_deploy : :deploy
+ scm_provider new_resource.scm_provider
+ revision new_resource.revision
+ repository new_resource.repository
+ user new_resource.owner
+ group new_resource.group
+ deploy_to new_resource.path
+ ssh_wrapper "#{new_resource.path}/deploy-ssh-wrapper" if new_resource.deploy_key
+ shallow_clone true
+ rollback_on_error new_resource.rollback_on_error
+ all_environments = ([new_resource.environment]+new_resource.sub_resources.map{|res| res.environment}).inject({}){|acc, val| acc.merge(val)}
+ environment all_environments
+ migrate new_resource.migrate
+ all_migration_commands = ([new_resource.migration_command]+new_resource.sub_resources.map{|res| res.migration_command}).select{|cmd| cmd && !cmd.empty?}
+ migration_command all_migration_commands.join(' && ')
+ restart_command do
+ ([new_resource]+new_resource.sub_resources).each do |res|
+ cmd = res.restart_command
+ if cmd.is_a? Proc
+ provider = Chef::Platform.provider_for_resource(res)
+ provider.load_current_resource
+ provider.instance_eval(&cmd)
+ elsif cmd && !cmd.empty?
+ execute cmd do
+ user new_resource.owner
+ group new_resource.group
+ environment all_environments
+ end
+ end
+ end
+ end
+ purge_before_symlink new_resource.purge_before_symlink
+ create_dirs_before_symlink new_resource.create_dirs_before_symlink
+ symlinks new_resource.symlinks
+ all_symlinks_before_migrate = [new_resource.symlink_before_migrate]+new_resource.sub_resources.map{|res| res.symlink_before_migrate}
+ symlink_before_migrate all_symlinks_before_migrate.inject({}){|acc, val| acc.merge(val)}
+ before_migrate do
+ app_provider.send(:run_actions_with_context, :before_migrate, @run_context)
+ end
+ before_symlink do
+ app_provider.send(:run_actions_with_context, :before_symlink, @run_context)
+ end
+ before_restart do
+ app_provider.send(:run_actions_with_context, :before_restart, @run_context)
+ end
+ after_restart do
+ app_provider.send(:run_actions_with_context, :after_restart, @run_context)
+ end
+ end
+end
+
+def run_actions_with_context(action, context)
+ new_resource.sub_resources.each do |resource|
+ saved_run_context = resource.instance_variable_get :@run_context
+ resource.instance_variable_set :@run_context, context
+ resource.run_action action
+ resource.instance_variable_set :@run_context, saved_run_context
+ end
+ callback(action, new_resource.send(action))
+end
View
30 cookbooks/application/recipes/default.rb
@@ -0,0 +1,30 @@
+#
+# Cookbook Name:: application
+# Recipe:: default
+#
+# Copyright 2009, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+search(:apps) do |app|
+ (app["server_roles"] & node.run_list.roles).each do |app_role|
+ app["type"][app_role].each do |thing|
+ node.run_state[:current_app] = app
+ include_recipe "application::#{thing}"
+ end
+ end
+end
+
+node.run_state.delete(:current_app)
+
View
196 cookbooks/application/recipes/django.rb
@@ -0,0 +1,196 @@
+ #
+# Cookbook Name:: application
+# Recipe:: django
+#
+# Copyright 2011, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Chef::Log.warn "The application::django recipe is deprecated and will go away on Aug 1st. See the README for migration information."
+
+app = node.run_state[:current_app]
+
+include_recipe "python"
+
+###
+# You really most likely don't want to run this recipe from here - let the
+# default application recipe work it's mojo for you.
+###
+
+node.default[:apps][app['id']][node.chef_environment][:run_migrations] = false
+
+# the Django split-settings file name varies from project to project...+1 for standardization
+local_settings_full_path = app['local_settings_file'] || 'settings_local.py'
+local_settings_file_name = local_settings_full_path.split(/[\\\/]/).last
+
+## Create required directories
+
+directory app['deploy_to'] do
+ owner app['owner']
+ group app['group']
+ mode '0755'
+ recursive true
+end
+
+directory "#{app['deploy_to']}/shared" do
+ owner app['owner']
+ group app['group']
+ mode '0755'
+ recursive true
+end
+
+## Create a virtualenv for the app
+ve = python_virtualenv app['id'] do
+ path "#{app['deploy_to']}/shared/env"
+ action :create
+end
+
+## First, install any application specific packages
+if app['packages']
+ app['packages'].each do |pkg,ver|
+ package pkg do
+ action :install
+ version ver if ver && ver.length > 0
+ end
+ end
+end
+
+## Next, install any application specific gems
+if app['pips']
+ app['pips'].each do |pip,ver|
+ python_pip pip do
+ version ver if ver && ver.length > 0
+ virtualenv ve.path
+ action :install
+ end
+ end
+end
+
+if app.has_key?("deploy_key")
+ ruby_block "write_key" do
+ block do
+ f = ::File.open("#{app['deploy_to']}/id_deploy", "w")
+ f.print(app["deploy_key"])
+ f.close
+ end
+ not_if do ::File.exists?("#{app['deploy_to']}/id_deploy"); end
+ end
+
+ file "#{app['deploy_to']}/id_deploy" do
+ owner app['owner']
+ group app['group']
+ mode '0600'
+ end
+
+ template "#{app['deploy_to']}/deploy-ssh-wrapper" do
+ source "deploy-ssh-wrapper.erb"
+ owner app['owner']
+ group app['group']
+ mode "0755"
+ variables app.to_hash
+ end
+end
+
+if app["database_master_role"]
+ dbm = nil
+ # If we are the database master
+ if node.run_list.roles.include?(app["database_master_role"][0])
+ dbm = node
+ else
+ # Find the database master
+ results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
+ rows = results[0]
+ if rows.length == 1
+ dbm = rows[0]
+ end
+ end
+
+ # we need the django version to render the correct type of settings.py file
+ django_version = 1.2
+ if app['pips'].has_key?('django') && !app['pips']['django'].strip.empty?
+ django_version = app['pips']['django'].to_f
+ end
+
+ # Assuming we have one...
+ if dbm
+ # local_settings.py
+ template "#{app['deploy_to']}/shared/#{local_settings_file_name}" do
+ source "settings.py.erb"
+ owner app["owner"]
+ group app["group"]
+ mode "644"
+ variables(
+ :host => (dbm.attribute?('cloud') ? dbm['cloud']['local_ipv4'] : dbm['ipaddress']),
+ :database => app['databases'][node.chef_environment],
+ :django_version => django_version
+ )
+ end
+ else
+ Chef::Log.warn("No node with role #{app["database_master_role"][0]}, #{local_settings_file_name} not rendered!")
+ end
+end
+
+## Then, deploy
+deploy_revision app['id'] do
+ revision app['revision'][node.chef_environment]
+ repository app['repository']
+ user app['owner']
+ group app['group']
+ deploy_to app['deploy_to']
+ action app['force'][node.chef_environment] ? :force_deploy : :deploy
+ ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
+ shallow_clone true
+ purge_before_symlink([])
+ create_dirs_before_symlink([])
+ symlinks({})
+ before_migrate do
+ requirements_file = nil
+ # look for requirements.txt files in common locations
+ if ::File.exists?(::File.join(release_path, "requirements", "#{node.chef_environment}.txt"))
+ requirements_file = ::File.join(release_path, "requirements", "#{node.chef_environment}.txt")
+ elsif ::File.exists?(::File.join(release_path, "requirements.txt"))
+ requirements_file = ::File.join(release_path, "requirements.txt")
+ end
+
+ if requirements_file
+ Chef::Log.info("Installing pips using requirements file: #{requirements_file}")
+ pip_cmd = File.join(ve.path, "bin", "pip")
+ execute "#{pip_cmd} install -r #{requirements_file}" do
+ ignore_failure true
+ cwd release_path
+ end
+ end
+ end
+
+ symlink_before_migrate({
+ local_settings_file_name => local_settings_full_path
+ })
+
+ if app['migrate'][node.chef_environment] && node[:apps][app['id']][node.chef_environment][:run_migrations]
+ migrate true
+ migration_command app['migration_command'] || "#{::File.join(ve.path, "bin", "python")} manage.py migrate"
+ else
+ migrate false
+ end
+ before_symlink do
+ ruby_block "remove_run_migrations" do
+ block do
+ if node.role?("#{app['id']}_run_migrations")
+ Chef::Log.info("Migrations were run, removing role[#{app['id']}_run_migrations]")
+ node.run_list.remove("role[#{app['id']}_run_migrations]")
+ end
+ end
+ end
+ end
+end
View
57 cookbooks/application/recipes/gunicorn.rb
@@ -0,0 +1,57 @@
+#
+# Cookbook Name:: application
+# Recipe:: gunicorn
+#
+# Copyright 2011, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Chef::Log.warn "The application::gunicorn recipe is deprecated and will go away on Aug 1st. See the README for migration information."
+
+app = node.run_state[:current_app]
+
+ve = resources(:python_virtualenv => app['id'])
+node.default[:gunicorn][:virtualenv] = ve.path
+
+include_recipe "gunicorn"
+
+node.default[:gunicorn][:worker_timeout] = 60
+node.default[:gunicorn][:preload_app] = false
+node.default[:gunicorn][:worker_processes] = [node[:cpu][:total].to_i * 4, 8].min
+node.default[:gunicorn][:server_hooks] = {:pre_fork => 'import time;time.sleep(1)'}
+node.default[:gunicorn][:port] = '8080'
+
+gunicorn_config "/etc/gunicorn/#{app['id']}.py" do
+ listen "#{node[:ipaddress]}:#{node[:gunicorn][:port]}"
+ worker_timeout node[:gunicorn][:worker_timeout]
+ preload_app node[:gunicorn][:preload_app]
+ worker_processes node[:gunicorn][:worker_processes]
+ server_hooks node[:gunicorn][:server_hooks]
+ action :create
+end
+
+runit_service app['id'] do
+ template_name 'gunicorn'
+ cookbook 'application'
+ options('app' => app, 'virtualenv' => ve.path)
+ run_restart false
+end
+
+if ::File.exists?(::File.join(app['deploy_to'], "current"))
+ d = resources(:deploy_revision => app['id'])
+ d.restart_command do
+ execute "/etc/init.d/#{app['id']} hup"
+ end
+end
+
View
110 cookbooks/application/recipes/java_webapp.rb
@@ -0,0 +1,110 @@
+#
+# Cookbook Name:: application
+# Recipe:: java_webapp
+#
+# Copyright 2010-2011, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Chef::Log.warn "The application::java_webapp recipe is deprecated and will go away on Aug 1st. See the README for migration information."
+
+app = node.run_state[:current_app]
+
+###
+# You really most likely don't want to run this recipe from here - let the
+# default application recipe work it's mojo for you.
+###
+
+node.default[:apps][app['id']][node.chef_environment][:run_migrations] = false
+
+## First, install any application specific packages
+if app['packages']
+ app['packages'].each do |pkg,ver|
+ package pkg do
+ action :install
+ version ver if ver && ver.length > 0
+ end
+ end
+end
+
+directory app['deploy_to'] do
+ owner app['owner']
+ group app['group']
+ mode '0755'
+ recursive true
+end
+
+directory "#{app['deploy_to']}/releases" do
+ owner app['owner']
+ group app['group']
+ mode '0755'
+ recursive true
+end
+
+directory "#{app['deploy_to']}/shared" do
+ owner app['owner']
+ group app['group']
+ mode '0755'
+ recursive true
+end
+
+%w{ log pids system }.each do |dir|
+
+ directory "#{app['deploy_to']}/shared/#{dir}" do
+ owner app['owner']
+ group app['group']
+ mode '0755'
+ recursive true
+ end
+
+end
+
+if app["database_master_role"]
+ dbm = nil
+ # If we are the database master
+ if node.run_list.roles.include?(app["database_master_role"][0])
+ dbm = node
+ else
+ # Find the database master
+ results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
+ rows = results[0]
+ if rows.length == 1
+ dbm = rows[0]
+ end
+ end
+
+ # Assuming we have one...
+ if dbm
+ template "#{app['deploy_to']}/shared/#{app['id']}.xml" do
+ source "context.xml.erb"
+ owner app["owner"]
+ group app["group"]
+ mode "644"
+ variables(
+ :host => (dbm.attribute?('cloud') ? dbm['cloud']['local_ipv4'] : dbm['ipaddress']),
+ :app => app['id'],
+ :database => app['databases'][node.chef_environment],
+ :war => "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
+ )
+ end
+ end
+end
+
+## Then, deploy
+remote_file app['id'] do
+ path "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
+ source app['war'][node.chef_environment]['source']
+ mode "0644"
+ checksum app['war'][node.chef_environment]['checksum']
+end
View
55 cookbooks/application/recipes/mod_php_apache2.rb
@@ -0,0 +1,55 @@
+#
+# Cookbook Name:: application
+# Recipe:: mod_php_apache2
+#
+# Copyright 2011, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Chef::Log.warn "The application::mod_php_apache2 recipe is deprecated and will go away on Aug 1st. See the README for migration information."
+
+app = node.run_state[:current_app]
+
+node.default['apache']['listen_ports'] = [ "8080" ]
+
+include_recipe "apache2"
+include_recipe "apache2::mod_rewrite"
+include_recipe "apache2::mod_deflate"
+include_recipe "apache2::mod_headers"
+include_recipe "apache2::mod_php5"
+
+server_aliases = [ "#{app['id']}.#{node['domain']}", node['fqdn'] ]
+
+if node.has_key?("cloud")
+ server_aliases << node['cloud']['public_hostname']
+end
+
+web_app app['id'] do
+ docroot "#{app['deploy_to']}/current"
+ template 'php.conf.erb'
+ server_name "#{app['id']}.#{node['domain']}"
+ server_aliases server_aliases
+ log_dir node['apache']['log_dir']
+end
+
+if ::File.exists?(::File.join(app['deploy_to'], "current"))
+ d = resources(:deploy_revision => app['id'])
+ d.restart_command do
+ service "apache2" do action :restart; end
+ end
+end
+
+apache_site "000-default" do
+ enable false
+end
View
54 cookbooks/application/recipes/passenger_apache2.rb
@@ -0,0 +1,54 @@
+#
+# Cookbook Name:: application
+# Recipe:: passenger_apache2
+#
+# Copyright 2010, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Chef::Log.warn "The application::passenger_apache2 recipe is deprecated and will go away on Aug 1st. See the README for migration information."
+
+app = node.run_state[:current_app]
+
+include_recipe "apache2"
+include_recipe "apache2::mod_ssl"
+include_recipe "apache2::mod_rewrite"
+include_recipe "passenger_apache2::mod_rails"
+
+server_aliases = [ "#{app['id']}.#{node['domain']}", node['fqdn'] ]
+
+if node.has_key?("cloud")
+ server_aliases << node['cloud']['public_hostname']
+end
+
+web_app app['id'] do
+ docroot "#{app['deploy_to']}/current/public"
+ template "#{app['id']}.conf.erb"
+ cookbook "#{app['id']}"
+ server_name "#{app['id']}.#{node[:domain]}"
+ server_aliases server_aliases
+ log_dir node[:apache][:log_dir]
+ rails_env node.chef_environment
+end
+
+if ::File.exists?(::File.join(app['deploy_to'], "current"))
+ d = resources(:deploy_revision => app['id'])
+ d.restart_command do
+ service "apache2" do action :restart; end
+ end
+end
+
+apache_site "000-default" do
+ enable false
+end
View
146 cookbooks/application/recipes/php.rb
@@ -0,0 +1,146 @@
+#
+# Cookbook Name:: application
+# Recipe:: php
+#
+# Copyright 2011, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Chef::Log.warn "The application::php recipe is deprecated and will go away on Aug 1st. See the README for migration information."
+
+app = node.run_state[:current_app]
+
+include_recipe "php"
+
+###
+# You really most likely don't want to run this recipe from here - let the
+# default application recipe work it's mojo for you.
+###
+
+node.default['apps'][app['id']][node.chef_environment]['run_migrations'] = false
+
+# the PHP projects have no standard local settings file name..or path in the project
+local_settings_full_path = app['local_settings_file'] || 'LocalSettings.php'
+local_settings_file_name = local_settings_full_path.split(/[\\\/]/).last
+
+## First, install any application specific packages
+if app['packages']
+ app['packages'].each do |pkg,ver|
+ package pkg do
+ action :install
+ version ver if ver && ver.length > 0
+ end
+ end
+end
+
+## Next, install any application specific gems
+if app['pears']
+ app['pears'].each do |pear,ver|
+ php_pear pear do
+ action :install
+ version ver if ver && ver.length > 0
+ end
+ end
+end
+
+directory app['deploy_to'] do
+ owner app['owner']
+ group app['group']
+ mode '0755'
+ recursive true
+end
+
+directory "#{app['deploy_to']}/shared" do
+ owner app['owner']
+ group app['group']
+ mode '0755'
+ recursive true
+end
+
+if app.has_key?("deploy_key")
+ ruby_block "write_key" do
+ block do
+ f = ::File.open("#{app['deploy_to']}/id_deploy", "w")
+ f.print(app["deploy_key"])
+ f.close
+ end
+ not_if do ::File.exists?("#{app['deploy_to']}/id_deploy"); end
+ end
+
+ file "#{app['deploy_to']}/id_deploy" do
+ owner app['owner']
+ group app['group']
+ mode '0600'
+ end
+
+ template "#{app['deploy_to']}/deploy-ssh-wrapper" do
+ source "deploy-ssh-wrapper.erb"
+ owner app['owner']
+ group app['group']
+ mode "0755"
+ variables app.to_hash
+ end
+end
+
+if app["database_master_role"]
+ dbm = nil
+ # If we are the database master
+ if node.run_list.roles.include?(app["database_master_role"][0])
+ dbm = node
+ else
+ # Find the database master
+ results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
+ rows = results[0]
+ if rows.length == 1
+ dbm = rows[0]
+ end
+ end
+
+ # Assuming we have one...
+ if dbm
+ template "#{app['deploy_to']}/shared/#{local_settings_file_name}" do
+ source "#{local_settings_file_name}.erb"
+ cookbook app["id"]
+ owner app["owner"]
+ group app["group"]
+ mode "644"
+ variables(
+ :path => "#{app['deploy_to']}/current",
+ :host => (dbm.attribute?('cloud') ? dbm['cloud']['local_ipv4'] : dbm['ipaddress']),
+ :database => app['databases'][node.chef_environment],
+ :app => app
+ )
+ end
+ else
+ Chef::Log.warn("No node with role #{app['database_master_role'][0]}, #{local_settings_file_name} not rendered!")
+ end
+end
+
+## Then, deploy
+deploy_revision app['id'] do
+ revision app['revision'][node.chef_environment]
+ repository app['repository']
+ user app['owner']
+ group app['group']
+ deploy_to app['deploy_to']
+ action app['force'][node.chef_environment] ? :force_deploy : :deploy
+ ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
+ shallow_clone true
+ purge_before_symlink([])
+ create_dirs_before_symlink([])
+ symlinks({})
+ symlink_before_migrate({