]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm-staging/recipes/default.rb
Add clone civicrm-staging cookbook
[chef.git] / cookbooks / civicrm-staging / recipes / default.rb
1 #
2 # Cookbook:: civicrm
3 # Recipe:: default
4 #
5 # Copyright:: 2011, OpenStreetMap Foundation
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 #     https://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
20 include_recipe "wordpress"
21 include_recipe "mysql"
22
23 package %w[
24   php-xml
25   php-curl
26   rsync
27   wkhtmltopdf
28   php-bcmath
29   php-intl
30 ]
31
32 cache_dir = Chef::Config[:file_cache_path]
33
34 passwords = data_bag_item("civicrm-staging", "passwords")
35 wp2fa_encrypt_keys = data_bag_item("civicrm-staging", "wp2fa_encrypt_keys")
36
37 database_password = passwords["database"]
38 site_key = passwords["site_key"]
39 cred_keys = passwords["cred_keys"]
40 sign_keys = passwords["sign_keys"]
41
42 mysql_user "civicrm-staging@localhost" do
43   password database_password
44 end
45
46 mysql_database "civicrm-staging" do
47   permissions "civicrm-staging@localhost" => :all
48 end
49
50 wordpress_site "join-staging.osmfoundation.org" do
51   aliases "crm-staging.osmfoundation.org"
52   database_name "civicrm-staging"
53   database_user "civicrm-staging"
54   database_password database_password
55   wp2fa_encrypt_key wp2fa_encrypt_keys["key"]
56   fpm_prometheus_port 11301
57 end
58
59 wordpress_theme "osmblog-wp-theme" do
60   site "join-staging.osmfoundation.org"
61   repository "https://github.com/osmfoundation/osmblog-wp-theme.git"
62 end
63
64 wordpress_plugin "registration-honeypot" do
65   site "join-staging.osmfoundation.org"
66 end
67
68 wordpress_plugin "contact-form-7" do
69   site "join-staging.osmfoundation.org"
70 end
71
72 wordpress_plugin "civicrm-admin-utilities" do
73   site "join-staging.osmfoundation.org"
74 end
75
76 civicrm_version = node[:civicrm_staging][:version]
77 civicrm_directory = "/srv/join-staging.osmfoundation.org/wp-content/plugins/civicrm"
78
79 directory "/opt/civicrm-staging-#{civicrm_version}" do
80   owner "wordpress"
81   group "wordpress"
82   mode "755"
83 end
84
85 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
86   action :create_if_missing
87   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
88   owner "wordpress"
89   group "wordpress"
90   mode "644"
91   backup false
92 end
93
94 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
95   action :create_if_missing
96   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
97   owner "wordpress"
98   group "wordpress"
99   mode "644"
100   backup false
101 end
102
103 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
104   action :nothing
105   destination "/opt/civicrm-staging-#{civicrm_version}"
106   overwrite true
107   owner "wordpress"
108   group "wordpress"
109   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
110 end
111
112 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
113   action :nothing
114   destination "/opt/civicrm-staging-#{civicrm_version}/civicrm"
115   overwrite true
116   owner "wordpress"
117   group "wordpress"
118   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
119 end
120
121 execute "/opt/civicrm-staging-#{civicrm_version}/civicrm" do
122   action :nothing
123   command "rsync --archive --delete /opt/civicrm-staging-#{civicrm_version}/civicrm/ #{civicrm_directory}"
124   user "wordpress"
125   group "wordpress"
126   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
127   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
128 end
129
130 directory "/srv/join-staging.osmfoundation.org/wp-content/uploads" do
131   owner "www-data"
132   group "www-data"
133   mode "755"
134 end
135
136 extensions_directory = "/srv/join-staging.osmfoundation.org/wp-content/plugins/civicrm-extensions"
137
138 directory extensions_directory do
139   owner "wordpress"
140   group "wordpress"
141   mode "755"
142 end
143
144 node[:civicrm_staging][:extensions].each_value do |details|
145   git "#{extensions_directory}/#{details[:name]}" do
146     action :sync
147     repository details[:repository]
148     revision details[:revision]
149     user "wordpress"
150     group "wordpress"
151   end
152 end
153
154 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
155   line.gsub!(/%%cms%%/, "WordPress")
156   line.gsub!(/%%CMSdbUser%%/, "civicrm-staging")
157   line.gsub!(/%%CMSdbPass%%/, database_password)
158   line.gsub!(/%%CMSdbHost%%/, "localhost")
159   line.gsub!(/%%CMSdbName%%/, "civicrm-staging")
160   line.gsub!(/%%dbUser%%/, "civicrm-staging")
161   line.gsub!(/%%dbPass%%/, database_password)
162   line.gsub!(/%%dbHost%%/, "localhost")
163   line.gsub!(/%%dbName%%/, "civicrm-staging")
164   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
165   line.gsub!(/%%templateCompileDir%%/, "/srv/join-staging.osmfoundation.org/wp-content/uploads/civicrm/templates_c/")
166   line.gsub!(/%%baseURL%%/, "http://join-staging.osmfoundation.org/")
167   line.gsub!(/%%siteKey%%/, site_key)
168   line.gsub!(/%%credKeys%%/, cred_keys)
169   line.gsub!(/%%signKeys%%/, sign_keys)
170   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join-staging.osmfoundation.org');")
171
172   line
173 end
174
175 file "#{civicrm_directory}/civicrm.settings.php" do
176   owner "wordpress"
177   group "wordpress"
178   mode "644"
179   content settings
180 end
181
182 # systemd_service "osmf-crm-staging-jobs" do
183 #   description "Run CRM staging jobs"
184 #   exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s join-staging.osmfoundation.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
185 #   user "www-data"
186 #   sandbox :enable_network => true
187 #   memory_deny_write_execute false
188 #   restrict_address_families "AF_UNIX"
189 #   read_write_paths "/srv/join-staging.osmfoundation.org/wp-content/uploads/civicrm"
190 # end
191
192 # systemd_timer "osmf-crm-staging-jobs" do
193 #   description "Run CRM staging jobs"
194 #   on_boot_sec "15m"
195 #   on_unit_inactive_sec "15m"
196 # end
197
198 # service "osmf-crm-jobs-staging.timer" do
199 #   action [:enable, :start]
200 # end
201
202 # template "/etc/cron.daily/osmf-crm-staging-backup" do
203 #   source "backup.cron.erb"
204 #   owner "root"
205 #   group "root"
206 #   mode "750"
207 #   variables :passwords => passwords
208 # end