capistrano-ops 0.1.1 → 0.1.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6af441f4d4b138e9fa1cbd23f7a1cf5d51790864244533628a892af64217c0b
|
4
|
+
data.tar.gz: d2f5b562b99aa1c5f9d2901341d639032b44f7ff4f62c18ca0c662cdc506b76f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b33aceafbc6d21bcc45c09396b73c5d3781c6bf0bc622003586a80b91e042bf05d449488e91e3f92e9d6d8eddf6a68a89122ec6fd4ade5b1c291fe6226efa6d7
|
7
|
+
data.tar.gz: 3d2616714f9837708658eb31f3c753c28de224a1ca268ad74694216ee6f3c35c80333bf58683a1f4c6986ba0c4168e69f7110728dc25bc03241acdf849d6ecf2
|
@@ -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
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'capistrano/ops'
|
4
3
|
require 'rails'
|
4
|
+
# require 'capistrano/ops'
|
5
5
|
module Capistrano
|
6
6
|
module Ops
|
7
|
-
class Railtie < Rails::Railtie
|
7
|
+
class Railtie < ::Rails::Railtie
|
8
8
|
railtie_name :ops
|
9
9
|
rake_tasks do
|
10
10
|
path = File.expand_path(__dir__)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-ops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Crusius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|