This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
/
helpers.rb
70 lines (60 loc) · 1.62 KB
/
helpers.rb
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
# frozen_string_literal: true
def applications
if Chef::Config[:solo]
Chef::Log.warn('This recipe uses search. Chef Solo does not support search.')
end
search(:aws_opsworks_app)
end
def rdses
if Chef::Config[:solo]
Chef::Log.warn('This recipe uses search. Chef Solo does not support search.')
end
search(:aws_opsworks_rds_db_instance)
end
def www_group
value_for_platform_family(
'debian' => 'www-data'
)
end
def create_deploy_dir(application, subdir = '/')
dir = File.join(deploy_dir(application), subdir)
directory dir do
mode '0755'
recursive true
owner node['deployer']['user'] || 'root'
group www_group
not_if { File.directory?(dir) }
end
dir
end
def deploy_dir(application)
File.join('/', 'srv', 'www', application['shortname'])
end
def every_enabled_application
node['deploy'].each do |deploy_app_shortname, deploy|
application = applications.detect { |app| app['shortname'] == deploy_app_shortname }
next unless application
yield application, deploy
end
end
def every_enabled_rds
rdses.each do |rds|
yield rds
end
end
def perform_bundle_install(release_path)
bundle_install File.join(release_path, 'Gemfile') do
deployment true
without %w(development test)
end
end
def prepare_recipe
node.default['deploy'] = Hash[applications.map { |app| [app['shortname'], {}] }].merge(node['deploy'] || {})
apps_not_included.each do |app_for_removal|
node.rm('deploy', app_for_removal)
end
end
def apps_not_included
return [] if node['applications'].blank?
node['deploy'].keys.select { |app_name| !node['applications'].include?(app_name) }
end