5 # Copyright:: 2011, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
20 include_recipe "wordpress"
21 include_recipe "mysql"
32 cache_dir = Chef::Config[:file_cache_path]
34 passwords = data_bag_item("civicrm-staging", "passwords")
35 wp2fa_encrypt_keys = data_bag_item("civicrm-staging", "wp2fa_encrypt_keys")
37 database_password = passwords["database"]
38 site_key = passwords["site_key"]
39 cred_keys = passwords["cred_keys"]
40 sign_keys = passwords["sign_keys"]
42 mysql_user "civicrm-staging@localhost" do
43 password database_password
46 mysql_database "civicrm-staging" do
47 permissions "civicrm-staging@localhost" => :all
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
59 wordpress_theme "osmblog-wp-theme" do
60 site "join-staging.osmfoundation.org"
61 repository "https://github.com/osmfoundation/osmblog-wp-theme.git"
64 wordpress_plugin "registration-honeypot" do
65 site "join-staging.osmfoundation.org"
68 wordpress_plugin "contact-form-7" do
69 site "join-staging.osmfoundation.org"
72 wordpress_plugin "civicrm-admin-utilities" do
73 site "join-staging.osmfoundation.org"
76 civicrm_version = node[:civicrm_staging][:version]
77 civicrm_directory = "/srv/join-staging.osmfoundation.org/wp-content/plugins/civicrm"
79 directory "/opt/civicrm-staging-#{civicrm_version}" do
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"
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"
103 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
105 destination "/opt/civicrm-staging-#{civicrm_version}"
109 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
112 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
114 destination "/opt/civicrm-staging-#{civicrm_version}/civicrm"
118 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
121 execute "/opt/civicrm-staging-#{civicrm_version}/civicrm" do
123 command "rsync --archive --delete /opt/civicrm-staging-#{civicrm_version}/civicrm/ #{civicrm_directory}"
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
130 directory "/srv/join-staging.osmfoundation.org/wp-content/uploads" do
136 extensions_directory = "/srv/join-staging.osmfoundation.org/wp-content/plugins/civicrm-extensions"
138 directory extensions_directory do
144 node[:civicrm_staging][:extensions].each_value do |details|
145 git "#{extensions_directory}/#{details[:name]}" do
147 repository details[:repository]
148 revision details[:revision]
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');")
175 file "#{civicrm_directory}/civicrm.settings.php" do
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"
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"
192 # systemd_timer "osmf-crm-staging-jobs" do
193 # description "Run CRM staging jobs"
195 # on_unit_inactive_sec "15m"
198 # service "osmf-crm-jobs-staging.timer" do
199 # action [:enable, :start]
202 # template "/etc/cron.daily/osmf-crm-staging-backup" do
203 # source "backup.cron.erb"
207 # variables :passwords => passwords