capistrano-config 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +0 -1
- data/lib/capistrano-config.rb +100 -58
- data/lib/capistrano-config/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -40,7 +40,6 @@ Following options are available to manage your configuration files.
|
|
40
40
|
* `:config_readable_files` - list of files which should be readable. empty by default.
|
41
41
|
* `:config_writable_files` - list of files which should be writable. empty by default.
|
42
42
|
* `:config_executable_files` - list of files which should be executable. empty by default.
|
43
|
-
* `:config_remove_files` - list of files which should be removed. empty by default.
|
44
43
|
|
45
44
|
## Contributing
|
46
45
|
|
data/lib/capistrano-config.rb
CHANGED
@@ -11,16 +11,10 @@ module Capistrano
|
|
11
11
|
_cset(:config_path_local) { File.expand_path('.') }
|
12
12
|
_cset(:config_template_path) { File.join(File.expand_path('.'), 'config', 'templates') }
|
13
13
|
_cset(:config_files, [])
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
config_files.map { |file|
|
19
|
-
f = Tempfile.new('config'); t = f.path
|
20
|
-
f.close(true) # remote tempfile immediately
|
21
|
-
t
|
22
|
-
}
|
23
|
-
}
|
14
|
+
|
15
|
+
_cset(:config_use_shared, false)
|
16
|
+
_cset(:config_shared_path) { File.join(shared_path, 'config') }
|
17
|
+
|
24
18
|
_cset(:config_readable_mode, "ug+r")
|
25
19
|
_cset(:config_readable_files, [])
|
26
20
|
_cset(:config_writable_mode, "ug+rw")
|
@@ -29,16 +23,14 @@ module Capistrano
|
|
29
23
|
_cset(:config_executable_files, [])
|
30
24
|
_cset(:config_remove_files, [])
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
39
|
-
after 'deploy:finalize_update', 'config:update'
|
26
|
+
def tempfile(name)
|
27
|
+
f = Tempfile.new(name)
|
28
|
+
path = f.path
|
29
|
+
f.close(true) # close and remove tempfile immediately
|
30
|
+
path
|
31
|
+
end
|
40
32
|
|
41
|
-
def
|
33
|
+
def template(config)
|
42
34
|
if File.file?(config)
|
43
35
|
File.read(config)
|
44
36
|
elsif File.file?("#{config}.erb")
|
@@ -48,62 +40,112 @@ module Capistrano
|
|
48
40
|
end
|
49
41
|
end
|
50
42
|
|
51
|
-
def
|
52
|
-
options = {
|
53
|
-
:readable_files => [], :writable_files => [], :executable_files => [],
|
54
|
-
:remove_files => [],
|
55
|
-
:use_sudo => true,
|
56
|
-
}.merge(options)
|
57
|
-
dirs = src_tmp_tgt.map { |src, tmp, tgt| File.dirname(tgt) }.uniq
|
43
|
+
def update_one(source, target, options={})
|
58
44
|
try_sudo = options[:use_sudo] ? sudo : ""
|
59
45
|
execute = []
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
execute << "#{try_sudo} chmod #{config_readable_mode} #{
|
65
|
-
execute << "#{try_sudo} chmod #{config_writable_mode} #{
|
66
|
-
execute << "#{try_sudo} chmod #{config_executable_mode} #{
|
67
|
-
execute << "#{try_sudo} rm -f #{
|
46
|
+
dirs = [ File.dirname(source), File.dirname(target) ].uniq
|
47
|
+
execute << "#{try_sudo} mkdir -p #{dirs.map { |d| d.dump }.join(' ')}"
|
48
|
+
execute << "( #{try_sudo} diff -u #{target.dump} #{source.dump} || #{try_sudo} mv -f #{source.dump} #{target.dump} )"
|
49
|
+
|
50
|
+
execute << "#{try_sudo} chmod #{config_readable_mode} #{target.dump}" if options[:readable_files].include?(target)
|
51
|
+
execute << "#{try_sudo} chmod #{config_writable_mode} #{target.dump}" if options[:writable_files].include?(target)
|
52
|
+
execute << "#{try_sudo} chmod #{config_executable_mode} #{target.dump}" if options[:executable_files].include?(target)
|
53
|
+
execute << "#{try_sudo} rm -f #{config_remove_files.map { |f| f.dump }.join(' ')}" if options[:remove_files].include?(target)
|
68
54
|
|
69
55
|
execute.join(' && ')
|
70
56
|
end
|
71
57
|
|
72
|
-
|
58
|
+
def update_all(files={}, options={})
|
59
|
+
srcs = files.map { |src, dst| src }
|
60
|
+
tmps = files.map { tempfile("capistrano-config") }
|
61
|
+
dsts = files.map { |src, dst| dst }
|
62
|
+
begin
|
63
|
+
srcs.zip(tmps).each do |src, tmp|
|
64
|
+
put(template(src), tmp)
|
65
|
+
end
|
66
|
+
tmps.zip(dsts).each do |tmp, dst|
|
67
|
+
run(update_one(tmp, dst, options.merge(:use_sudo => fetch(:config_use_sudo_remotely, false))))
|
68
|
+
end
|
69
|
+
ensure
|
70
|
+
run("rm -f #{tmps.map { |f| f.dump }.join(' ')}") unless tmps.empty?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def update_all_locally(files={}, options={})
|
75
|
+
srcs = files.map { |src, dst| src }
|
76
|
+
tmps = files.map { tempfile("capistrano-config") }
|
77
|
+
dsts = files.map { |src, dst| dst }
|
73
78
|
begin
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
:use_sudo => fetch(:config_use_sudo_locally, false),
|
81
|
-
:readable_files => config_readable_files.map { |f| File.join(config_path_local, f) },
|
82
|
-
:writable_files => config_writable_files.map { |f| File.join(config_path_local, f) },
|
83
|
-
:executable_files => config_executable_files.map { |f| File.join(config_path_local, f) },
|
84
|
-
:remove_files => config_remove_files.map { |f| File.join(config_path_local, f) }))
|
79
|
+
srcs.zip(tmps).each do |src, tmp|
|
80
|
+
File.open(tmp, 'wb') { |fp| fp.write(template(src)) } unless dry_run
|
81
|
+
end
|
82
|
+
tmps.zip(dsts).each do |tmp, dst|
|
83
|
+
run_locally(update_one(tmp, dst, options.merge(:use_sudo => fetch(:config_use_sudo_locally, false))))
|
84
|
+
end
|
85
85
|
ensure
|
86
|
-
run_locally("rm -f #{
|
86
|
+
run_locally("rm -f #{tmps.map { |f| f.dump }.join(' ')}") unless tmps.empty?
|
87
87
|
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def symlink_all(files={}, options={})
|
91
|
+
execute = []
|
92
|
+
files.each do |src, dst|
|
93
|
+
execute << "( rm -f #{dst.dump} && ln -s #{src.dump} #{dst.dump} )"
|
94
|
+
end
|
95
|
+
run(execute.join(' && '))
|
96
|
+
end
|
97
|
+
|
98
|
+
desc("Setup shared application config.")
|
99
|
+
task(:setup, :roles => :app, :except => { :no_release => true }) {
|
100
|
+
if config_use_shared
|
101
|
+
srcs = config_files.map { |f| File.join(config_template_path, f) }
|
102
|
+
dsts = config_files.map { |f| File.join(config_shared_path, f) }
|
103
|
+
update_all(srcs.zip(dsts),
|
104
|
+
:readable_files => config_readable_files.map { |f| File.join(config_shared_path, f) },
|
105
|
+
:writable_files => config_writable_files.map { |f| File.join(config_shared_path, f) },
|
106
|
+
:executable_files => config_executable_files.map { |f| File.join(config_shared_path, f) },
|
107
|
+
:remove_files => config_remove_files.map { |f| File.join(config_shared_path, f) }
|
108
|
+
)
|
109
|
+
end
|
110
|
+
}
|
111
|
+
after 'deploy:setup', 'config:setup'
|
112
|
+
|
113
|
+
desc("Update applicatin config.")
|
114
|
+
task(:update, :roles => :app, :except => { :no_release => true }) {
|
115
|
+
transaction {
|
116
|
+
update_remotely if fetch(:config_update_remotely, true)
|
117
|
+
update_locally if fetch(:config_update_locally, false)
|
118
|
+
}
|
88
119
|
}
|
120
|
+
after 'deploy:finalize_update', 'config:update'
|
89
121
|
|
90
122
|
task(:update_remotely, :roles => :app, :except => { :no_release => true }) {
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
}
|
97
|
-
|
98
|
-
|
123
|
+
if config_use_shared
|
124
|
+
srcs = config_files.map { |f| File.join(config_shared_path, f) }
|
125
|
+
dsts = config_files.map { |f| File.join(config_path, f) }
|
126
|
+
symlink_all(srcs.zip(dsts))
|
127
|
+
else
|
128
|
+
srcs = config_files.map { |f| File.join(config_template_path, f) }
|
129
|
+
dsts = config_files.map { |f| File.join(config_path, f) }
|
130
|
+
update_all(srcs.zip(dsts),
|
99
131
|
:readable_files => config_readable_files.map { |f| File.join(config_path, f) },
|
100
132
|
:writable_files => config_writable_files.map { |f| File.join(config_path, f) },
|
101
133
|
:executable_files => config_executable_files.map { |f| File.join(config_path, f) },
|
102
|
-
:remove_files => config_remove_files.map { |f| File.join(config_path, f) }
|
103
|
-
|
104
|
-
run("rm -f #{config_temporary_files.join(' ')}") unless config_temporary_files.empty?
|
134
|
+
:remove_files => config_remove_files.map { |f| File.join(config_path, f) }
|
135
|
+
)
|
105
136
|
end
|
106
137
|
}
|
138
|
+
|
139
|
+
task(:update_locally, :roles => :app, :except => { :no_release => true }) {
|
140
|
+
srcs = config_files.map { |f| File.join(config_template_path, f) }
|
141
|
+
dsts = config_files.map { |f| File.join(config_path_local, f) }
|
142
|
+
update_all_locally(srcs.zip(dsts),
|
143
|
+
:readable_files => config_readable_files.map { |f| File.join(config_path_local, f) },
|
144
|
+
:writable_files => config_writable_files.map { |f| File.join(config_path_local, f) },
|
145
|
+
:executable_files => config_executable_files.map { |f| File.join(config_path_local, f) },
|
146
|
+
:remove_files => config_remove_files.map { |f| File.join(config_path_local, f) }
|
147
|
+
)
|
148
|
+
}
|
107
149
|
}
|
108
150
|
}
|
109
151
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|