default.rb
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package 'memcached'
service 'memcached' do
action [:enable, :start]
end
if node['platform'] == 'centos'
cookbook_file '/etc/yum.repos.d/colab.repo' do
owner 'root'
mode 0644
end
end
package 'colab'
directory '/etc/colab' do
owner 'root'
group 'root'
mode 0755
end
directory '/var/log/colab' do
owner 'colab'
group 'colab'
mode 0755
end
directory '/var/lock/colab' do
owner 'colab'
group 'colab'
mode 0755
end
execute 'secret-key' do
f = '/etc/colab/secret.key'
command "openssl rand -hex 32 -out #{f} && chown root:colab #{f} && chmod 0640 #{f}"
not_if { File.exists?(f) }
notifies :create, 'template[/etc/colab/settings.yaml]'
end
template '/etc/colab/settings.yaml' do
owner 'root'
group 'colab'
mode 0640
notifies :restart, 'service[colab]'
end
template '/etc/colab/settings.d/00-database.yaml' do
owner 'root'
group 'colab'
mode 0640
notifies :restart, 'service[colab]'
end
template '/tmp/admin-gitlab.json' do
password = SecureRandom.random_number.to_s
variables(
:password => password
)
end
execute 'create-admin-token-colab' do
command "colab-admin loaddata admin-gitlab.json"
cwd '/tmp'
user 'root'
end
execute 'create-admin-token-gitlab' do
user = "admin-gitlab"
email = "admin-gitlab@example.com"
password = SecureRandom.random_number.to_s
command "RAILS_ENV=production bundle exec rails runner \"User.create(name: \'#{user}\', username: \'#{user}\', email: \'#{email}\', password: \'#{password}\', admin: \'true\')\""
user_exist = Dir.chdir '/usr/lib/gitlab' do
`RAILS_ENV=production bundle exec rails runner \"puts User.find_by_email(\'admin-gitlab@example.com\').nil?\"`.strip
end
not_if {user_exist == "false"}
cwd '/usr/lib/gitlab'
user 'git'
end
template '/etc/colab/settings.d/01-apps.yaml' do
owner 'root'
group 'colab'
mode 0640
notifies :restart, 'service[colab]'
get_private_token = lambda do
Dir.chdir '/usr/lib/gitlab' do
`sudo -u git RAILS_ENV=production bundle exec rails runner \"puts User.find_by_email(\'admin-gitlab@example.com\').private_token\"`.strip
end
end
variables(
:get_private_token => get_private_token
)
end
template '/etc/colab/settings.d/02-logging.yaml' do
owner 'root'
group 'colab'
mode 0640
notifies :restart, 'service[colab]'
end
directory '/var/lib/colab-assets/spb/' do
owner 'root'
group 'root'
mode 0755
end
cookbook_file '/var/lib/colab-assets/spb/logo.svg' do
owner 'root'
group 'root'
mode 0644
end
cookbook_file '/var/lib/colab-assets/spb/fav.ico' do
owner 'root'
group 'root'
mode 0644
end
# Add mailman group to colab user
execute 'colab-mailman-group' do
command "usermod -a -G mailman colab"
end
execute 'colab-admin migrate'
execute 'colab-admin:collectstatic' do
command 'colab-admin collectstatic --noinput'
end
service 'colab' do
action [:enable, :start]
supports :restart => true
end