]> git.openstreetmap.org Git - chef.git/blob - cookbooks/blogs/recipes/default.rb
Merge remote-tracking branch 'github/pull/422'
[chef.git] / cookbooks / blogs / recipes / default.rb
1 #
2 # Cookbook:: blogs
3 # Recipe:: default
4 #
5 # Copyright:: 2016, 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 "git"
23
24 ruby_version = if node[:lsb][:release].to_f < 20.04
25                  "2.5"
26                else
27                  "2.7"
28                end
29
30 package %W[
31   ruby#{ruby_version}
32   ruby#{ruby_version}-dev
33   make
34   gcc
35   g++
36   libsqlite3-dev
37 ]
38
39 gem_package "bundler#{ruby_version}" do
40   package_name "bundler"
41   version "~> 2.1.4"
42   gem_binary "gem#{ruby_version}"
43   options "--format-executable"
44 end
45
46 directory "/srv/blogs.openstreetmap.org" do
47   owner "blogs"
48   group "blogs"
49   mode "755"
50 end
51
52 git "/srv/blogs.openstreetmap.org" do
53   action :sync
54   repository "https://github.com/gravitystorm/blogs.osm.org.git"
55   depth 1
56   user "blogs"
57   group "blogs"
58   notifies :run, "execute[/srv/blogs.openstreetmap.org/Gemfile]", :immediately
59 end
60
61 execute "/srv/blogs.openstreetmap.org/Gemfile" do
62   action :nothing
63   command "bundle#{ruby_version} install --deployment"
64   cwd "/srv/blogs.openstreetmap.org"
65   user "blogs"
66   group "blogs"
67   notifies :run, "execute[/srv/blogs.openstreetmap.org]", :immediately
68 end
69
70 execute "/srv/blogs.openstreetmap.org" do
71   action :nothing
72   command "bundle#{ruby_version} exec pluto build -t osm -o build"
73   cwd "/srv/blogs.openstreetmap.org"
74   user "blogs"
75   group "blogs"
76 end
77
78 ssl_certificate "blogs.openstreetmap.org" do
79   domains ["blogs.openstreetmap.org", "blogs.osm.org"]
80   notifies :reload, "service[apache2]"
81 end
82
83 apache_site "blogs.openstreetmap.org" do
84   template "apache.erb"
85   directory "/srv/blogs.openstreetmap.org/build"
86   variables :aliases => ["blogs.osm.org"]
87 end
88
89 template "/usr/local/bin/blogs-update" do
90   source "blogs-update.erb"
91   owner "root"
92   group "root"
93   mode "0755"
94   variables :ruby_version => ruby_version
95 end
96
97 cron_d "blogs" do
98   minute "*/30"
99   user "blogs"
100   command "/usr/local/bin/blogs-update"
101   mailto "admins@openstreetmap.org"
102 end