OSDN Git Service

6d1ff563d725f92e5dab4a4eec092da460134b66
[metasearch/grid-chef-repo.git] / cookbooks / gitlab-grid / recipes / server.rb
1 #
2 # Cookbook Name:: gitlab-grid
3 # Recipe:: server
4 #
5 # Copyright 2017, whitestar
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 #     http://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 # https://about.gitlab.com/downloads/
21
22 #::Chef::Recipe.send(:include, PlatformUtils::VirtUtils)
23
24 include_recipe 'gitlab-grid::commons'
25
26 #config = node['gitlab-grid']['gitlab.rb']
27 #override_config = node.override['gitlab-grid']['gitlab.rb']
28 #force_override_config = node.force_override['gitlab-grid']['gitlab.rb']
29
30 case node['platform_family']
31 when 'rhel'
32   [
33     'curl',
34     'policycoreutils',
35     'openssh-server',
36     'openssh-clients',
37     'postfix',
38   ].each {|pkg|
39     resources(package: pkg) rescue package pkg do
40       action :install
41     end
42   }
43
44   [
45     'sshd',
46     'postfix',
47   ].each {|srv|
48     resources(service: srv) rescue service srv do
49       action [:enable, :start]
50     end
51   }
52
53   bash 'update_firewall' do
54     code <<-EOH
55       firewall-cmd --permanent --add-service=http
56       systemctl reload firewalld
57     EOH
58     action :run
59   end
60
61   execute 'add_yum_repo_gitlab-ce' do
62     command 'curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash'
63     action :run
64     not_if { File.exist?('/etc/yum.repos.d/gitlab_gitlab-ce.repo') }
65   end
66 when 'debian'
67   [
68     'curl',
69     'openssh-server',
70     'ca-certificates',
71     'postfix',
72   ].each {|pkg|
73     resources(package: pkg) rescue package pkg do
74       action :install
75     end
76   }
77
78   apt_get_update = 'apt-get_update'
79   resources(execute: apt_get_update) rescue execute apt_get_update do
80     command 'apt-get update'
81     action :nothing
82   end
83
84   execute 'add_apt_source_gitlab-ce' do
85     command 'curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash'
86     action :run
87     not_if { File.exist?('/etc/apt/sources.list.d/gitlab_gitlab-ce.list') }
88     notifies :run, "execute[#{apt_get_update}]", :immediately
89   end
90 end
91
92 [
93   'gitlab-ce',
94 ].each {|pkg|
95   resources(package: pkg) rescue package pkg do
96     action :install
97   end
98 }
99
100 template '/etc/gitlab/gitlab.rb' do
101   source  'etc/gitlab/gitlab.rb'
102   owner 'root'
103   group 'root'
104   mode '0600'
105   action :create
106 end
107
108 log <<-"EOM"
109 Note: You must execute the following command manually if the gitlab.rb file has been updated.
110   $ sudo gitlab-ctl reconfigure
111 EOM