]> git.openstreetmap.org Git - chef.git/blob - cookbooks/db/recipes/base.rb
Build database extensions for all installed postgres versions
[chef.git] / cookbooks / db / recipes / base.rb
1 #
2 # Cookbook:: db
3 # Recipe:: base
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 "git"
22 include_recipe "postgresql"
23 include_recipe "python"
24
25 passwords = data_bag_item("db", "passwords")
26 wal_secrets = data_bag_item("db", "wal-secrets")
27
28 ruby_version = node[:passenger][:ruby_version]
29
30 postgresql_munin "openstreetmap" do
31   cluster node[:db][:cluster]
32   database "openstreetmap"
33 end
34
35 directory "/srv/www.openstreetmap.org" do
36   group "rails"
37   mode "2775"
38 end
39
40 rails_port "www.openstreetmap.org" do
41   ruby ruby_version
42   directory "/srv/www.openstreetmap.org/rails"
43   user "rails"
44   group "rails"
45   repository "https://git.openstreetmap.org/public/rails.git"
46   revision "live"
47   build_assets false
48   database_host "localhost"
49   database_name "openstreetmap"
50   database_username "openstreetmap"
51   database_password passwords["openstreetmap"]
52   gpx_dir "/store/rails/gpx"
53 end
54
55 package %w[
56   cmake
57   libosmium2-dev
58   libprotozero-dev
59   libboost-filesystem-dev
60   libboost-program-options-dev
61   libbz2-dev
62   zlib1g-dev
63   libexpat1-dev
64   libyaml-cpp-dev
65   libpqxx-dev
66 ]
67
68 git "/opt/osmdbt" do
69   action :sync
70   repository "https://github.com/openstreetmap/osmdbt.git"
71   revision "v0.2"
72   depth 1
73   user "root"
74   group "root"
75 end
76
77 node[:postgresql][:versions].each do |db_version|
78   pg_config = "/usr/lib/postgresql/#{db_version}/bin/pg_config"
79   function_directory = "/srv/www.openstreetmap.org/rails/db/functions/#{db_version}"
80
81   directory function_directory do
82     owner "rails"
83     group "rails"
84     mode "755"
85   end
86
87   execute function_directory do
88     action :nothing
89     command "make BUNDLE=bundle#{ruby_version} PG_CONFIG=#{pg_config} DESTDIR=#{function_directory}"
90     cwd "/srv/www.openstreetmap.org/rails/db/functions"
91     user "rails"
92     group "rails"
93     subscribes :run, "directory[#{function_directory}]"
94     subscribes :run, "git[/srv/www.openstreetmap.org/rails]"
95   end
96
97   link "/usr/lib/postgresql/#{db_version}/lib/libpgosm.so" do
98     to "#{function_directory}/libpgosm.so"
99     owner "root"
100     group "root"
101   end
102
103   directory "/opt/osmdbt/build-#{db_version}" do
104     owner "root"
105     group "root"
106     mode "755"
107   end
108
109   execute "/opt/osmdbt/build-#{db_version}" do
110     action :nothing
111     command "cmake -DPG_CONFIG=/usr/lib/postgresql/#{db_version}/bin/pg_config .."
112     cwd "/opt/osmdbt/build-#{db_version}"
113     user "root"
114     group "root"
115     subscribes :run, "directory[/opt/osmdbt/build-#{db_version}]"
116     subscribes :run, "git[/opt/osmdbt]"
117   end
118
119   execute "/opt/osmdbt/build-#{db_version}/postgresql-plugin/Makefile" do
120     action :nothing
121     command "make"
122     cwd "/opt/osmdbt/build-#{db_version}/postgresql-plugin"
123     user "root"
124     group "root"
125     subscribes :run, "execute[/opt/osmdbt/build-#{db_version}]"
126   end
127
128   link "/usr/lib/postgresql/#{db_version}/lib/osm-logical.so" do
129     to "/opt/osmdbt/build-#{db_version}/postgresql-plugin/osm-logical.so"
130     owner "root"
131     group "root"
132   end
133 end
134
135 package "lzop"
136
137 python_package "wal-e" do
138   python_version "3"
139 end
140
141 python_package "boto" do
142   python_version "3"
143 end
144
145 template "/usr/local/bin/openstreetmap-wal-e" do
146   source "wal-e.erb"
147   owner "root"
148   group "postgres"
149   mode "750"
150   variables :s3_key => wal_secrets["s3_key"]
151 end
152
153 remote_file "/usr/local/bin/wal-g" do
154   action :create
155   source "https://github.com/wal-g/wal-g/releases/download/v1.1/wal-g-pg-ubuntu-20.04-amd64"
156   owner "root"
157   group "root"
158   mode "755"
159 end
160
161 template "/usr/local/bin/openstreetmap-wal-g" do
162   source "wal-g.erb"
163   owner "root"
164   group "postgres"
165   mode "750"
166   variables :s3_key => wal_secrets["s3_key"]
167 end