README.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. Application cookbook
  2. ====================
  3. This cookbook is initially designed to be able to describe and deploy web applications. Currently supported:
  4. * Rails
  5. Other application stacks (PHP, DJango, JBoss, etc) will be supported as new recipes at a later date.
  6. ---
  7. Recipes
  8. =======
  9. The application cookbook contains the following recipes.
  10. default
  11. -------
  12. Searches the `apps` data bag and checks that a server role in the app exists on this node, adds the app to the run state and uses the role for the app to locate the recipes that need to be used. See below regarding the application data bag structure.
  13. rails
  14. -----
  15. Using the node's `run_state` that contains the current application in the search, this recipe will install required packages and gems, set up the deployment scaffolding, creates database and memcached configurations if required and then performs a revision-based deploy.
  16. This recipe can be used on nodes that are going to run the application, or on nodes that need to have the application code checkout available such as supporting utility nodes or a configured load balancer that needs static assets stored in the application repository.
  17. unicorn
  18. -------
  19. Requires `unicorn` cookbook.
  20. Unicorn is installed, default attributes are set for the node and an app specific unicorn config and runit service are created.
  21. ---
  22. Deprecated Recipes
  23. ==================
  24. The following recipes are deprecated in favor of rails+unicorn, as that is performant enough for many Rails applications, and takes less time to provision new instances. Using these recipes may require additional work to the rest of the stack that wouldn't be required with rails+unicorn because they were early-phase development of this cookbook.
  25. passenger-nginx
  26. ---------------
  27. Builds passenger as an nginx module, drops off the configuration file and sets up the site to run the application under nginx with passenger. Does not deploy the code automatically.
  28. rails_nginx_ree_passenger
  29. -------------------------
  30. Sets up the application stack with Ruby Enterprise Edition, Nginx and Passenger.
  31. The recipe searches the apps data bag and then installs packages and gems, creates the nginx vhost config and enables the site, sets up the deployment scaffolding, and uses a revision-based deploy for the code. Database and memcached yaml files are written out as well, if required.
  32. ---
  33. Application Data Bag
  34. ====================
  35. The applications data bag expects certain values in order to configure parts of the recipe. Below is a paste of the JSON, where the value is a description of the key. Use your own values, as required. Note that this data bag is also used by the `database` cookbook, so it will contain database information as well. Items that may be ambiguous have an example.
  36. The application used in examples is named `my_app` and the environment is `production`. Most top-level keys are Arrays, and each top-level key has an entry that describes what it is for, followed by the example entries. Entries that are hashes themselves will have the description in the value.
  37. Note about `databases`, the data specified will be rendered as the `database.yml` file.
  38. Note about gems and packages, the version is optional. If specified, the version will be passed as a parameter to the resource. Otherwise it will use the latest available version per the default `:install` action for the package provider.
  39. {
  40. "id": "my_app",
  41. "server_roles": [
  42. "application specific role(s), typically the name of the app, e.g., my_app",
  43. "my_app"
  44. ],
  45. "type": {
  46. "my_app": [
  47. "recipes in this application cookbook to run for this role",
  48. "rails",
  49. "unicorn"
  50. ]
  51. },
  52. "memcached_role": [
  53. "name of the role used for the app-specific memcached server",
  54. "my_app_memcached"
  55. ],
  56. "database_slave_role": [
  57. "name of the role used by database slaves, typically named after the app, 'my_app_database_slave'",
  58. "my_app_database_slave"
  59. ],
  60. "database_master_role": [
  61. "name of the role used by database master, typically named after the app 'my_app_database_master'",
  62. "my_app_database_master"
  63. ],
  64. "repository": "git@github.com:company/my_app.git",
  65. "revision": {
  66. "production": "commit hash, branch or tag to deploy"
  67. },
  68. "force": {
  69. "production": "true or false w/o quotes to force deployment, see the rails.rb recipe"
  70. },
  71. "migrate": {
  72. "production": "true or false boolean to force migration, see rails.rb recipe"
  73. },
  74. "databases": {
  75. "db_name_production": {
  76. "reconnect": "true",
  77. "encoding": "utf8",
  78. "username": "db_user",
  79. "adapter": "mysql",
  80. "password": "awesome_password",
  81. "database": "db_name_production"
  82. }
  83. },
  84. "mysql_root_password": {
  85. "production": "password for the root user in mysql"
  86. },
  87. "mysql_debian_password": {
  88. "production": "password for the debian-sys-maint user on ubuntu/debian"
  89. },
  90. "mysql_repl_password": {
  91. "production": "password for the 'repl' user for replication."
  92. },
  93. "snapshots_to_keep": {
  94. "production": "if using EBS, integer of the number of snapshots we're going to keep for this environment."
  95. },
  96. "deploy_key": "SSH private key used to deploy from a private git repository",
  97. "deploy_to": "path to deploy, e.g. /srv/my_app",
  98. "owner": "owner for the application files when deployed",
  99. "group": "group for the application files when deployed",
  100. "packages": {
  101. "package_name": "specific packages required for installation at the OS level to run the app like libraries and specific version, e.g.",
  102. "curl": "7.19.5-1ubuntu2"
  103. },
  104. "gems": {
  105. "gem_name": "specific gems required for installation to run the application, and if a specific version is required, e.g.",
  106. "rails": "2.3.5"
  107. },
  108. "memcached": {
  109. "production": {
  110. "namespace": "specify the memcache namespace, ie my_app_environment"
  111. }
  112. }
  113. }
  114. ---
  115. Usage
  116. =====
  117. To use the application cookbook, we recommend creating a role named after the application, e.g. `my_app`. In your chef-repo, create `roles/my_app.rb`. Also recommended is a site-cookbook named after the application, e.g. `my_app`, for additional application specific setup.
  118. name "my_app"
  119. description "My application front end server."
  120. run_list(
  121. "recipe[application]"
  122. )
  123. If you need other recipes, such as `mysql::client` add those as well. Then upload the role to the Chef Server.
  124. % knife role from file roles/my_app.rb
  125. Add the role to a node. Create the data bag per the guidelines above, and run Chef to watch it deploy the application!
  126. ---
  127. License and Author
  128. ==================
  129. Author:: Adam Jacob (<adam@opscode.com>)
  130. Author:: Joshua Timberman (<joshua@opscode.com>)
  131. Copyright 2009-2010, Opscode, Inc.
  132. Licensed under the Apache License, Version 2.0 (the "License");
  133. you may not use this file except in compliance with the License.
  134. You may obtain a copy of the License at
  135. http://www.apache.org/licenses/LICENSE-2.0
  136. Unless required by applicable law or agreed to in writing, software
  137. distributed under the License is distributed on an "AS IS" BASIS,
  138. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  139. See the License for the specific language governing permissions and
  140. limitations under the License.