]> git.openstreetmap.org Git - chef.git/blob - cookbooks/osqa/recipes/default.rb
Add more depth limits to git checkouts
[chef.git] / cookbooks / osqa / recipes / default.rb
1 #
2 # Cookbook:: osqa
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 "accounts"
21 include_recipe "apache"
22 include_recipe "memcached"
23 include_recipe "python"
24 include_recipe "tools"
25
26 package "python-dev"
27 package "libmysqlclient-dev"
28 package "libpq-dev"
29
30 python_directory = "/opt/osqa-python"
31
32 python_virtualenv python_directory
33
34 python_package "Django" do
35   python_virtualenv python_directory
36   version "1.6.11"
37 end
38
39 python_package "html5lib" do
40   python_virtualenv python_directory
41   version "0.999"
42 end
43
44 python_package "Markdown" do
45   python_virtualenv python_directory
46   version "2.4"
47 end
48
49 python_package "python-memcached" do
50   python_virtualenv python_directory
51   version "1.53"
52 end
53
54 python_package "python-openid" do
55   python_virtualenv python_directory
56   version "2.2.5"
57 end
58
59 python_package "MySQL-python" do
60   python_virtualenv python_directory
61   version "1.2.3"
62 end
63
64 python_package "psycopg2" do
65   python_virtualenv python_directory
66   version "2.7.6.1"
67 end
68
69 python_package "South" do
70   python_virtualenv python_directory
71   version "0.7.6"
72 end
73
74 apache_module "rewrite"
75 apache_module "wsgi"
76
77 node[:osqa][:sites].each do |site|
78   site_name = site[:name]
79   site_aliases = site[:aliases] || []
80   directory = site[:directory] || "/srv/#{site_name}"
81   site_user = site[:user] || node[:osqa][:user]
82   site_user = Etc.getpwuid(site_user).name if site_user.is_a?(Integer)
83   site_group = site[:group] || node[:osqa][:group] || Etc.getpwnam(site_user).gid
84   site_group = Etc.getgrgid(site_group).name if site_group.is_a?(Integer)
85   database_name = site[:database_name] || node[:osqa][:database_name]
86   database_user = site[:database_user] || node[:osqa][:database_user]
87   database_password = site[:database_user] || node[:osqa][:database_password]
88   backup_name = site[:backup]
89
90   ssl_certificate site_name do
91     domains [site_name] + site_aliases
92     notifies :reload, "service[apache2]"
93   end
94
95   apache_site site_name do
96     template "apache.erb"
97     directory directory
98     variables :user => site_user, :group => site_group, :aliases => site_aliases, :python_home => python_directory
99   end
100
101   directory directory do
102     owner site_user
103     group site_group
104     mode 0o755
105   end
106
107   execute "osqa-migrate" do
108     action :nothing
109     command "python manage.py migrate forum"
110     cwd "#{directory}/osqa"
111     user site_user
112     group site_group
113     notifies :reload, "service[apache2]"
114   end
115
116   git "#{directory}/osqa" do
117     action :sync
118     repository "https://git.openstreetmap.org/public/osqa.git"
119     revision "live"
120     depth 1
121     user site_user
122     group site_group
123     notifies :run, "execute[osqa-migrate]"
124   end
125
126   directory "#{directory}/upfiles" do
127     user site_user
128     group site_group
129     mode 0o755
130   end
131
132   template "#{directory}/osqa/osqa.wsgi" do
133     source "osqa.wsgi.erb"
134     owner site_user
135     group site_group
136     mode 0o644
137     variables :directory => directory
138     notifies :reload, "service[apache2]"
139   end
140
141   settings = edit_file "#{directory}/osqa/settings_local.py.dist" do |line|
142     line.gsub!(/^( *)'ENGINE': '.*',/, "\\1'ENGINE': 'django.db.backends.postgresql_psycopg2',")
143     line.gsub!(/^( *)'NAME': '.*',/, "\\1'NAME': '#{database_name}',")
144     line.gsub!(/^( *)'USER': '.*',/, "\\1'USER': '#{database_user}',")
145     line.gsub!(/^( *)'PASSWORD': '.*',/, "\\1'PASSWORD': '#{database_password}',")
146     line.gsub!(/^ALLOWED_HOSTS = .*/, "ALLOWED_HOSTS = ('help.openstreetmap.org',)")
147     line.gsub!(/^CACHE_BACKEND = .*/, "CACHE_BACKEND = 'memcached://127.0.0.1:11211/'")
148     line.gsub!(%r{^APP_URL = 'http://'}, "APP_URL = 'https://#{site_name}'")
149     line.gsub!(%r{^TIME_ZONE = 'America/New_York'}, "TIME_ZONE = 'Europe/London'")
150     line.gsub!(/^DISABLED_MODULES = \[([^\]]+)\]/, "DISABLED_MODULES = [\\1, 'localauth', 'facebookauth', 'oauthauth']")
151
152     line
153   end
154
155   file "#{directory}/osqa/settings_local.py" do
156     owner site_user
157     group site_group
158     mode 0o644
159     content settings
160     notifies :reload, "service[apache2]"
161   end
162
163   template "/etc/cron.daily/#{backup_name}-backup" do
164     source "backup.cron.erb"
165     owner "root"
166     group "root"
167     mode 0o755
168     variables :name => backup_name, :directory => directory, :user => site_user, :database => database_name
169   end
170 end