]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/recipes/repository.rb
Merge remote-tracking branch 'github/pull/165'
[chef.git] / cookbooks / chef / recipes / repository.rb
1 #
2 # Cookbook Name:: chef
3 # Recipe:: repository
4 #
5 # Copyright 2013, 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 "git"
21
22 keys = data_bag_item("chef", "keys")
23
24 directory "/var/lib/chef" do
25   owner "chefrepo"
26   group "chefrepo"
27   mode 0o2775
28 end
29
30 %w[public private].each do |repository|
31   repository_directory = node[:chef][:"#{repository}_repository"]
32
33   git "/var/lib/chef/#{repository}" do
34     action :checkout
35     repository repository_directory
36     revision "master"
37     user "chefrepo"
38     group "chefrepo"
39   end
40
41   directory "/var/lib/chef/#{repository}/.chef" do
42     owner "chefrepo"
43     group "chefrepo"
44     mode 0o2775
45   end
46
47   file "/var/lib/chef/#{repository}/.chef/client.pem" do
48     content keys["git"].join("\n")
49     owner "chefrepo"
50     group "chefrepo"
51     mode 0o660
52   end
53
54   cookbook_file "/var/lib/chef/#{repository}/.chef/knife.rb" do
55     source "knife.rb"
56     owner "chefrepo"
57     group "chefrepo"
58     mode 0o660
59   end
60
61   template "#{repository_directory}/hooks/post-receive" do
62     source "post-receive.erb"
63     owner "chefrepo"
64     group "chefrepo"
65     mode 0o750
66     variables :repository => repository
67   end
68 end