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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e34dc742a965031bb1b567fecc4e729a62878e8e2e96fd1749d4d7317755e827
4
- data.tar.gz: 073b3e371926d7190d13b1739be38650097961fae84f915fbc651f3f9bd02ff9
3
+ metadata.gz: '09b60a4ca6637d545cc7d8b194dbec1d3a1ac405a7989bd0cdbf2e643ceb628f'
4
+ data.tar.gz: 5a618ae2186f1e9f8f94f16b0e10bc17ddf73298bb004ea17c91d1a2b10cb982
5
5
  SHA512:
6
- metadata.gz: '096dbd8ed8e503b5ece31715584506a1acb5d317938dc13a0b9b9a54adec04ea5cc3a94b54f9981d514b141fb887c40afff39bae034c902282d3e6e740880b8f'
7
- data.tar.gz: b9d88ddc367f2dfd5b18be1adb65ca929a07e2229b51bceacb03313d36b36a20eef683577dbc6e5d588a027093347eb21b826199529e3523b890b824f836ac3c
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 figaro_yml file from the server'
8
+ desc 'get the `application.yml` file from server and create local if it does not exist'
9
9
  task :get do
10
- on roles(rake_roles) do
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
- puts capture "cat #{shared_path}/config/application.yml"
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
- changes = false
65
- local_server = hash1.to_a - hash2.to_a
66
- server_local = hash2.to_a - hash1.to_a
67
-
68
- [local_server + server_local].flatten(1).to_h.keys.each do |k|
69
- new_value = hash1[k].to_s
70
- new_value = new_value.empty? ? "nil" : new_value
71
- old_value = hash2[k].to_s
72
- old_value = old_value.empty? ? "nil" : old_value
73
- if old_value != new_value
74
- puts "#{k}: #{old_value} => #{new_value} \r\n"
75
- changes = true
76
- end
77
- end
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Capistrano
3
3
  module Ops
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-ops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Crusius