php.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #
  2. # Cookbook Name:: application
  3. # Recipe:: php
  4. #
  5. # Copyright 2011, Opscode, Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. Chef::Log.warn "The application::php recipe is deprecated and will go away on Aug 1st. See the README for migration information."
  20. app = node.run_state[:current_app]
  21. include_recipe "php"
  22. ###
  23. # You really most likely don't want to run this recipe from here - let the
  24. # default application recipe work it's mojo for you.
  25. ###
  26. node.default['apps'][app['id']][node.chef_environment]['run_migrations'] = false
  27. # the PHP projects have no standard local settings file name..or path in the project
  28. local_settings_full_path = app['local_settings_file'] || 'LocalSettings.php'
  29. local_settings_file_name = local_settings_full_path.split(/[\\\/]/).last
  30. ## First, install any application specific packages
  31. if app['packages']
  32. app['packages'].each do |pkg,ver|
  33. package pkg do
  34. action :install
  35. version ver if ver && ver.length > 0
  36. end
  37. end
  38. end
  39. ## Next, install any application specific gems
  40. if app['pears']
  41. app['pears'].each do |pear,ver|
  42. php_pear pear do
  43. action :install
  44. version ver if ver && ver.length > 0
  45. end
  46. end
  47. end
  48. directory app['deploy_to'] do
  49. owner app['owner']
  50. group app['group']
  51. mode '0755'
  52. recursive true
  53. end
  54. directory "#{app['deploy_to']}/shared" do
  55. owner app['owner']
  56. group app['group']
  57. mode '0755'
  58. recursive true
  59. end
  60. if app.has_key?("deploy_key")
  61. ruby_block "write_key" do
  62. block do
  63. f = ::File.open("#{app['deploy_to']}/id_deploy", "w")
  64. f.print(app["deploy_key"])
  65. f.close
  66. end
  67. not_if do ::File.exists?("#{app['deploy_to']}/id_deploy"); end
  68. end
  69. file "#{app['deploy_to']}/id_deploy" do
  70. owner app['owner']
  71. group app['group']
  72. mode '0600'
  73. end
  74. template "#{app['deploy_to']}/deploy-ssh-wrapper" do
  75. source "deploy-ssh-wrapper.erb"
  76. owner app['owner']
  77. group app['group']
  78. mode "0755"
  79. variables app.to_hash
  80. end
  81. end
  82. if app["database_master_role"]
  83. dbm = nil
  84. # If we are the database master
  85. if node.run_list.roles.include?(app["database_master_role"][0])
  86. dbm = node
  87. else
  88. # Find the database master
  89. results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
  90. rows = results[0]
  91. if rows.length == 1
  92. dbm = rows[0]
  93. end
  94. end
  95. # Assuming we have one...
  96. if dbm
  97. template "#{app['deploy_to']}/shared/#{local_settings_file_name}" do
  98. source "#{local_settings_file_name}.erb"
  99. cookbook app["id"]
  100. owner app["owner"]
  101. group app["group"]
  102. mode "644"
  103. variables(
  104. :path => "#{app['deploy_to']}/current",
  105. :host => (dbm.attribute?('cloud') ? dbm['cloud']['local_ipv4'] : dbm['ipaddress']),
  106. :database => app['databases'][node.chef_environment],
  107. :app => app
  108. )
  109. end
  110. else
  111. Chef::Log.warn("No node with role #{app['database_master_role'][0]}, #{local_settings_file_name} not rendered!")
  112. end
  113. end
  114. ## Then, deploy
  115. deploy_revision app['id'] do
  116. revision app['revision'][node.chef_environment]
  117. repository app['repository']
  118. user app['owner']
  119. group app['group']
  120. deploy_to app['deploy_to']
  121. action app['force'][node.chef_environment] ? :force_deploy : :deploy
  122. ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
  123. shallow_clone true
  124. purge_before_symlink([])
  125. create_dirs_before_symlink([])
  126. symlinks({})
  127. symlink_before_migrate({
  128. local_settings_file_name => local_settings_full_path
  129. })
  130. end