capistrano-ops 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/capistrano/ops/capistrano/v3/tasks/figaro_yml.rake +78 -18
- data/lib/capistrano/ops/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09b60a4ca6637d545cc7d8b194dbec1d3a1ac405a7989bd0cdbf2e643ceb628f'
|
4
|
+
data.tar.gz: 5a618ae2186f1e9f8f94f16b0e10bc17ddf73298bb004ea17c91d1a2b10cb982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cec5cf8430d5a2d5381d68a2d5281811f5a6cfda41b020052cba59f6db269619a59c616a160fd05f9fc0f260ebfbfda30e14ee769be1b341d3cff43b75a61e87
|
7
|
+
data.tar.gz: 01acbfc3304b7d8e6ec492d85119bf6584f01cdd33883c0242c1741e180662ff6a570b127366f1e595f58b6839e79ac44417ee35a44a204e2a7ea957561c38b1
|
@@ -5,13 +5,65 @@ namespace :figaro_yml do
|
|
5
5
|
# Defaults to :app role
|
6
6
|
rake_roles = fetch(:rake_roles, :app)
|
7
7
|
|
8
|
-
desc 'get the
|
8
|
+
desc 'get the `application.yml` file from server and create local if it does not exist'
|
9
9
|
task :get do
|
10
|
-
|
10
|
+
env = fetch(:stage)
|
11
|
+
if !File.exist?('config/application.yml')
|
12
|
+
puts "config/application.yml does not exist, creating it from all stages"
|
13
|
+
run_locally do
|
14
|
+
yamls={}
|
15
|
+
stages = Dir.glob('config/deploy/*.rb')
|
16
|
+
puts "found #{stages.count} stages"
|
17
|
+
stages.map do |f|
|
18
|
+
stage =File.basename(f, '.rb')
|
19
|
+
puts "download #{stage} application.yml"
|
20
|
+
begin
|
21
|
+
res = capture "cap #{stage} figaro_yml:get_stage"
|
22
|
+
yamls= yamls.merge(YAML.safe_load(res))
|
23
|
+
rescue
|
24
|
+
puts "could not get #{stage} application.yml"
|
25
|
+
end
|
26
|
+
yamls
|
27
|
+
end
|
28
|
+
# write to new file
|
29
|
+
puts "writing to config/application.yml"
|
30
|
+
write_to_file('config/application.yml', yamls.to_yaml)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
local_yml = YAML.safe_load(File.read('config/application.yml'))
|
34
|
+
on roles(rake_roles) do
|
35
|
+
remote = capture("cat #{shared_path}/config/application.yml")
|
36
|
+
remote_yml = YAML.safe_load(remote)
|
37
|
+
remote_stage = remote_yml[env.to_s]
|
38
|
+
puts "remote application.yml stage '#{env.to_s}':\n\n"
|
39
|
+
puts remote + "\r\n"
|
40
|
+
puts "\r\n"
|
41
|
+
loop do
|
42
|
+
print "Overwrite local application.yml stage '#{env.to_s}'? (y/N): "
|
43
|
+
input = $stdin.gets.strip.downcase
|
44
|
+
answer = (input.empty? ? 'N' : input).downcase.to_s
|
45
|
+
|
46
|
+
next unless %w(y n).include?(answer)
|
47
|
+
|
48
|
+
if answer == 'y'
|
49
|
+
puts 'Updating local application.yml'
|
50
|
+
local_yml[env.to_s] = remote_stage
|
51
|
+
write_to_file('config/application.yml', local_yml.to_yaml)
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
break
|
55
|
+
end
|
56
|
+
puts 'Nothing written to local application.yml'
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
11
61
|
|
12
|
-
|
62
|
+
task :get_stage do
|
63
|
+
on roles(rake_roles) do
|
64
|
+
puts capture "cat #{shared_path}/config/application.yml"
|
65
|
+
end
|
13
66
|
end
|
14
|
-
end
|
15
67
|
|
16
68
|
desc 'compare and set the figaro_yml file on the server'
|
17
69
|
task :compare do
|
@@ -61,20 +113,28 @@ namespace :figaro_yml do
|
|
61
113
|
end
|
62
114
|
end
|
63
115
|
def compare_hashes(hash1, hash2)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
116
|
+
changes = false
|
117
|
+
local_server = hash1.to_a - hash2.to_a
|
118
|
+
server_local = hash2.to_a - hash1.to_a
|
119
|
+
|
120
|
+
[local_server + server_local].flatten(1).to_h.keys.each do |k|
|
121
|
+
new_value = hash1[k].to_s
|
122
|
+
new_value = new_value.empty? ? "nil" : new_value
|
123
|
+
old_value = hash2[k].to_s
|
124
|
+
old_value = old_value.empty? ? "nil" : old_value
|
125
|
+
|
126
|
+
if old_value != new_value
|
127
|
+
puts "#{k}: #{old_value} => #{new_value} \r\n"
|
128
|
+
changes = true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def write_to_file(file, content)
|
134
|
+
File.open(file, 'w') do |f|
|
135
|
+
f.write(content)
|
78
136
|
end
|
137
|
+
end
|
138
|
+
|
79
139
|
end
|
80
140
|
# rubocop:enable Metrics/BlockLength
|